FIX: proper exit status code for backup/restore scripts

This commit is contained in:
Régis Hanol 2014-08-04 17:55:09 +02:00
parent 2e134742d4
commit 925a15c9aa
3 changed files with 12 additions and 2 deletions

View file

@ -2,6 +2,8 @@ module Export
class Exporter
attr_reader :success
def initialize(user_id, publish_to_message_bus = false)
@user_id, @publish_to_message_bus = user_id, publish_to_message_bus

View file

@ -5,6 +5,8 @@ module Import
class Importer
attr_reader :success
def initialize(user_id, filename, publish_to_message_bus = false)
@user_id, @filename, @publish_to_message_bus = user_id, filename, publish_to_message_bus

View file

@ -45,7 +45,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
require "export/exporter"
puts "Starting export..."
backup = Export::Exporter.new(Discourse.system_user.id).run
exporter = Export::Exporter.new(Discourse.system_user.id)
backup = exporter.run
if filename.present?
puts "Moving '#{backup}' to '#{filename}'"
FileUtils.mv(backup, filename)
@ -53,6 +54,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
end
puts "Export done."
puts "Output file is in: #{backup}", ""
exit(1) unless exporter.success
end
desc "export", "Backup a Discourse forum"
@ -68,7 +71,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
begin
puts "Starting restore: #{filename}"
Import::Importer.new(Discourse.system_user.id, filename).run
importer = Import::Importer.new(Discourse.system_user.id, filename)
importer.run
puts 'Restore done.'
rescue Import::FilenameMissingError
puts '', 'The filename argument was missing.', ''
@ -77,6 +81,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
puts '', 'Restores are not allowed.', 'An admin needs to set allow_restore to true in the site settings before restores can be run.', ''
puts 'Restore cancelled.', ''
end
exit(1) unless importer.try(:success)
end
desc "import", "Restore a Discourse backup"