mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Always unpause Sidekiq after backup and restore
* Logs exceptions during the cleanup phase, but doesn't stop executing subsequent cleanup tasks. * Notifies the user at the end of the cleanup phase, so that the log contains possible errors during that phase.
This commit is contained in:
@@ -54,13 +54,10 @@ module BackupRestore
|
|||||||
@success = true
|
@success = true
|
||||||
File.join(@archive_directory, @backup_filename)
|
File.join(@archive_directory, @backup_filename)
|
||||||
ensure
|
ensure
|
||||||
begin
|
remove_old
|
||||||
notify_user
|
clean_up
|
||||||
remove_old
|
notify_user
|
||||||
clean_up
|
log "Finished!"
|
||||||
rescue => ex
|
|
||||||
Rails.logger.error("#{ex}\n" + ex.backtrace.join("\n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
@success ? log("[SUCCESS]") : log("[FAILED]")
|
@success ? log("[SUCCESS]") : log("[FAILED]")
|
||||||
end
|
end
|
||||||
@@ -255,6 +252,8 @@ module BackupRestore
|
|||||||
def remove_old
|
def remove_old
|
||||||
log "Removing old backups..."
|
log "Removing old backups..."
|
||||||
Backup.remove_old
|
Backup.remove_old
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while removing old backups.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_user
|
def notify_user
|
||||||
@@ -270,6 +269,8 @@ module BackupRestore
|
|||||||
end
|
end
|
||||||
|
|
||||||
post
|
post
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while notifying user.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_up
|
def clean_up
|
||||||
@@ -279,42 +280,49 @@ module BackupRestore
|
|||||||
disable_readonly_mode if Discourse.readonly_mode?
|
disable_readonly_mode if Discourse.readonly_mode?
|
||||||
mark_backup_as_not_running
|
mark_backup_as_not_running
|
||||||
refresh_disk_space
|
refresh_disk_space
|
||||||
log "Finished!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_disk_space
|
def refresh_disk_space
|
||||||
log "Refreshing disk cache..."
|
log "Refreshing disk stats..."
|
||||||
DiskSpace.reset_cached_stats
|
DiskSpace.reset_cached_stats
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while refreshing disk stats.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_tar_leftovers
|
def remove_tar_leftovers
|
||||||
log "Removing '.tar' leftovers..."
|
log "Removing '.tar' leftovers..."
|
||||||
Dir["#{@archive_directory}/*.tar"].each { |filename| File.delete(filename) }
|
Dir["#{@archive_directory}/*.tar"].each { |filename| File.delete(filename) }
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while removing '.tar' leftovers.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_tmp_directory
|
def remove_tmp_directory
|
||||||
log "Removing tmp '#{@tmp_directory}' directory..."
|
log "Removing tmp '#{@tmp_directory}' directory..."
|
||||||
FileUtils.rm_rf(@tmp_directory) if Dir[@tmp_directory].present?
|
FileUtils.rm_rf(@tmp_directory) if Dir[@tmp_directory].present?
|
||||||
rescue
|
rescue => ex
|
||||||
log "Something went wrong while removing the following tmp directory: #{@tmp_directory}"
|
log "Something went wrong while removing the following tmp directory: #{@tmp_directory}", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpause_sidekiq
|
def unpause_sidekiq
|
||||||
log "Unpausing sidekiq..."
|
log "Unpausing sidekiq..."
|
||||||
Sidekiq.unpause!
|
Sidekiq.unpause!
|
||||||
rescue
|
rescue => ex
|
||||||
log "Something went wrong while unpausing Sidekiq."
|
log "Something went wrong while unpausing Sidekiq.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_readonly_mode
|
def disable_readonly_mode
|
||||||
return if @readonly_mode_was_enabled
|
return if @readonly_mode_was_enabled
|
||||||
log "Disabling readonly mode..."
|
log "Disabling readonly mode..."
|
||||||
Discourse.disable_readonly_mode
|
Discourse.disable_readonly_mode
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while disabling readonly mode.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_backup_as_not_running
|
def mark_backup_as_not_running
|
||||||
log "Marking backup as finished..."
|
log "Marking backup as finished..."
|
||||||
BackupRestore.mark_as_not_running!
|
BackupRestore.mark_as_not_running!
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while marking backup as finished.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_directory_exists(directory)
|
def ensure_directory_exists(directory)
|
||||||
@@ -322,11 +330,12 @@ module BackupRestore
|
|||||||
FileUtils.mkdir_p(directory)
|
FileUtils.mkdir_p(directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log(message)
|
def log(message, ex = nil)
|
||||||
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
puts(message)
|
puts(message)
|
||||||
publish_log(message, timestamp)
|
publish_log(message, timestamp)
|
||||||
save_log(message, timestamp)
|
save_log(message, timestamp)
|
||||||
|
Rails.logger.error("#{ex}\n" + ex.backtrace.join("\n")) if ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_log(message, timestamp)
|
def publish_log(message, timestamp)
|
||||||
|
|||||||
@@ -103,12 +103,9 @@ module BackupRestore
|
|||||||
else
|
else
|
||||||
@success = true
|
@success = true
|
||||||
ensure
|
ensure
|
||||||
begin
|
clean_up
|
||||||
notify_user
|
notify_user
|
||||||
clean_up
|
log "Finished!"
|
||||||
rescue => ex
|
|
||||||
Rails.logger.error("#{ex}\n" + ex.backtrace.join("\n"))
|
|
||||||
end
|
|
||||||
|
|
||||||
@success ? log("[SUCCESS]") : log("[FAILED]")
|
@success ? log("[SUCCESS]") : log("[FAILED]")
|
||||||
end
|
end
|
||||||
@@ -459,6 +456,8 @@ module BackupRestore
|
|||||||
else
|
else
|
||||||
log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..."
|
log "Could not send notification to '#{@user_info[:username]}' (#{@user_info[:email]}), because the user does not exists..."
|
||||||
end
|
end
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while notifying user.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_up
|
def clean_up
|
||||||
@@ -467,32 +466,35 @@ module BackupRestore
|
|||||||
unpause_sidekiq
|
unpause_sidekiq
|
||||||
disable_readonly_mode if Discourse.readonly_mode?
|
disable_readonly_mode if Discourse.readonly_mode?
|
||||||
mark_restore_as_not_running
|
mark_restore_as_not_running
|
||||||
log "Finished!"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_tmp_directory
|
def remove_tmp_directory
|
||||||
log "Removing tmp '#{@tmp_directory}' directory..."
|
log "Removing tmp '#{@tmp_directory}' directory..."
|
||||||
FileUtils.rm_rf(@tmp_directory) if Dir[@tmp_directory].present?
|
FileUtils.rm_rf(@tmp_directory) if Dir[@tmp_directory].present?
|
||||||
rescue
|
rescue => ex
|
||||||
log "Something went wrong while removing the following tmp directory: #{@tmp_directory}"
|
log "Something went wrong while removing the following tmp directory: #{@tmp_directory}", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpause_sidekiq
|
def unpause_sidekiq
|
||||||
log "Unpausing sidekiq..."
|
log "Unpausing sidekiq..."
|
||||||
Sidekiq.unpause!
|
Sidekiq.unpause!
|
||||||
rescue
|
rescue => ex
|
||||||
log "Something went wrong while unpausing Sidekiq."
|
log "Something went wrong while unpausing Sidekiq.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_readonly_mode
|
def disable_readonly_mode
|
||||||
return if @readonly_mode_was_enabled
|
return if @readonly_mode_was_enabled
|
||||||
log "Disabling readonly mode..."
|
log "Disabling readonly mode..."
|
||||||
Discourse.disable_readonly_mode
|
Discourse.disable_readonly_mode
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while disabling readonly mode.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_restore_as_not_running
|
def mark_restore_as_not_running
|
||||||
log "Marking restore as finished..."
|
log "Marking restore as finished..."
|
||||||
BackupRestore.mark_as_not_running!
|
BackupRestore.mark_as_not_running!
|
||||||
|
rescue => ex
|
||||||
|
log "Something went wrong while marking restore as finished.", ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_directory_exists(directory)
|
def ensure_directory_exists(directory)
|
||||||
@@ -500,11 +502,12 @@ module BackupRestore
|
|||||||
FileUtils.mkdir_p(directory)
|
FileUtils.mkdir_p(directory)
|
||||||
end
|
end
|
||||||
|
|
||||||
def log(message)
|
def log(message, ex = nil)
|
||||||
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
puts(message)
|
puts(message)
|
||||||
publish_log(message, timestamp)
|
publish_log(message, timestamp)
|
||||||
save_log(message, timestamp)
|
save_log(message, timestamp)
|
||||||
|
Rails.logger.error("#{ex}\n" + ex.backtrace.join("\n")) if ex
|
||||||
end
|
end
|
||||||
|
|
||||||
def publish_log(message, timestamp)
|
def publish_log(message, timestamp)
|
||||||
|
|||||||
Reference in New Issue
Block a user