Skip to content

Instantly share code, notes, and snippets.

@jrh-spg
Last active June 17, 2017 19:41
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 jrh-spg/491ad66b3182c1310c5ec9418a4bee8b to your computer and use it in GitHub Desktop.
Save jrh-spg/491ad66b3182c1310c5ec9418a4bee8b to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create the lock file to prevent parallel instances.
LOCKFILE=/tmp/.backup.sh.lck
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "already running"
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
# What to backup.
backup_files="/home/jake /root /var /etc"
# Where to backup to.
dest="/backup"
# Set the bandwidth limit in KBytes.
bwlimit=25000
# What to exclude
excludes=".cache"
# To infinity and beyond!
sudo rsync --bwlimit=$bwlimit --exclude=$excludes -Pav $backup_files $dest
# Remove the lock file after a succesful backup.
rm -f ${LOCKFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment