Class: Baya::Adapters::Rsync
- Inherits:
-
Object
- Object
- Baya::Adapters::Rsync
- Defined in:
- lib/baya/adapters/rsync.rb
Instance Method Summary collapse
- #archive(root) ⇒ Object
- #backup(root) ⇒ Object
-
#initialize(config) ⇒ Rsync
constructor
A new instance of Rsync.
Constructor Details
#initialize(config) ⇒ Rsync
Returns a new instance of Rsync.
8 9 10 |
# File 'lib/baya/adapters/rsync.rb', line 8 def initialize(config) @config = config end |
Instance Method Details
#archive(root) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/baya/adapters/rsync.rb', line 12 def archive(root) target = root + "/" + @config['destination'] source = @config['source'] rsync_archive(source, target) end |
#backup(root) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/baya/adapters/rsync.rb', line 19 def backup(root) target = root + "/" + @config['destination'] source = @config['source'] date = Time.now.strftime("%Y%m%d%H%M%S") previous = Dir[target + "/*/"].sort_by { |a| File.basename(a) } rsync_backup(source, target + "/" + date, previous.last) if keep = @config['keepBackups'] && @config['keepBackups'].to_i if previous.count - keep > 0 to_delete = previous[0..previous.count - keep] to_delete.each do |f| FileUtils.rmtree(f) end end end end |