From cc27d61f9e9a387413884e5f21e8595449f2ea30 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 17 Oct 2018 18:32:07 +0200 Subject: [PATCH] FIX: discourse script didn't allow backups with paths anymore This restores the previous functionality. The script now allows the following options: * `discourse backup` (uses the system generated filename) * `discourse backup ` (uses the provided filename) * `discourse backup ` (moves the backup to the provided path with the given filename) Remote backup stores do not support the last option. Some file extensions (like `.tar.gz`) are automatically removed from the provided filename. --- script/discourse | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/script/discourse b/script/discourse index ddfc6181933..205b9be545b 100755 --- a/script/discourse +++ b/script/discourse @@ -61,23 +61,43 @@ class DiscourseCLI < Thor require "backup_restore/backup_restore" require "backup_restore/backuper" - puts "Starting backup..." - backuper = BackupRestore::Backuper.new(Discourse.system_user.id, filename: filename) - backup_filename = backuper.run - puts "Backup done." - store = BackupRestore::BackupStore.create + if filename + destination_directory = File.dirname(filename).sub(/^\.$/, '') + + if destination_directory.present? && store.remote? + puts "Only local backup storage supports paths." + exit(1) + end + + filename_without_extension = File.basename(filename).sub(/\.(sql\.)?(tar\.gz|t?gz)$/i, '') + end + + puts "Starting backup..." + backuper = BackupRestore::Backuper.new(Discourse.system_user.id, filename: filename_without_extension) + backup_filename = backuper.run + exit(1) unless backuper.success + + puts "Backup done." + if store.remote? location = BackupLocationSiteSetting.values.find { |v| v[:value] == SiteSetting.backup_location } location = I18n.t("admin_js.#{location[:name]}") if location puts "Output file is stored on #{location} as #{backup_filename}", "" else backup = store.file(backup_filename, include_download_source: true) - puts "Output file is in: #{backup.source}", "" - end - exit(1) unless backuper.success + if destination_directory.present? + puts "Moving backup file..." + backup_path = File.join(destination_directory, backup_filename) + FileUtils.mv(backup.source, backup_path) + else + backup_path = backup.source + end + + puts "Output file is in: #{backup_path}", "" + end end desc "export", "Backup a Discourse forum"