Ru-b2-SQL-Backups/starter.rb
connorc@orbitnode.net 6b2941e3a1 Refactored code to use a new Loggman class for
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.
2023-03-19 17:10:48 -06:00

26 lines
684 B
Ruby

# frozen_string_literal: true
require_relative 'mysql_database_config'
require_relative 'mysql_database_backup'
require_relative 'loggman'
config_file = 'config.json'
logger = Loggman.new
begin
logger.info('Starting script.')
config_generator = MysqlDatabaseConfig.new(config_file)
config_generator.generate
logger.info("Generated MySQL database configuration file: #{config_file}.")
backup = MysqlDatabaseBackup.new(config_file)
backup.backup
logger.info('Performed MySQL database backup.')
logger.info('Script completed successfully.')
rescue StandardError => e
logger.error("An error occurred: #{e.message}")
logger.debug("Backtrace: #{e.backtrace}")
end