Created
December 5, 2018 00:50
-
-
Save npodonnell/b07ef229d155101f88188d76361411d6 to your computer and use it in GitHub Desktop.
Very simple file backup script using rsync
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
#!/usr/bin/bash | |
INTERVAL=10 | |
SRC_DIRS=( Documents ) | |
DEST_HOST=192.168.0.1 | |
DEST_USER=user | |
DEST_DIR="~/backup" # Quotes are important! | |
if [ -e ~/.syncfiles.lock ]; then | |
echo "lockfile detected" | |
exit 0 | |
fi | |
touch ~/.syncfiles.lock && echo "Created lockfile" | |
trap "{ rm ~/.syncfiles.lock; echo \"lockfile removed\"; exit 255; }" EXIT | |
while [ true ]; do | |
rsync -r ${SRC_DIRS[@]} $DEST_USER@$DEST_HOST:$DEST_DIR | |
sleep $INTERVAL | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment