Skip to content

A platform for community discussion. Free, open, simple.

FIX: discourse script didn't allow backups with paths anymore

Gerhard Schlagercc27d61f9e9a
diff --git a/script/discourse b/script/discourse
index ddfc6181933..205b9be545b 100755
--- a/script/discourse
+++ b/script/discourse
@@ -61,12 +61,25 @@ class DiscourseCLI < Thor
require "backup_restore/backup_restore"
require "backup_restore/backuper"
+ 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)
+ backuper = BackupRestore::Backuper.new(Discourse.system_user.id, filename: filename_without_extension)
backup_filename = backuper.run
- puts "Backup done."
+ exit(1) unless backuper.success
- store = BackupRestore::BackupStore.create
+ puts "Backup done."
if store.remote?
location = BackupLocationSiteSetting.values.find { |v| v[:value] == SiteSetting.backup_location }
@@ -74,10 +87,17 @@ class DiscourseCLI < Thor
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"