Class: DbBackup
Direct Known Subclasses
Constant Summary
Constants inherited from Backup
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #clean_files ⇒ Object
- #ensure_path ⇒ Object
- #filename ⇒ Object
- #filepath ⇒ Object
-
#initialize(user: nil, database: nil, password: nil, compress: true, host: nil, encrypt: nil) ⇒ DbBackup
constructor
A new instance of DbBackup.
- #path ⇒ Object
- #restore_path ⇒ Object
Methods inherited from Backup
#backup_command, #backup_type, #compress?, #debug?, #encrypt?, #encrypt_compress_pipe_command, #filename_extension, #get_datetime_from_filename, #minimum_backup_size, #output_command, #print_info, #run, #verify_backup
Constructor Details
#initialize(user: nil, database: nil, password: nil, compress: true, host: nil, encrypt: nil) ⇒ DbBackup
Returns a new instance of DbBackup.
6 7 8 9 10 11 12 |
# File 'lib/backup/db_backup.rb', line 6 def initialize user: nil, database: nil, password: nil, compress: true, host: nil, encrypt: nil super compress: compress, encrypt: encrypt user = ENV['USER'] if user.nil? password = ENV['PASSWORD'] if password.nil? @password, @user, @database, @host = password, user, database, host ensure_path unless database.nil? end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
4 5 6 |
# File 'lib/backup/db_backup.rb', line 4 def database @database end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
4 5 6 |
# File 'lib/backup/db_backup.rb', line 4 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
4 5 6 |
# File 'lib/backup/db_backup.rb', line 4 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/backup/db_backup.rb', line 4 def user @user end |
Instance Method Details
#clean_files ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/backup/db_backup.rb', line 34 def clean_files result = {} # true - delete file, false - do not delete months_taken = [] days_taken = [] files = Dir.entries(path) - ['.', '..'] files.each do |file| datetime = get_datetime_from_filename(file) day_id = datetime.strftime('%Y-%m-%d') month_id = datetime.strftime('%Y-%m') if datetime < (DateTime.now << 2) # 1 month ago if datetime.day == 1 && !(months_taken.include? month_id) result[file] = false months_taken << month_id else result[file] = true end elsif datetime < DateTime.now - 14 # 2 weeks ago if [1, 7, 14, 21].include?(datetime.day) && !(days_taken.include?(day_id)) result[file] = false days_taken << day_id else result[file] = true end elsif days_taken.includ end end end |
#ensure_path ⇒ Object
30 31 32 |
# File 'lib/backup/db_backup.rb', line 30 def ensure_path `mkdir -p #{path}` end |
#filename ⇒ Object
14 15 16 |
# File 'lib/backup/db_backup.rb', line 14 def filename "#{backup_type}-#{database}-#{DateTime.now.strftime(DATE_FORMAT)}.#{filename_extension('sql')}" end |
#filepath ⇒ Object
26 27 28 |
# File 'lib/backup/db_backup.rb', line 26 def filepath "#{path}/#{filename}" end |
#path ⇒ Object
18 19 20 |
# File 'lib/backup/db_backup.rb', line 18 def path "#{Techinform::BACKUPS_LOCAL_PREFIX}/#{backup_type}/#{database}" end |
#restore_path ⇒ Object
22 23 24 |
# File 'lib/backup/db_backup.rb', line 22 def restore_path "#{Techinform::BACKUPS_ALL_PREFIX}/backups/#{backup_type}/#{database}" end |