mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
rename export/import in favor of backup/restore for better consistency
This commit is contained in:
parent
bbbec13606
commit
5504622c1b
7 changed files with 50 additions and 48 deletions
|
@ -1,4 +1,4 @@
|
||||||
require_dependency "backup_restore"
|
require "backup_restore/backup_restore"
|
||||||
|
|
||||||
class Admin::BackupsController < Admin::AdminController
|
class Admin::BackupsController < Admin::AdminController
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require_dependency "backup_restore"
|
require "backup_restore/backup_restore"
|
||||||
|
|
||||||
module Jobs
|
module Jobs
|
||||||
class CreateBackup < Jobs::Scheduled
|
class CreateBackup < Jobs::Scheduled
|
||||||
|
|
|
@ -1383,14 +1383,16 @@ en:
|
||||||
|
|
||||||
[prefs]: %{user_preferences_url}
|
[prefs]: %{user_preferences_url}
|
||||||
|
|
||||||
export_succeeded:
|
backup_succeeded:
|
||||||
subject_template: "Export completed successfully"
|
subject_template: "Backup completed successfully"
|
||||||
text_body_template: "The export was successful."
|
text_body_template: "The backup was successful.
|
||||||
|
|
||||||
export_failed:
|
Visit the [admin > backup section](/admin/backups) to download your new backup."
|
||||||
subject_template: "Export failed"
|
|
||||||
|
backup_failed:
|
||||||
|
subject_template: "Backup failed"
|
||||||
text_body_template: |
|
text_body_template: |
|
||||||
The export has failed.
|
The backup has failed.
|
||||||
|
|
||||||
Here's the log:
|
Here's the log:
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require_dependency "export/exporter"
|
require "backup_restore/backuper"
|
||||||
require_dependency "import/importer"
|
require "backup_restore/restorer"
|
||||||
|
|
||||||
module BackupRestore
|
module BackupRestore
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ module BackupRestore
|
||||||
LOGS_CHANNEL = "/admin/backups/logs"
|
LOGS_CHANNEL = "/admin/backups/logs"
|
||||||
|
|
||||||
def self.backup!(user_id, opts={})
|
def self.backup!(user_id, opts={})
|
||||||
start! Export::Exporter.new(user_id, opts)
|
start! BackupRestore::Backuper.new(user_id, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.restore!(user_id, filename, publish_to_message_bus=false)
|
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
|
end
|
||||||
|
|
||||||
def self.rollback!
|
def self.rollback!
|
|
@ -1,6 +1,6 @@
|
||||||
module Export
|
module BackupRestore
|
||||||
|
|
||||||
class Exporter
|
class Backuper
|
||||||
|
|
||||||
attr_reader :success
|
attr_reader :success
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ module Export
|
||||||
log "[STARTED]"
|
log "[STARTED]"
|
||||||
log "'#{@user.username}' has started the backup!"
|
log "'#{@user.username}' has started the backup!"
|
||||||
|
|
||||||
mark_export_as_running
|
mark_backup_as_running
|
||||||
|
|
||||||
listen_for_shutdown_signal
|
listen_for_shutdown_signal
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ module Export
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_export_as_running
|
def mark_backup_as_running
|
||||||
log "Marking backup as running..."
|
log "Marking backup as running..."
|
||||||
BackupRestore.mark_as_running!
|
BackupRestore.mark_as_running!
|
||||||
end
|
end
|
||||||
|
@ -275,9 +275,9 @@ module Export
|
||||||
def notify_user
|
def notify_user
|
||||||
log "Notifying '#{@user.username}' of the end of the backup..."
|
log "Notifying '#{@user.username}' of the end of the backup..."
|
||||||
if @success
|
if @success
|
||||||
SystemMessage.create_from_system_user(@user, :export_succeeded)
|
SystemMessage.create_from_system_user(@user, :backup_succeeded)
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ module Export
|
||||||
remove_tmp_directory
|
remove_tmp_directory
|
||||||
unpause_sidekiq
|
unpause_sidekiq
|
||||||
disable_readonly_mode if Discourse.readonly_mode?
|
disable_readonly_mode if Discourse.readonly_mode?
|
||||||
mark_export_as_not_running
|
mark_backup_as_not_running
|
||||||
log "Finished!"
|
log "Finished!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ module Export
|
||||||
Discourse.disable_readonly_mode
|
Discourse.disable_readonly_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_export_as_not_running
|
def mark_backup_as_not_running
|
||||||
log "Marking backup as finished..."
|
log "Marking backup as finished..."
|
||||||
BackupRestore.mark_as_not_running!
|
BackupRestore.mark_as_not_running!
|
||||||
end
|
end
|
|
@ -1,16 +1,16 @@
|
||||||
module Import
|
module BackupRestore
|
||||||
|
|
||||||
class ImportDisabledError < RuntimeError; end
|
class RestoreDisabledError < RuntimeError; end
|
||||||
class FilenameMissingError < RuntimeError; end
|
class FilenameMissingError < RuntimeError; end
|
||||||
|
|
||||||
class Importer
|
class Restorer
|
||||||
|
|
||||||
attr_reader :success
|
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
|
||||||
|
|
||||||
ensure_import_is_enabled
|
ensure_restore_is_enabled
|
||||||
ensure_no_operation_is_running
|
ensure_no_operation_is_running
|
||||||
ensure_we_have_a_user
|
ensure_we_have_a_user
|
||||||
ensure_we_have_a_filename
|
ensure_we_have_a_filename
|
||||||
|
@ -22,7 +22,7 @@ module Import
|
||||||
log "[STARTED]"
|
log "[STARTED]"
|
||||||
log "'#{@user_info[:username]}' has started the restore!"
|
log "'#{@user_info[:username]}' has started the restore!"
|
||||||
|
|
||||||
mark_import_as_running
|
mark_restore_as_running
|
||||||
|
|
||||||
listen_for_shutdown_signal
|
listen_for_shutdown_signal
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@ module Import
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def ensure_import_is_enabled
|
def ensure_restore_is_enabled
|
||||||
raise Import::ImportDisabledError unless Rails.env.development? || SiteSetting.allow_restore?
|
raise Restore::RestoreDisabledError unless Rails.env.development? || SiteSetting.allow_restore?
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_no_operation_is_running
|
def ensure_no_operation_is_running
|
||||||
|
@ -88,7 +88,7 @@ module Import
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_we_have_a_filename
|
def ensure_we_have_a_filename
|
||||||
raise Import::FilenameMissingError if @filename.nil?
|
raise Restore::FilenameMissingError if @filename.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_state
|
def initialize_state
|
||||||
|
@ -115,7 +115,7 @@ module Import
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_import_as_running
|
def mark_restore_as_running
|
||||||
log "Marking restore as running..."
|
log "Marking restore as running..."
|
||||||
BackupRestore.mark_as_running!
|
BackupRestore.mark_as_running!
|
||||||
end
|
end
|
||||||
|
@ -174,7 +174,7 @@ module Import
|
||||||
log " Current version: #{@current_version}"
|
log " Current version: #{@current_version}"
|
||||||
log " Restored version: #{@metadata["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
|
raise error if @metadata["version"] > @current_version
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -290,9 +290,9 @@ module Import
|
||||||
if user = User.find_by(email: @user_info[:email])
|
if user = User.find_by(email: @user_info[:email])
|
||||||
log "Notifying '#{user.username}' of the end of the restore..."
|
log "Notifying '#{user.username}' of the end of the restore..."
|
||||||
if @success
|
if @success
|
||||||
SystemMessage.create_from_system_user(user, :import_succeeded)
|
SystemMessage.create_from_system_user(user, :restore_succeeded)
|
||||||
else
|
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
|
end
|
||||||
else
|
else
|
||||||
log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..."
|
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
|
remove_tmp_directory
|
||||||
unpause_sidekiq
|
unpause_sidekiq
|
||||||
disable_readonly_mode if Discourse.readonly_mode?
|
disable_readonly_mode if Discourse.readonly_mode?
|
||||||
mark_import_as_not_running
|
mark_restore_as_not_running
|
||||||
log "Finished!"
|
log "Finished!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ module Import
|
||||||
Discourse.disable_readonly_mode
|
Discourse.disable_readonly_mode
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_import_as_not_running
|
def mark_restore_as_not_running
|
||||||
log "Marking restore as finished..."
|
log "Marking restore as finished..."
|
||||||
BackupRestore.mark_as_not_running!
|
BackupRestore.mark_as_not_running!
|
||||||
end
|
end
|
|
@ -45,21 +45,21 @@ WHERE table_schema='public' and (data_type like 'char%' or data_type like 'text%
|
||||||
desc "backup", "Backup a discourse forum"
|
desc "backup", "Backup a discourse forum"
|
||||||
def backup(filename = nil)
|
def backup(filename = nil)
|
||||||
load_rails
|
load_rails
|
||||||
require "backup_restore"
|
require "backup_restore/backup_restore"
|
||||||
require "export/exporter"
|
require "backup_restore/backuper"
|
||||||
|
|
||||||
puts "Starting export..."
|
puts "Starting backup..."
|
||||||
exporter = Export::Exporter.new(Discourse.system_user.id)
|
backuper = BackupRestore::Backuper.new(Discourse.system_user.id)
|
||||||
backup = exporter.run
|
backup = backuper.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)
|
||||||
backup = filename
|
backup = filename
|
||||||
end
|
end
|
||||||
puts "Export done."
|
puts "Backup done."
|
||||||
puts "Output file is in: #{backup}", ""
|
puts "Output file is in: #{backup}", ""
|
||||||
|
|
||||||
exit(1) unless exporter.success
|
exit(1) unless backuper.success
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "export", "Backup a Discourse forum"
|
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"
|
desc "restore", "Restore a Discourse backup"
|
||||||
def restore(filename)
|
def restore(filename)
|
||||||
load_rails
|
load_rails
|
||||||
require "backup_restore"
|
require "backup_restore/backup_restore"
|
||||||
require "import/importer"
|
require "backup_restore/restorer"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
puts "Starting restore: #{filename}"
|
puts "Starting restore: #{filename}"
|
||||||
importer = Import::Importer.new(Discourse.system_user.id, filename)
|
restorer = BackupRestore::Restorer.new(Discourse.system_user.id, filename)
|
||||||
importer.run
|
restorer.run
|
||||||
puts 'Restore done.'
|
puts 'Restore done.'
|
||||||
rescue Import::FilenameMissingError
|
rescue BackupRestore::FilenameMissingError
|
||||||
puts '', 'The filename argument was missing.', ''
|
puts '', 'The filename argument was missing.', ''
|
||||||
usage
|
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 '', '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)
|
exit(1) unless restorer.try(:success)
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "import", "Restore a Discourse backup"
|
desc "import", "Restore a Discourse backup"
|
||||||
|
|
Loading…
Reference in a new issue