diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb index fac8c8f836f..3a3ae1b1c2e 100644 --- a/app/controllers/admin/backups_controller.rb +++ b/app/controllers/admin/backups_controller.rb @@ -1,4 +1,4 @@ -require_dependency "backup_restore" +require "backup_restore/backup_restore" class Admin::BackupsController < Admin::AdminController diff --git a/app/jobs/scheduled/create_backup.rb b/app/jobs/scheduled/create_backup.rb index abf08c1dc5a..3c877cd38fd 100644 --- a/app/jobs/scheduled/create_backup.rb +++ b/app/jobs/scheduled/create_backup.rb @@ -1,4 +1,4 @@ -require_dependency "backup_restore" +require "backup_restore/backup_restore" module Jobs class CreateBackup < Jobs::Scheduled diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 51256f792b1..1cba02ac0e3 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1383,14 +1383,16 @@ en: [prefs]: %{user_preferences_url} - export_succeeded: - subject_template: "Export completed successfully" - text_body_template: "The export was successful." + backup_succeeded: + subject_template: "Backup completed successfully" + text_body_template: "The backup was successful. - export_failed: - subject_template: "Export failed" + Visit the [admin > backup section](/admin/backups) to download your new backup." + + backup_failed: + subject_template: "Backup failed" text_body_template: | - The export has failed. + The backup has failed. Here's the log: diff --git a/lib/backup_restore.rb b/lib/backup_restore/backup_restore.rb similarity index 96% rename from lib/backup_restore.rb rename to lib/backup_restore/backup_restore.rb index b599437619e..c917be31ba1 100644 --- a/lib/backup_restore.rb +++ b/lib/backup_restore/backup_restore.rb @@ -1,5 +1,5 @@ -require_dependency "export/exporter" -require_dependency "import/importer" +require "backup_restore/backuper" +require "backup_restore/restorer" module BackupRestore @@ -10,11 +10,11 @@ module BackupRestore LOGS_CHANNEL = "/admin/backups/logs" def self.backup!(user_id, opts={}) - start! Export::Exporter.new(user_id, opts) + start! BackupRestore::Backuper.new(user_id, opts) end def self.restore!(user_id, filename, publish_to_message_bus=false) - start! Import::Importer.new(user_id, filename, publish_to_message_bus) + start! BackupRestore::Restorer.new(user_id, filename, publish_to_message_bus) end def self.rollback! diff --git a/lib/export/exporter.rb b/lib/backup_restore/backuper.rb similarity index 97% rename from lib/export/exporter.rb rename to lib/backup_restore/backuper.rb index 7105a96ce2d..da51b902843 100644 --- a/lib/export/exporter.rb +++ b/lib/backup_restore/backuper.rb @@ -1,6 +1,6 @@ -module Export +module BackupRestore - class Exporter + class Backuper attr_reader :success @@ -19,7 +19,7 @@ module Export log "[STARTED]" log "'#{@user.username}' has started the backup!" - mark_export_as_running + mark_backup_as_running listen_for_shutdown_signal @@ -95,7 +95,7 @@ module Export end end - def mark_export_as_running + def mark_backup_as_running log "Marking backup as running..." BackupRestore.mark_as_running! end @@ -275,9 +275,9 @@ module Export def notify_user log "Notifying '#{@user.username}' of the end of the backup..." if @success - SystemMessage.create_from_system_user(@user, :export_succeeded) + SystemMessage.create_from_system_user(@user, :backup_succeeded) else - SystemMessage.create_from_system_user(@user, :export_failed, logs: @logs.join("\n")) + SystemMessage.create_from_system_user(@user, :backup_failed, logs: @logs.join("\n")) end end @@ -286,7 +286,7 @@ module Export remove_tmp_directory unpause_sidekiq disable_readonly_mode if Discourse.readonly_mode? - mark_export_as_not_running + mark_backup_as_not_running log "Finished!" end @@ -310,7 +310,7 @@ module Export Discourse.disable_readonly_mode end - def mark_export_as_not_running + def mark_backup_as_not_running log "Marking backup as finished..." BackupRestore.mark_as_not_running! end diff --git a/lib/import/importer.rb b/lib/backup_restore/restorer.rb similarity index 93% rename from lib/import/importer.rb rename to lib/backup_restore/restorer.rb index 4787f585e85..8751aecdd29 100644 --- a/lib/import/importer.rb +++ b/lib/backup_restore/restorer.rb @@ -1,16 +1,16 @@ -module Import +module BackupRestore - class ImportDisabledError < RuntimeError; end + class RestoreDisabledError < RuntimeError; end class FilenameMissingError < RuntimeError; end - class Importer + class Restorer 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 - ensure_import_is_enabled + ensure_restore_is_enabled ensure_no_operation_is_running ensure_we_have_a_user ensure_we_have_a_filename @@ -22,7 +22,7 @@ module Import log "[STARTED]" log "'#{@user_info[:username]}' has started the restore!" - mark_import_as_running + mark_restore_as_running listen_for_shutdown_signal @@ -72,8 +72,8 @@ module Import protected - def ensure_import_is_enabled - raise Import::ImportDisabledError unless Rails.env.development? || SiteSetting.allow_restore? + def ensure_restore_is_enabled + raise Restore::RestoreDisabledError unless Rails.env.development? || SiteSetting.allow_restore? end def ensure_no_operation_is_running @@ -88,7 +88,7 @@ module Import end def ensure_we_have_a_filename - raise Import::FilenameMissingError if @filename.nil? + raise Restore::FilenameMissingError if @filename.nil? end def initialize_state @@ -115,7 +115,7 @@ module Import end end - def mark_import_as_running + def mark_restore_as_running log "Marking restore as running..." BackupRestore.mark_as_running! end @@ -174,7 +174,7 @@ module Import log " Current version: #{@current_version}" log " Restored version: #{@metadata["version"]}" - error = "You're trying to import a more recent version of the schema. You should migrate first!" + error = "You're trying to restore a more recent version of the schema. You should migrate first!" raise error if @metadata["version"] > @current_version end @@ -290,9 +290,9 @@ module Import if user = User.find_by(email: @user_info[:email]) log "Notifying '#{user.username}' of the end of the restore..." if @success - SystemMessage.create_from_system_user(user, :import_succeeded) + SystemMessage.create_from_system_user(user, :restore_succeeded) else - SystemMessage.create_from_system_user(user, :import_failed, logs: @logs.join("\n")) + SystemMessage.create_from_system_user(user, :restore_failed, logs: @logs.join("\n")) end else log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..." @@ -304,7 +304,7 @@ module Import remove_tmp_directory unpause_sidekiq disable_readonly_mode if Discourse.readonly_mode? - mark_import_as_not_running + mark_restore_as_not_running log "Finished!" end @@ -328,7 +328,7 @@ module Import Discourse.disable_readonly_mode end - def mark_import_as_not_running + def mark_restore_as_not_running log "Marking restore as finished..." BackupRestore.mark_as_not_running! end diff --git a/script/discourse b/script/discourse index 4fdc7a6a824..c33c3260e59 100755 --- a/script/discourse +++ b/script/discourse @@ -45,21 +45,21 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text% desc "backup", "Backup a discourse forum" def backup(filename = nil) load_rails - require "backup_restore" - require "export/exporter" + require "backup_restore/backup_restore" + require "backup_restore/backuper" - puts "Starting export..." - exporter = Export::Exporter.new(Discourse.system_user.id) - backup = exporter.run + puts "Starting backup..." + backuper = BackupRestore::Backuper.new(Discourse.system_user.id) + backup = backuper.run if filename.present? puts "Moving '#{backup}' to '#{filename}'" FileUtils.mv(backup, filename) backup = filename end - puts "Export done." + puts "Backup done." puts "Output file is in: #{backup}", "" - exit(1) unless exporter.success + exit(1) unless backuper.success end desc "export", "Backup a Discourse forum" @@ -70,23 +70,23 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text% desc "restore", "Restore a Discourse backup" def restore(filename) load_rails - require "backup_restore" - require "import/importer" + require "backup_restore/backup_restore" + require "backup_restore/restorer" begin puts "Starting restore: #{filename}" - importer = Import::Importer.new(Discourse.system_user.id, filename) - importer.run + restorer = BackupRestore::Restorer.new(Discourse.system_user.id, filename) + restorer.run puts 'Restore done.' - rescue Import::FilenameMissingError + rescue BackupRestore::FilenameMissingError puts '', 'The filename argument was missing.', '' usage - rescue Import::ImportDisabledError + rescue BackupRestore::RestoreDisabledError 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) + exit(1) unless restorer.try(:success) end desc "import", "Restore a Discourse backup"