Simple Raspberry Pi file sync
Doing some experimentation with Raspberry Pi and looked into how to automate code copying.
To copy files it’s simple enough to use rsync
:
rsync -rvaz --delete ./ pi@192.168.0.108:/home/pi/code/${PWD##*/} --exclude="*.git" --exclude="*.vscode" --exclude=".gitignore" --exclude="*~"
This would copy all files in current directory to the equivalent directory in code/
on the pi located at 192.168.0.108 (pi has a static IP) and would exclude git, vscode and temp files.
Then I aliased this to rsync-current
.
Finally I used inotifywait
to trigger when files are changed and then execute a command.
while inotifywait ./* ; do rsync-current; done
This will wait for a file change and execute rsync-current
. Granted it will execute whenever the modified date changes regardless of whether there are content changes, but it’s good enough.
All in all it functions almost exactly like guard
.