Created
January 27, 2011 09:30
-
-
Save danlucraft/798288 to your computer and use it in GitHub Desktop.
handy script for rsyncing between machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'fsevents' | |
require 'fileutils' | |
STDOUT.sync = true | |
project = ARGV[0] || 'skweb' | |
options = { | |
:directory_to_watch => "/Users/danlucraft/Songkick/#{project}", | |
:remote_host => 'of1-dev-dan', | |
:remote_dir => "development/#{project}" | |
} | |
def sync(options) | |
start = Time.now | |
cmd = "rsync -varx --delete -e ssh --exclude='log/*' --exclude='*.yml.201*' --exclude='.redcar' --exclude='.git' --exclude='tmp/*' --exclude='*.css' #{options[:directory_to_watch]}/ #{options[:remote_host]}:#{options[:remote_dir]}/" | |
puts cmd | |
puts `#{cmd}` | |
puts "Synced in " | |
puts "#{sprintf('%.2f', Time.now - start)}s" | |
$0 = "Last #{Time.now.strftime("%X")}" | |
puts $0 | |
end | |
sync(options) | |
FileUtils.cd(options[:directory_to_watch]) do | |
stream = FSEvents::Stream.watch(options[:directory_to_watch], :latency => 2.5) do | |
sync(options) | |
end | |
stream.run | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment