Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Created December 5, 2018 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/b07ef229d155101f88188d76361411d6 to your computer and use it in GitHub Desktop.
Save npodonnell/b07ef229d155101f88188d76361411d6 to your computer and use it in GitHub Desktop.
Very simple file backup script using rsync
#!/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