logging and to handle all file naming, storing logs in the backup
directory by default. Made the Loggman class delete logs older than
2 months and create new log files each week. Refactored the
MysqlDatabaseConfig and MysqlDatabaseBackup classes to use the new
Loggman class for logging and added error handling code. Updated the
upload_to_b2 method in MysqlDatabaseBackup to properly handle errors
when listing and deleting old backups in the B2 bucket.
customizable retention and logging
Refactor backup method to dump each database individually
Update delete_old_backups method to remove local backups based on user-defined retention days
Add Loggman class for logging program actions to a logfile and implement log deletion for logs older than a week
Modify MysqlDatabaseConfig class to ask the user for local and B2 backup retention days
Update MysqlDatabaseBackup class to use user-defined retention days for local backups
Refactor upload_to_b2 method to delete B2 backups based on user-defined retention days
Implement various code improvements and refactoring for better readability and maintainability
This commit modifies the upload_to_b2 method in the MysqlDatabaseBackup class to delete all files in the specified Backblaze B2 bucket that do not match the name of the backup file being uploaded. The implementation retrieves a list of all files in the bucket using the b2 ls command and then iterates over each line to extract the name of each file. If the name of a file does not match the name of the backup file, the implementation extracts its file ID using a regular expression and then uses the b2 delete-file-version command to delete the file from the bucket. Finally, the implementation uploads the backup file to the B2 bucket.
This commit modifies the upload_to_b2 method in the MysqlDatabaseBackup class to search for an existing backup file with the same name as the backup file being uploaded in a specified Backblaze B2 bucket. The implementation retrieves a list of all files in the bucket using the b2 ls command and then iterates over each line to search for a file with the same name as the backup file. If a matching file is found, the implementation extracts its file ID using a regular expression and then uses the b2 delete-file-version command to delete the file from the bucket. Note that this implementation assumes that the backup file has a unique name.
The generate method in the MysqlDatabaseConfig class had an error that caused an undefined local variable or method 'config'. The error was due to using the config variable before it was initialized. The solution was to move the code that sets b2_enabled and adds b2 to config after the config variable is initialized. This commit fixes the error by modifying the generate method in the MysqlDatabaseConfig class.
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.