FIX: Unpause sidekiq before adding uploads to backup

tar exits with status 1 when uploads are modified or deleted by a sidekiq job, so we need to treat it like status 0.

According to the documentation it should be safe to ignore status 1 ("Some files differ"):

> If tar was given `--create', `--append' or `--update' option, this exit code means that some files were changed while being archived and so the resulting archive does not contain the exact copy of the file set.

Status 2 ("Fatal error") still results in an exception.
This commit is contained in:
Gerhard Schlager 2019-02-11 14:38:42 +01:00
parent b8b1759de9
commit 220944a38a
2 changed files with 6 additions and 6 deletions

View File

@ -37,14 +37,14 @@ module BackupRestore
dump_public_schema
unpause_sidekiq
disable_readonly_mode
### READ-ONLY / END ###
log "Finalizing backup..."
@with_uploads ? create_archive : move_dump_backup
unpause_sidekiq
upload_archive
after_create_hook
@ -237,8 +237,8 @@ module BackupRestore
FileUtils.cd(File.join(Rails.root, "public")) do
if File.directory?(upload_directory)
Discourse::Utils.execute_command(
'tar', '--append', '--dereference', '--warning=no-file-changed', '--file', tar_filename, upload_directory,
failure_message: "Failed to archive uploads."
'tar', '--append', '--dereference', '--file', tar_filename, upload_directory,
failure_message: "Failed to archive uploads.", success_status_codes: [0, 1]
)
else
log "No uploads found, skipping archiving uploads..."

View File

@ -21,10 +21,10 @@ module Discourse
end
class Utils
def self.execute_command(*command, failure_message: "")
def self.execute_command(*command, failure_message: "", success_status_codes: [0])
stdout, stderr, status = Open3.capture3(*command)
if !status.success?
if !status.exited? || !success_status_codes.include?(status.exitstatus)
failure_message = "#{failure_message}\n" if !failure_message.blank?
raise "#{caller[0]}: #{failure_message}#{stderr}"
end