Class: Leipreachan::DBBackup
- Inherits:
-
Object
- Object
- Leipreachan::DBBackup
- Defined in:
- lib/leipreachan.rb
Direct Known Subclasses
Constant Summary collapse
- MAX_DAYS =
30
- DIRECTORY =
'backups'
Instance Attribute Summary collapse
-
#backup_file ⇒ Object
Returns the value of attribute backup_file.
-
#backup_folder ⇒ Object
Returns the value of attribute backup_folder.
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#db_config ⇒ Object
Returns the value of attribute db_config.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#max_days ⇒ Object
Returns the value of attribute max_days.
-
#target_date ⇒ Object
Returns the value of attribute target_date.
Instance Method Summary collapse
- #backup! ⇒ Object
-
#initialize(env) ⇒ DBBackup
constructor
A new instance of DBBackup.
- #list ⇒ Object
- #restore! ⇒ Object
- #restorelast! ⇒ Object
Constructor Details
#initialize(env) ⇒ DBBackup
Returns a new instance of DBBackup.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/leipreachan.rb', line 25 def initialize env @max_days = (env['DAYS'] || MAX_DAYS).to_i @target_date = env['DATE'] @backup_folder = env['DATE'] || Time.now.strftime("%Y%m%d") @directory = env['DIR'] || DIRECTORY datetime_stamp = Time.now.strftime("%Y%m%d%H%M%S") @base_path = File.join(Rails.root, directory) file_name = "#{datetime_stamp}.sql" @backup_file = File.join(backup_base_on(backup_folder), file_name) @db_config = ActiveRecord::Base.configurations[Rails.env] end |
Instance Attribute Details
#backup_file ⇒ Object
Returns the value of attribute backup_file.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def backup_file @backup_file end |
#backup_folder ⇒ Object
Returns the value of attribute backup_folder.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def backup_folder @backup_folder end |
#base_path ⇒ Object
Returns the value of attribute base_path.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def base_path @base_path end |
#db_config ⇒ Object
Returns the value of attribute db_config.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def db_config @db_config end |
#directory ⇒ Object
Returns the value of attribute directory.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def directory @directory end |
#max_days ⇒ Object
Returns the value of attribute max_days.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def max_days @max_days end |
#target_date ⇒ Object
Returns the value of attribute target_date.
17 18 19 |
# File 'lib/leipreachan.rb', line 17 def target_date @target_date end |
Instance Method Details
#backup! ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/leipreachan.rb', line 39 def backup! FileUtils.mkdir_p(backup_base_on(backup_folder)) dbbackup! puts "Created backup: #{backup_file}.gz" backups_count = Dir.new(backup_base_on(backup_folder)).entries.select{|name| name.match(/sql.gz$/)}.size puts "#{backups_count} backups available for #{backup_folder} date" remove_unwanted_backups end |
#list ⇒ Object
57 58 59 |
# File 'lib/leipreachan.rb', line 57 def list target_date.present? ? single_date(target_date) : all_dates end |
#restore! ⇒ Object
49 50 51 |
# File 'lib/leipreachan.rb', line 49 def restore! dbrestore! get_file_for_restore end |
#restorelast! ⇒ Object
53 54 55 |
# File 'lib/leipreachan.rb', line 53 def restorelast! dbrestore! get_lastfile_for_restore end |