diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index c813d87f91a..5ee1f016396 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -127,6 +127,7 @@ module BackupRestore BackupMetadata.create!(name: "s3_base_url", value: SiteSetting.Upload.enable_s3_uploads ? SiteSetting.Upload.s3_base_url : nil) BackupMetadata.create!(name: "s3_cdn_url", value: SiteSetting.Upload.enable_s3_uploads ? SiteSetting.Upload.s3_cdn_url : nil) BackupMetadata.create!(name: "db_name", value: RailsMultisite::ConnectionManagement.current_db) + BackupMetadata.create!(name: "multisite", value: Rails.configuration.multisite) end def enable_readonly_mode diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb index 9586e4d32b9..75a1c90336a 100644 --- a/lib/backup_restore/restorer.rb +++ b/lib/backup_restore/restorer.rb @@ -458,19 +458,22 @@ module BackupRestore def remap_uploads(previous_db_name, current_db_name) log "Remapping uploads..." + was_multisite = BackupMetadata.value_for("multisite") == "true" + uploads_folder = was_multisite ? "/" : "/uploads/#{current_db_name}/" + if (old_base_url = BackupMetadata.value_for("base_url")) && old_base_url != Discourse.base_url DbHelper.remap(old_base_url, Discourse.base_url) end current_s3_base_url = SiteSetting.Upload.enable_s3_uploads ? SiteSetting.Upload.s3_base_url : nil if (old_s3_base_url = BackupMetadata.value_for("s3_base_url")) && old_base_url != current_s3_base_url - DbHelper.remap("#{old_s3_base_url}/", "/uploads/#{current_db_name}/") + DbHelper.remap("#{old_s3_base_url}/", uploads_folder) end current_s3_cdn_url = SiteSetting.Upload.enable_s3_uploads ? SiteSetting.Upload.s3_cdn_url : nil if (old_s3_cdn_url = BackupMetadata.value_for("s3_cdn_url")) && old_s3_cdn_url != current_s3_cdn_url base_url = SiteSetting.Upload.enable_s3_uploads ? SiteSetting.Upload.s3_cdn_url : Discourse.base_url - DbHelper.remap("#{old_s3_cdn_url}/", UrlHelper.schemaless("#{base_url}/uploads/#{current_db_name}/")) + DbHelper.remap("#{old_s3_cdn_url}/", UrlHelper.schemaless("#{base_url}#{uploads_folder}")) old_host = URI.parse(old_s3_cdn_url).host new_host = URI.parse(base_url.presence || Discourse.base_url).host