Skip to content

Instantly share code, notes, and snippets.

@Gargron
Created October 14, 2013 15:16
Show Gist options
  • Save Gargron/6977277 to your computer and use it in GitHub Desktop.
Save Gargron/6977277 to your computer and use it in GitHub Desktop.
Script to do an incremental backup of the home directory of a user
#! /bin/sh
DRIVE_PATH="/path/to/drive"
USER="joe"
BACKUP_PATH="$DRIVE_PATH/backups/$USER@$(hostname)"
if command -v rdiff-backup >/dev/null 2>&1; then
echo "Checking drive..."
if ! [ -d "$DRIVE_PATH" ]; then
echo "Backup drive not mounted"
exit 1
fi
echo "About to create home folder backup for $USER@$(hostname)..."
if ! [ -d "$BACKUP_PATH" ]; then
echo "Creating backup destination folder..."
mkdir -p $BACKUP_PATH
fi
if rdiff-backup /home/$USER $BACKUP_PATH >/dev/null 2>&1; then
echo "Done"
else
echo "An error occurred with rdiff-backup"
exit 1
fi
else
echo "rdiff-backup is not installed, it is required"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment