class BackupS3::Cycler
no docs
Public Class Methods
new(name)
click to toggle source
# File lib/backup_aws_s3.rb, line 33 def initialize(name) @name = name end
Public Instance Methods
cycle!(opt = {})
click to toggle source
# File lib/backup_aws_s3.rb, line 44 def cycle!(opt = {}) backups = yaml_load.unshift( path: opt[:path], time: Time.now.strftime('%Y.%m.%d.%H.%M.%S') ) excess = backups.count - opt[:keep].to_i if excess > 0 backups.pop(excess).each do |backup| begin remove!(backup[:path]) rescue => err p "Error removing old backups: #{err}" end end end yaml_save(backups) end
remove!(directory)
click to toggle source
# File lib/backup_aws_s3.rb, line 37 def remove!(directory) p "Removing old backup: #{directory}" s3 = Manage::S3::new(ENV['S3_ACCESS_KEY_ID'], ENV['S3_SECRET_KEY_ID']) s3.remove_path(directory) p "Removed old backup: #{directory}" end
yaml_file()
click to toggle source
Returns path to the YAML data file.
# File lib/backup_aws_s3.rb, line 63 def yaml_file @yaml_file ||= begin home_path = File.expand_path('~') File.join(home_path, 'backup_aws_s3', "#{ @name }.yml") end end
yaml_load()
click to toggle source
Returns stored Package objects, sorted by time descending (oldest last).
# File lib/backup_aws_s3.rb, line 71 def yaml_load if File.exist?(yaml_file) && !File.zero?(yaml_file) # raise YAML.load_file(yaml_file).inspect YAML.load_file(yaml_file).sort_by!{|b| b[:time]}.reverse! else [] end end
yaml_save(backups)
click to toggle source
Stores the given package objects to the YAML data file.
# File lib/backup_aws_s3.rb, line 81 def yaml_save(backups) FileUtils.mkdir_p(File.dirname(yaml_file)) File.open(yaml_file, 'w') do |file| file.write(backups.to_yaml) end end