Class: EngineYard::Backup
- Inherits:
-
Object
- Object
- EngineYard::Backup
- Includes:
- FileUtils
- Defined in:
- lib/backup/backup.rb
Constant Summary collapse
- VERSION =
"0.0.1"- RELEASES =
5- TIMESTAMP =
"%Y%m%d%H%M%S"
Instance Attribute Summary collapse
-
#backups ⇒ Object
readonly
Returns the value of attribute backups.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #backup_current ⇒ Object
-
#delete_old_backups ⇒ Object
Look for releases and delete the oldest ones outside of our RELEASES threshold.
-
#find_all_releases ⇒ Object
Find all versions of our backup filename, which match file.TIMESTAMP.
-
#initialize(file) ⇒ Backup
constructor
A new instance of Backup.
- #keep_list ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(file) ⇒ Backup
Returns a new instance of Backup.
12 13 14 15 |
# File 'lib/backup/backup.rb', line 12 def initialize(file) raise "No such file found" unless File.file?(file) @filename, @backups = file, [] end |
Instance Attribute Details
#backups ⇒ Object (readonly)
Returns the value of attribute backups.
5 6 7 |
# File 'lib/backup/backup.rb', line 5 def backups @backups end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/backup/backup.rb', line 5 def filename @filename end |
Instance Method Details
#backup_current ⇒ Object
22 23 24 |
# File 'lib/backup/backup.rb', line 22 def backup_current FileUtils.mv(@filename, "#{@filename}.#{Time.now.strftime(TIMESTAMP)}") end |
#delete_old_backups ⇒ Object
Look for releases and delete the oldest ones outside of our RELEASES threshold
27 28 29 30 31 |
# File 'lib/backup/backup.rb', line 27 def delete_old_backups find_all_releases delete_list = @backups - keep_list delete_list.each {|f| File.delete(f) } end |
#find_all_releases ⇒ Object
Find all versions of our backup filename, which match file.TIMESTAMP
38 39 40 41 42 43 44 45 46 |
# File 'lib/backup/backup.rb', line 38 def find_all_releases Dir.chdir(File.dirname(@filename)) backups = Dir.glob("#{File.basename(@filename)}.*") remove_faults(backups) backups.sort! do |x,y| Date.strptime(x.split(".").last, TIMESTAMP) <=> Date.strptime(y.split(".").last, TIMESTAMP) end @backups = backups end |
#keep_list ⇒ Object
33 34 35 |
# File 'lib/backup/backup.rb', line 33 def keep_list @backups[-RELEASES..-1] end |
#run ⇒ Object
17 18 19 20 |
# File 'lib/backup/backup.rb', line 17 def run backup_current delete_old_backups end |