mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: proper exit status code for backup/restore scripts
This commit is contained in:
parent
2e134742d4
commit
925a15c9aa
3 changed files with 12 additions and 2 deletions
|
@ -2,6 +2,8 @@ module Export
|
||||||
|
|
||||||
class Exporter
|
class Exporter
|
||||||
|
|
||||||
|
attr_reader :success
|
||||||
|
|
||||||
def initialize(user_id, publish_to_message_bus = false)
|
def initialize(user_id, publish_to_message_bus = false)
|
||||||
@user_id, @publish_to_message_bus = user_id, publish_to_message_bus
|
@user_id, @publish_to_message_bus = user_id, publish_to_message_bus
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ module Import
|
||||||
|
|
||||||
class Importer
|
class Importer
|
||||||
|
|
||||||
|
attr_reader :success
|
||||||
|
|
||||||
def initialize(user_id, filename, publish_to_message_bus = false)
|
def initialize(user_id, filename, publish_to_message_bus = false)
|
||||||
@user_id, @filename, @publish_to_message_bus = user_id, filename, publish_to_message_bus
|
@user_id, @filename, @publish_to_message_bus = user_id, filename, publish_to_message_bus
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
|
||||||
require "export/exporter"
|
require "export/exporter"
|
||||||
|
|
||||||
puts "Starting export..."
|
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?
|
if filename.present?
|
||||||
puts "Moving '#{backup}' to '#{filename}'"
|
puts "Moving '#{backup}' to '#{filename}'"
|
||||||
FileUtils.mv(backup, filename)
|
FileUtils.mv(backup, filename)
|
||||||
|
@ -53,6 +54,8 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
|
||||||
end
|
end
|
||||||
puts "Export done."
|
puts "Export done."
|
||||||
puts "Output file is in: #{backup}", ""
|
puts "Output file is in: #{backup}", ""
|
||||||
|
|
||||||
|
exit(1) unless exporter.success
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "export", "Backup a Discourse forum"
|
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
|
begin
|
||||||
puts "Starting restore: #{filename}"
|
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.'
|
puts 'Restore done.'
|
||||||
rescue Import::FilenameMissingError
|
rescue Import::FilenameMissingError
|
||||||
puts '', 'The filename argument was missing.', ''
|
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 '', '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.', ''
|
puts 'Restore cancelled.', ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
exit(1) unless importer.try(:success)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "import", "Restore a Discourse backup"
|
desc "import", "Restore a Discourse backup"
|
||||||
|
|
Loading…
Reference in a new issue