Skip to content

Instantly share code, notes, and snippets.

@fvoges
Forked from tsileo/duptools.sh
Last active August 29, 2015 14:04
Show Gist options
  • Save fvoges/5543b556311cf4c97d20 to your computer and use it in GitHub Desktop.
Save fvoges/5543b556311cf4c97d20 to your computer and use it in GitHub Desktop.
duptools.sh - frontend shell script for duplicity
export AWS_ACCESS_KEY_ID="YOUR_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET"
# See below duplicity options, uses same key for encryption and signing
export PASSPHRASE="YOUR_GPG_KEY_PASSPHRASE"
PURGE_AGE="65D"
# directories, space separated
SOURCE=""
SOURCE="${SOURCE} /vol/dir1"
SOURCE="${SOURCE} /vol/dir2"
BUCKET="s3+http://YOUR_BUCKET/SOMETHING"
LOGFILE="/var/log/duplicity.log"
# set email to receive a backup report
EMAIL="YOU_EMAIL"
DUPLICITY_OPTS=""
DUPLICITY_OPTS="$DUPLICITY_OPTS --s3-use-new-style"
DUPLICITY_OPTS="$DUPLICITY_OPTS --s3-european-buckets"
#DUPLICITY_OPTS="$DUPLICITY_OPTS --verbosity info"
#DUPLICITY_OPTS="$DUPLICITY_OPTS --verbosity 9"
DUPLICITY_OPTS="$DUPLICITY_OPTS --volsize=250"
#DUPLICITY_OPTS="$DUPLICITY_OPTS --tempdir /var/tmp"
DUPLICITY_OPTS="$DUPLICITY_OPTS --encrypt-sign-key YOUR_GPG_KEY_ID"
# vim: set ft=sh et ts=2 sw=2:
#!/bin/bash
# Added:
# * trickle to limit bandwith usage
# * some options and moved all config to ~/.duptoolsrc
# * extra commands to clenup and purge old backups
test -f ~/.duptoolsrc || exit 1
source ~/.duptoolsrc
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.
trickle -s -u 700 duplicity $DUPLICITY_OPTS --full-if-older-than 30D $INCLUDE --exclude '**' / $BUCKET > $LOGFILE
if [ -n "$EMAIL" ]; then
mail -s "backup report for ${HOSTNAME}" $EMAIL < $LOGFILE
fi
}
list() {
duplicity list-current-files $DUPLICITY_OPTS $BUCKET
}
restore() {
if [ $# = 2 ]; then
duplicity restore $DUPLICITY_OPTS --file-to-restore $1 $BUCKET $2
else
duplicity restore $DUPLICITY_OPTS --file-to-restore $1 --time $2 $BUCKET $3
fi
}
status() {
duplicity collection-status $DUPLICITY_OPTS $BUCKET
}
purge () {
duplicity remove-older-than $PURGE_AGE --force $DUPLICITY_OPTS $BUCKET
}
cleanup () {
duplicity cleanup --extra-clean --force $DUPLICITY_OPTS $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
elif [ "$1" = "purge" ]; then
purge
elif [ "$1" = "cleanup" ]; then
cleanup
else
echo "
duptools - manage duplicity backup
USAGE:
./duptools.sh backup
./duptools.sh list
./duptools.sh status
./duptools.sh purge
./duptools.sh cleanup
./duptools.sh restore file [time] dest
"
fi
# vim: set ft=sh et ts=2 sw=2:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment