You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
998 B
Bash

#!/bin/bash
# Backup home dir via rdiff-backup
# Then rsync it to remote
# e.g. 0 */1 * * * /home/nathan/scripts/backup/backup_home.sh -d /home/nathan -b /srv/dev-disk-by-uuid-d9f9e8fd-c473-450e-919e-c43200a6ac4a/nathan/lilman/ -r nathan@alphavps.aney.co.uk -R ~/backups/home/lilman
while getopts s:d:b:r:R:n: flag
do
case "${flag}" in
d) DATA=${OPTARG};;
b) BACKUPDIR=${OPTARG};;
r) REMOTE=${OPTARG};;
R) REMOTEBACKUP=${OPTARG};;
n) NOW=${OPTARG};;
esac
done
mkdir -p $BACKUPDIR
# Incremental backup of the directory locally (hourly?)
rdiff-backup $DATA $BACKUPDIR
# Don't keep backups over 1W
rdiff-backup --force --remove-older-than 1W $BACKUPDIR
# Backup to remote
TIME=$(date +%H%M)
if [ "$TIME" = 0000 ] || [ "$NOW" = 1 ]
then
# Create the remote directory for backup if it doesn't exist
ssh $REMOTE mkdir -p $REMOTEBACKUP
# Copy the backup accross
# -e ssh makes it secure
rsync -azh -e ssh \
--delete \
$BACKUPDIR \
$REMOTE:$REMOTEBACKUP
fi