Fix bug in upload_to_b2 method to delete existing
files in B2 bucket with different names before uploading new backup file.
This commit is contained in:
parent
44e4e9aef8
commit
5b9ce0e341
|
@ -56,6 +56,7 @@ class MysqlDatabaseBackup
|
|||
# Check if a backup file with the same name already exists in the B2 bucket
|
||||
|
||||
existing_files = `b2 ls #{@b2_bucket_name}`
|
||||
unless existing_files.empty?
|
||||
existing_files.each_line do |line|
|
||||
file_name = line.split(' ').last.strip
|
||||
next unless file_name != b2_file_name
|
||||
|
@ -64,9 +65,11 @@ class MysqlDatabaseBackup
|
|||
`b2 delete-file-version #{@b2_bucket_name} #{file_name} #{file_id}`
|
||||
puts "Deleted existing backup file from B2 bucket: #{file_name}"
|
||||
end
|
||||
# Upload the backup file to the B2 bucket
|
||||
end
|
||||
|
||||
# Upload the backup file to the B2 bucket
|
||||
`b2 upload-file #{@b2_bucket_name} #{backup_file} #{b2_file_name}`
|
||||
puts "Uploaded backup file to B2 bucket: #{b2_file_url}"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user