From 220944a38a9699549b895363d7f44dd63867a0ba Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 11 Feb 2019 14:38:42 +0100 Subject: [PATCH] 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. --- lib/backup_restore/backuper.rb | 8 ++++---- lib/discourse.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index cdda8a1de21..e9d5c31503b 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -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..." diff --git a/lib/discourse.rb b/lib/discourse.rb index d681ddb2dde..7f5b0182e0b 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -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