Last active
August 20, 2019 18:24
-
-
Save boneskull/6d1fc763fa6da4b53c61 to your computer and use it in GitHub Desktop.
rsync stuff to a different directory on file changes (Mac OS X)
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
#!/bin/bash | |
# Get fswatch: brew install fswatch | |
EXCLUDES_FILE="/tmp/syncer-excludes.txt" | |
SOURCES=( "/path/to/folder/to/watch" ) | |
EXCLUDES=( | |
"*.vmwarevm" | |
".DS_Store" | |
"Icon\r" | |
".dropbox" | |
".dropbox.attr" | |
) | |
DEST="/path/to/destination/folder" | |
printf -- '%s\n' "${EXCLUDES[@]}" > ${EXCLUDES_FILE} | |
for SOURCE in ${SOURCES[@]}; do | |
fswatch "${SOURCE}" "echo \"`date +%H:%M:%S`: Changes detected in ${SOURCE}; syncing to ${DEST}\" && /usr/local/bin/rsync -ru --stats --links --copy-unsafe-links --delete --exclude-from=${EXCLUDES_FILE} \"${SOURCE}\" \"${DEST}\"" & | |
done | |
wait ${!} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Debug</key> | |
<true/> | |
<key>Label</key> | |
<string>org.hiller.syncer</string> | |
<key>LowPriorityIO</key> | |
<true/> | |
<key>Program</key> | |
<string>/path/to/hook-line-and-syncer</string> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>StandardErrorPath</key> | |
<string>/usr/local/var/log/hook-line-and-syncer.log</string> | |
<key>StandardOutPath</key> | |
<string>/usr/local/var/log/hook-line-and-syncer.log</string> | |
</dict> | |
</plist> |
(also update whatever path(s) you want watched, and your destination folder in the bash script)
I use this to work outside of Dropbox (which has case-sensitivity problems) then rsync
my crap into the Dropbox dir.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update the
plist
to be the path to the script. You can uselaunchctl load /path/to/org.hiller.syncer.plist
to automatically run this script at boot.