Class: EasySync::Rsync
- Inherits:
-
Object
- Object
- EasySync::Rsync
- Defined in:
- lib/easy_sync/rsync.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#exclude_file ⇒ Object
readonly
Returns the value of attribute exclude_file.
-
#last_snapshot ⇒ Object
readonly
Returns the value of attribute last_snapshot.
-
#logging ⇒ Object
readonly
Returns the value of attribute logging.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#sync_name ⇒ Object
readonly
Returns the value of attribute sync_name.
Instance Method Summary collapse
- #current_snapshot ⇒ Object
-
#initialize(options) ⇒ Rsync
constructor
A new instance of Rsync.
- #latest_snapshot ⇒ Object
- #remove_old_backups ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(options) ⇒ Rsync
Returns a new instance of Rsync.
9 10 11 12 13 14 15 |
# File 'lib/easy_sync/rsync.rb', line 9 def initialize() @sync_name = [:sync_name] @source = [:source] @destination = [:destination] @exclude_file = [:exclude_file] @logging = .fetch(:logging){:off} end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def current @current end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def destination @destination end |
#exclude_file ⇒ Object (readonly)
Returns the value of attribute exclude_file.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def exclude_file @exclude_file end |
#last_snapshot ⇒ Object (readonly)
Returns the value of attribute last_snapshot.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def last_snapshot @last_snapshot end |
#logging ⇒ Object (readonly)
Returns the value of attribute logging.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def logging @logging end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def source @source end |
#sync_name ⇒ Object (readonly)
Returns the value of attribute sync_name.
7 8 9 |
# File 'lib/easy_sync/rsync.rb', line 7 def sync_name @sync_name end |
Instance Method Details
#current_snapshot ⇒ Object
21 22 23 |
# File 'lib/easy_sync/rsync.rb', line 21 def current_snapshot @current = File.join destination, Time.now.strftime("%Y-%m-%d") end |
#latest_snapshot ⇒ Object
17 18 19 |
# File 'lib/easy_sync/rsync.rb', line 17 def latest_snapshot @last_snapshot = Dir["#{destination}/*"].max end |
#remove_old_backups ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/easy_sync/rsync.rb', line 25 def remove_old_backups backups = Dir["#{destination}/*"] (backups - backups.last(5)).each do |r| puts "Removing #{r}" FileUtils.remove_dir(r, true) end end |
#sync ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/easy_sync/rsync.rb', line 35 def sync commands = [ "rsync", "-avhiPH", "--exclude-from", "#{exclude_file}", "--link-dest", "#{latest_snapshot}" ] commands << ['--log-file', "#{ENV['HOME']}/easy_sync.log" ] if logging == :on commands << ["#{source}", "#{current_snapshot}"] commands = commands.flatten puts "\n\n\n------------------ Running #{sync_name} ------------------\n\n\n" remove_old_backups puts "latest snapshot #{@last_snapshot}" IO.popen(commands).each_line do |l| puts l end end |