Skip to content

Instantly share code, notes, and snippets.

@sethrh
Created July 13, 2017 20:48
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 sethrh/4be539457cc0ea460601626dc521eeb4 to your computer and use it in GitHub Desktop.
Save sethrh/4be539457cc0ea460601626dc521eeb4 to your computer and use it in GitHub Desktop.
Rdiff-backup shell script.
#!/bin/bash
# Shell script to run rdiff-backup.
# Put this in your crontab to run this every hour:
# 0 * * * * /home/seth/root/bin/backup.sh
# Change these locations to suit
BACKUP_DIR=/opt/backup/$HOSTNAME
BACKUP_LOG=$HOME/backup.log
savelog -n -c 7 "$BACKUP_LOG"
if [ ! -e $BACKUP_DIR ]; then
echo "$(date -R) Warning: backup directory missing; is your backup disk mounted?" | tee -a "$BACKUP_LOG"
fi
echo "$(date -R) Backup started" >> "$BACKUP_LOG"
rdiff-backup --print-statistics "$HOME" "$BACKUP_DIR" 2>>"$BACKUP_LOG"
if [ $? != 0 ]; then
echo "rdiff-backup exit Code: $status - Command Unsuccessful" >>"$BACKUP_LOG";
echo "$(date -R) Backup failed" >> "$BACKUP_LOG"
exit 1;
fi
# Remove backups older than a year - tune this for your backup size & backup disk size
rdiff-backup --force --remove-older-than 12M "$BACKUP_DIR"
echo "$(date -R) Backup completed" >> "$BACKUP_LOG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment