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
- #sync ⇒ Object
Constructor Details
#initialize(options) ⇒ Rsync
Returns a new instance of Rsync.
8 9 10 11 12 13 14 |
# File 'lib/easy_sync/rsync.rb', line 8 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.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def current @current end |
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def destination @destination end |
#exclude_file ⇒ Object (readonly)
Returns the value of attribute exclude_file.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def exclude_file @exclude_file end |
#last_snapshot ⇒ Object (readonly)
Returns the value of attribute last_snapshot.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def last_snapshot @last_snapshot end |
#logging ⇒ Object (readonly)
Returns the value of attribute logging.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def logging @logging end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def source @source end |
#sync_name ⇒ Object (readonly)
Returns the value of attribute sync_name.
6 7 8 |
# File 'lib/easy_sync/rsync.rb', line 6 def sync_name @sync_name end |
Instance Method Details
#current_snapshot ⇒ Object
20 21 22 |
# File 'lib/easy_sync/rsync.rb', line 20 def current_snapshot @current = File.join destination, Time.now.strftime("%Y-%m-%d") end |
#latest_snapshot ⇒ Object
16 17 18 |
# File 'lib/easy_sync/rsync.rb', line 16 def latest_snapshot @last_snapshot = Dir["#{destination}/*"].max_by{|s| File.mtime s} end |
#sync ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/easy_sync/rsync.rb', line 24 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 name = "\n\n\n------------------ Running #{sync_name} ------------------\n\n\n" puts name IO.popen(commands).each_line do |l| puts l end end |