Skip to content

Instantly share code, notes, and snippets.

@manchunlam
Created August 8, 2012 15:56
Show Gist options
  • Save manchunlam/3296182 to your computer and use it in GitHub Desktop.
Save manchunlam/3296182 to your computer and use it in GitHub Desktop.
Fire rsync if Changes are Detected in Directory
# 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
@manchunlam
Copy link
Author

25d8d5a fixes

  • Switching to a new branch on local dev does not delete files that exist only in the original branch on the VM

@manchunlam
Copy link
Author

rsync ignore and keep setting files

  1. .rsyncignore
  2. .rsynckeep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment