mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:34:31 +08:00
FEATURE: Multisite support for S3 backup store (#6700)
This commit is contained in:

committed by
Guo Xiang Tan

parent
ba762ea87f
commit
99117d664c
@ -83,7 +83,7 @@ module BackupRestore
|
||||
@timestamp = Time.now.strftime("%Y-%m-%d-%H%M%S")
|
||||
@tmp_directory = File.join(Rails.root, "tmp", "backups", @current_db, @timestamp)
|
||||
@dump_filename = File.join(@tmp_directory, BackupRestore::DUMP_FILE)
|
||||
@archive_directory = BackupRestore::LocalBackupStore.base_directory(@current_db)
|
||||
@archive_directory = BackupRestore::LocalBackupStore.base_directory(db: @current_db)
|
||||
filename = @filename_override || "#{SiteSetting.title.parameterize}-#{@timestamp}"
|
||||
@archive_basename = File.join(@archive_directory, "#{filename}-#{BackupRestore::VERSION_PREFIX}#{BackupRestore.current_version}")
|
||||
|
||||
|
@ -3,9 +3,11 @@ require_dependency "disk_space"
|
||||
|
||||
module BackupRestore
|
||||
class LocalBackupStore < BackupStore
|
||||
def self.base_directory(current_db = nil)
|
||||
current_db ||= RailsMultisite::ConnectionManagement.current_db
|
||||
base_directory = File.join(Rails.root, "public", "backups", current_db)
|
||||
def self.base_directory(db: nil, root_directory: nil)
|
||||
current_db = db || RailsMultisite::ConnectionManagement.current_db
|
||||
root_directory ||= File.join(Rails.root, "public", "backups")
|
||||
|
||||
base_directory = File.join(root_directory, current_db)
|
||||
FileUtils.mkdir_p(base_directory) unless Dir.exists?(base_directory)
|
||||
base_directory
|
||||
end
|
||||
@ -15,7 +17,7 @@ module BackupRestore
|
||||
end
|
||||
|
||||
def initialize(opts = {})
|
||||
@base_directory = opts[:base_directory] || LocalBackupStore.base_directory
|
||||
@base_directory = LocalBackupStore.base_directory(root_directory: opts[:root_directory])
|
||||
end
|
||||
|
||||
def remote?
|
||||
|
@ -5,11 +5,12 @@ module BackupRestore
|
||||
class S3BackupStore < BackupStore
|
||||
DOWNLOAD_URL_EXPIRES_AFTER_SECONDS ||= 15
|
||||
UPLOAD_URL_EXPIRES_AFTER_SECONDS ||= 21_600 # 6 hours
|
||||
MULTISITE_PREFIX = "backups"
|
||||
|
||||
def initialize(opts = {})
|
||||
s3_options = S3Helper.s3_options(SiteSetting)
|
||||
s3_options.merge!(opts[:s3_options]) if opts[:s3_options]
|
||||
@s3_helper = S3Helper.new(SiteSetting.s3_backup_bucket, '', s3_options)
|
||||
@s3_helper = S3Helper.new(s3_bucket_name_with_prefix, '', s3_options)
|
||||
end
|
||||
|
||||
def remote?
|
||||
@ -91,5 +92,13 @@ module BackupRestore
|
||||
def cleanup_allowed?
|
||||
!SiteSetting.s3_disable_cleanup
|
||||
end
|
||||
|
||||
def s3_bucket_name_with_prefix
|
||||
if Rails.configuration.multisite
|
||||
File.join(SiteSetting.s3_backup_bucket, MULTISITE_PREFIX, RailsMultisite::ConnectionManagement.current_db)
|
||||
else
|
||||
SiteSetting.s3_backup_bucket
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user