Created
August 8, 2012 15:56
-
-
Save manchunlam/3296182 to your computer and use it in GitHub Desktop.
Fire rsync if Changes are Detected in Directory
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
# source: http://pastebin.com/viMSaRh3 | |
# Invoke rsync when there are changes in the current directory | |
# 1. Change to project root, `cd /Users/joelam/Projects/tabs` | |
# 2. Initial rsync local to VM, `rsync -avzi -e ssh . deploy@joelam.dev.cloud.vitrue.com:/home/deploy/Projects/Vitrue/tabs/` | |
# 3. Please place this file in project_root (e.g. /Users/joelam/Projects/tabs/) | |
# 4. Run the script by `ruby fsevent_rsync.rb` | |
# 5. Modify any file in directory | |
# 6. rsync is executed, modified files are copied to VM | |
require 'rb-fsevent' | |
require 'open3' | |
include Open3 | |
options = { :latency => 2 } | |
vm_name = "joeshmoe" # from your dev VM URL | |
rsync = 'rsync -avzic -e ssh --delete --include-from ".rsynckeep" ' \ | |
'--exclude-from ".rsyncignore" . ' \ | |
"deploy@#{vm_name}.dev.cloud.vitrue.com:/home/deploy/Projects/Vitrue/tabs/" | |
fsevent = FSEvent.new | |
fsevent.watch Dir.pwd, options do |directories| | |
puts "Detected change inside: #{directories.inspect}" | |
popen3(rsync) do |stdin, stdout, stderr| | |
stdout.read.split("\n").map { |line| | |
puts "rsync: #{line}" | |
} | |
end | |
end | |
fsevent.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rsync ignore and keep setting files