Skip to content

Instantly share code, notes, and snippets.

@lsolesen
Forked from tsileo/duptools.sh
Created November 28, 2012 22:03
Show Gist options
  • Save lsolesen/4164984 to your computer and use it in GitHub Desktop.
Save lsolesen/4164984 to your computer and use it in GitHub Desktop.
A bash script to simplify backup management with duplicity (encrypted incremental backups via SCP)
#!/bin/bash
# user info
USER=USERNAME
PASSWORD=SECRET
export PASSPHRASE=GPG-PARAPHRASE
# server info
PROTOCOL="scp"
SERVER=SERVERNAME
DIRECTORY=/home/${USER}
# directories, space separated
SOURCE="/data/disk/o1/backups /data/disk/o2/backups /data/disk/o3/backups"
BUCKET=${PROTOCOL}://${USER}:${PASSWORD}@${SERVER}${DIRECTORY}
LOGFILE=/var/log/duplicity.log
# set email to receive a backup report
EMAIL=""
backup() {
INCLUDE=""
for CDIR in $SOURCE
do
TMP=" --include ${CDIR}"
INCLUDE=${INCLUDE}${TMP}
done
# perform an incremental backup to root, include directories, exclude everything else, / as reference.
duplicity --full-if-older-than 30D $INCLUDE --exclude '**' / $BUCKET > $LOGFILE
if [ -n "$EMAIL" ]; then
mail -s "backup report" $EMAIL < $LOGFILE
fi
}
list() {
duplicity list-current-files $BUCKET
}
restore() {
if [ $# = 2 ]; then
duplicity restore --file-to-restore $1 $BUCKET $2
else
duplicity restore --file-to-restore $1 --time $2 $BUCKET $3
fi
}
status() {
duplicity collection-status $BUCKET
}
if [ "$1" = "backup" ]; then
backup
elif [ "$1" = "list" ]; then
list
elif [ "$1" = "restore" ]; then
if [ $# = 3 ]; then
restore $2 $3
else
restore $2 $3 $4
fi
elif [ "$1" = "status" ]; then
status
else
echo "
dupthat - manage duplicity backup
USAGE:
./dupthat.sh backup
./dupthat.sh list
./dupthat.sh status
./dupthat.sh restore file [time] dest
"
fi
EXPORT PASSPHRASE=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment