mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:01:18 +08:00
new S3 backup layout (#9830)
* DEV: new S3 backup layout Currently, with $S3_BACKUP_BUCKET of "bucket/backups", multisite backups end up in "bucket/backups/backups/dbname/" and single-site will be in "bucket/backups/". Both _should_ be in "bucket/backups/dbname/" - remove MULTISITE_PREFIX, - always include dbname, - method to move to the new prefix - job to call the method * SPEC: add tests for `VacateLegacyPrefixBackups` onceoff job. Co-authored-by: Vinoth Kannan <vinothkannan@vinkas.com>
This commit is contained in:
@ -3,12 +3,11 @@
|
||||
module BackupRestore
|
||||
class S3BackupStore < BackupStore
|
||||
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(s3_bucket_name_with_prefix, '', s3_options)
|
||||
@s3_options = S3Helper.s3_options(SiteSetting)
|
||||
@s3_options.merge!(opts[:s3_options]) if opts[:s3_options]
|
||||
@s3_helper = S3Helper.new(s3_bucket_name_with_prefix, '', @s3_options.clone)
|
||||
end
|
||||
|
||||
def remote?
|
||||
@ -52,6 +51,20 @@ module BackupRestore
|
||||
raise StorageError
|
||||
end
|
||||
|
||||
def vacate_legacy_prefix
|
||||
legacy_s3_helper = S3Helper.new(s3_bucket_name_with_legacy_prefix, '', @s3_options.clone)
|
||||
legacy_keys = legacy_s3_helper.list.map { |o| o.key }
|
||||
legacy_keys.each do |legacy_key|
|
||||
bucket, prefix = s3_bucket_name_with_prefix.split('/', 2)
|
||||
@s3_helper.s3_client.copy_object({
|
||||
copy_source: File.join(bucket, legacy_key),
|
||||
bucket: bucket,
|
||||
key: File.join(prefix, legacy_key.split('/').last)
|
||||
})
|
||||
legacy_s3_helper.delete_object(legacy_key)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def unsorted_files
|
||||
@ -99,8 +112,12 @@ module BackupRestore
|
||||
end
|
||||
|
||||
def s3_bucket_name_with_prefix
|
||||
File.join(SiteSetting.s3_backup_bucket, RailsMultisite::ConnectionManagement.current_db)
|
||||
end
|
||||
|
||||
def s3_bucket_name_with_legacy_prefix
|
||||
if Rails.configuration.multisite
|
||||
File.join(SiteSetting.s3_backup_bucket, MULTISITE_PREFIX, RailsMultisite::ConnectionManagement.current_db)
|
||||
File.join(SiteSetting.s3_backup_bucket, "backups", RailsMultisite::ConnectionManagement.current_db)
|
||||
else
|
||||
SiteSetting.s3_backup_bucket
|
||||
end
|
||||
|
Reference in New Issue
Block a user