Last active
June 17, 2017 19:41
-
-
Save jrh-spg/491ad66b3182c1310c5ec9418a4bee8b to your computer and use it in GitHub Desktop.
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
#!/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