diff --git a/lib/backup_restore/backuper.rb b/lib/backup_restore/backuper.rb index 49c4252ffeb..bbdf0c561a7 100644 --- a/lib/backup_restore/backuper.rb +++ b/lib/backup_restore/backuper.rb @@ -256,9 +256,6 @@ module BackupRestore content_type = MiniMime.lookup_by_filename(@backup_filename).content_type archive_path = File.join(@archive_directory, @backup_filename) @store.upload_file(@backup_filename, archive_path, content_type) - ensure - log "Removing archive from local storage..." - FileUtils.remove_file(archive_path, force: true) end def after_create_hook @@ -294,6 +291,7 @@ module BackupRestore def clean_up log "Cleaning stuff up..." + delete_uploaded_archive remove_tar_leftovers unpause_sidekiq disable_readonly_mode if Discourse.readonly_mode? @@ -301,6 +299,19 @@ module BackupRestore refresh_disk_space end + def delete_uploaded_archive + return unless @store.remote? + + archive_path = File.join(@archive_directory, @backup_filename) + + if File.exist?(archive_path) + log "Removing archive from local storage..." + File.delete(archive_path) + end + rescue => ex + log "Something went wrong while deleting uploaded archive from local storage.", ex + end + def refresh_disk_space log "Refreshing disk stats..." @store.reset_cache diff --git a/lib/backup_restore/local_backup_store.rb b/lib/backup_restore/local_backup_store.rb index ae1c06e9154..b80b3fb031e 100644 --- a/lib/backup_restore/local_backup_store.rb +++ b/lib/backup_restore/local_backup_store.rb @@ -33,7 +33,7 @@ module BackupRestore path = path_from_filename(filename) if File.exists?(path) - FileUtils.remove_file(path, force: true) + File.delete(path) reset_cache end end