FIX: Backups should use relative paths for local uploads

This also ensures that restoring a backup works when it was created with the wrong upload paths in the time between ab4c0a4970163506e2c72884ff2ba2d8845eb10c (shortly after v2.6.0.beta1) and this fix.
This commit is contained in:
Gerhard Schlager
2020-08-21 15:09:50 +02:00
parent 2fac77cc48
commit f51ccea028
4 changed files with 36 additions and 5 deletions

View File

@ -67,6 +67,8 @@ module BackupRestore
log "Unzipping archive, this may take a while..."
Discourse::Utils.execute_command(
'tar', '--extract', '--gzip', '--file', @archive_path, '--directory', @tmp_directory,
'--transform', 's|var/www/discourse/public/uploads/|uploads/|',
# the transformation is a workaround for a bug which existed between v2.6.0.beta1 and v2.6.0.beta2
failure_message: "Failed to decompress archive."
)
end

View File

@ -234,15 +234,17 @@ module BackupRestore
log "Archiving uploads..."
if has_local_uploads?
upload_directory = Discourse.store.upload_path
if SiteSetting.include_thumbnails_in_backups
exclude_optimized = ""
else
optimized_path = File.join(local_uploads_directory, 'optimized')
optimized_path = File.join(upload_directory, 'optimized')
exclude_optimized = "--exclude=#{optimized_path}"
end
Discourse::Utils.execute_command(
'tar', '--append', '--dereference', exclude_optimized, '--file', tar_filename, local_uploads_directory,
'tar', '--append', '--dereference', exclude_optimized, '--file', tar_filename, upload_directory,
failure_message: "Failed to archive uploads.", success_status_codes: [0, 1],
chdir: File.join(Rails.root, "public")
)