Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Simple Raspberry Pi file sync

#technical

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.