Class: DeeBee::Backup

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/dee_bee/backup.rb

Constant Summary

Constants included from Helpers

Helpers::DEFAULT_DAYS_TO_KEEP_DAILY_FILES, Helpers::DEFAULT_DAYS_TO_KEEP_ORPHANS, Helpers::ONE_MONTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#age_in_days, #copy_files_of_pattern_to_directoy, #move_files_of_pattern_to_directoy, #remove_files_not_containing_substrings, #run_command, #symbolize_keys, #time_elapsed_for

Constructor Details

#initialize(configuration = DeeBee::Configuration.new) ⇒ Backup

Returns a new instance of Backup.



9
10
11
# File 'lib/dee_bee/backup.rb', line 9

def initialize (configuration = DeeBee::Configuration.new)
  @backup_settings = configuration.settings['backup']
end

Instance Attribute Details

#backup_settingsObject (readonly)

Returns the value of attribute backup_settings.



7
8
9
# File 'lib/dee_bee/backup.rb', line 7

def backup_settings
  @backup_settings
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dee_bee/backup.rb', line 13

def execute
  puts "\nCreating backup..."
  time_elapsed_for("Create backup") do
    if performing_mysql_backup?
      validate_my_cnf_present
      validate_host_setting_present
      validate_database_name_setting_present
      validate_path_exists

      # NOTE - no use of -u or -p as we are using ~/.my.cnf for these arguments
      run_command("/usr/bin/env mysqldump -h#{database_host} #{database_name} | gzip > #{backup_filepath}")

      validate_mysqldump_created_file
    else
      raise "Unknown/empty database adapter.  Please correct your settings yaml"
    end
  end
end