Fix B2 bucket upload issue and store b2_enabled in config
This commit addresses two main issues: The 'b2_enabled' value was not being stored in the config JSON. Added it to the config JSON to enable or disable B2 bucket uploads as needed. Corrected the execution of b2-cli commands in the MysqlDatabaseBackup class using backticks for proper shell command execution in Ruby. These changes should resolve the issue of the database dump file not being uploaded to the B2 bucket.
This commit is contained in:
parent
e73eef1064
commit
496be85eaa
|
@ -27,7 +27,6 @@ class MysqlDatabaseBackup
|
|||
return unless @b2_enabled
|
||||
|
||||
upload_to_b2(backup_file)
|
||||
|
||||
end
|
||||
|
||||
def delete_old_backups
|
||||
|
@ -52,16 +51,16 @@ class MysqlDatabaseBackup
|
|||
b2_file_url = "b2://#{@b2_bucket_name}/#{b2_file_name}"
|
||||
# Check if a backup file with the same name already exists in the B2 bucket
|
||||
|
||||
existing_file = b2-cli list-file-names #{@b2_bucket_name} --prefix #{b2_file_name}
|
||||
existing_file = `b2-cli list-file-names #{@b2_bucket_name} --prefix #{b2_file_name}`
|
||||
if existing_file.include?(b2_file_name)
|
||||
# Delete the existing backup file from the B2 bucket
|
||||
file_version = existing_file.match(/"fileId": "([^"]+)"/)[1]
|
||||
b2-cli delete-file-version #{@b2_bucket_name} #{b2_file_name} #{file_version}
|
||||
`b2-cli delete-file-version #{@b2_bucket_name} #{b2_file_name} #{file_version}`
|
||||
puts "Deleted existing backup file from B2 bucket: #{b2_file_url}"
|
||||
end
|
||||
Upload the backup file to the B2 bucket
|
||||
# Upload the backup file to the B2 bucket
|
||||
|
||||
b2-cli upload-file #{@b2_bucket_name} #{backup_file} #{b2_file_name}
|
||||
`b2-cli upload-file #{@b2_bucket_name} #{backup_file} #{b2_file_name}`
|
||||
puts "Uploaded backup file to B2 bucket: #{b2_file_url}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,10 +20,13 @@ class MysqlDatabaseConfig
|
|||
backup_dir = prompt('Backup Directory', default: '.')
|
||||
|
||||
b2_enabled = prompt_bool('Enable Backblaze B2?', default: false)
|
||||
config['b2_enabled'] = b2_enabled
|
||||
if b2_enabled
|
||||
@b2_key_id = prompt('Backblaze B2 Key ID')
|
||||
@b2_application_key = prompt('Backblaze B2 Application Key')
|
||||
@b2_bucket_name = prompt('Backblaze B2 Bucket Name')
|
||||
config['b2'] = {
|
||||
'key_id' => @b2_key_id,
|
||||
'application_key' => @b2_application_key,
|
||||
'bucket_name' => @b2_bucket_name
|
||||
}
|
||||
end
|
||||
|
||||
config = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user