Class: UBSafe::Commands::MySqlBackup
- Defined in:
- lib/ubsafe/ubsafe_commands/ubsafe_command_backup_mysql.rb
Instance Method Summary collapse
-
#after_clean_source ⇒ Symbol
Hook to allow customization after cleaning source.
-
#before_source_backup ⇒ Symbol
Hook to allow customization before creating source backup.
Methods inherited from Backup
#after_copy_backup, #after_rotate_destination_files, #after_source_backup, #all_backup_names, #backup, #before_clean_source, #before_copy_backup, #before_rotate_destination_files, #clean_source, #copy_backup, #create_and_copy_backup, #create_source_backup, #email_notify, #get_backup_file_name, #get_backup_file_name_with_generation, #get_remote_modified_timestamp, #initialize, instance, #remote_file_exists?, #rotate_destination_files, #rotate_destination_files_unconditionally, #scp_cmd, #ssh_cmd
Constructor Details
This class inherits a constructor from UBSafe::Commands::Backup
Instance Method Details
#after_clean_source ⇒ Symbol
Hook to allow customization after cleaning source
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ubsafe/ubsafe_commands/ubsafe_command_backup_mysql.rb', line 38 def after_clean_source tmp_dir = File.(@backup_options[:temporary_directory]) mysql_tmp_dir = File.join(tmp_dir,'mysql') cmd_output = `rm -rf #{mysql_tmp_dir}` cmd_status = $? cmd_status == 0 ? :success : :failure if cmd_status == :failure @log.error("Backup #{@backup_name} after_clean_source failed. Output #{cmd_output}") end return cmd_status end |
#before_source_backup ⇒ Symbol
Hook to allow customization before creating source backup
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ubsafe/ubsafe_commands/ubsafe_command_backup_mysql.rb', line 14 def before_source_backup tmp_dir = File.(@backup_options[:temporary_directory]) mysql_tmp_dir = File.join(tmp_dir,'mysql') FileUtils.mkdir_p(mysql_tmp_dir) cmd = " mysqldump -u#{@backup_options[:mysql_username]} -p#{@backup_options[:mysql_password]} -h#{@backup_options[:mysql_host]} #{@backup_options[:mysql_database]} >#{mysql_tmp_dir}/#{@backup_options[:mysql_database]}.sql" @log.info("Backup #{@backup_name} \"mysqldump -u#{@backup_options[:mysql_username]} -p[PASSWORD] -h#{@backup_options[:mysql_host]} #{@backup_options[:mysql_database]} >#{mysql_tmp_dir}/#{@backup_options[:mysql_database]}.sql\"") cmd_output = `#{cmd}` cmd_status = $? cmd_status = cmd_status == 0 ? :success : :failure if cmd_status == :failure # cleanup cmd_output = `rm -rf #{mysql_tmp_dir}` @log.error("Backup #{@backup_name} before_source_backup failed during mysqldump. Output #{cmd_output}") end # Point source to directory with dump file in it so rest of the world works @backup_options[:source_tree] = mysql_tmp_dir return cmd_status end |