Skip to content

Instantly share code, notes, and snippets.

@malesch
Last active December 10, 2015 22:38
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 malesch/4503984 to your computer and use it in GitHub Desktop.
Save malesch/4503984 to your computer and use it in GitHub Desktop.
Wrapper for duplicity for backing up system files and user directories (with local exclusion configuration)
#!/bin/bash
#
# Perform a system backup and backups of the specified additional
# directories (ADD_DIRS).
# The additional directories are checked for the exclusion file
# '.backup-exclude-list', holding relative paths, line-by-line.
# Alternatively directories can be excluded by putting the file
# '.backup-ignore' in the corresponding location (sub-directries
# are also excluded from the backup).
#
#---------------------------------------------------
# configuration section
#---------------------------------------------------
PROTOCOL=scp
HOST=u12345.your-backup.de
USER=u12345
PASSWORD=secret
# symmetric encryption
export PASSPHRASE='a-secret-password'
# additional directories to be backuped
ADD_DIRS=("/home/user1" "/home/user2" "/home/user3")
# number of full backups to keep
KEEP_FULL_BACKUPS=3
# end
#---------------------------------------------------
BACKUP_DESTINATION="$PROTOCOL://$USER:$PASSWORD@$HOST"
# system backup (configuration)
duplicity cleanup \
--extra-clean \
${BACKUP_DESTINATION}/system \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" != '--dry-run' ]; then echo '--force'; fi) \
>/dev/null \
\
&& \
\
duplicity \
--full-if-older-than 1W \
$(excl=""; for DIR in ${ADD_DIRS[@]}; do excl="$excl --exclude ${DIR}"; done; echo $excl) \
--include '/etc' \
--include '/boot' \
--exclude '**' \
/ \
${BACKUP_DESTINATION}/system \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" == '--dry-run' ]; then echo '--dry-run'; fi ) \
$(if [ "$1" != '--dry-run' ]; then echo '--no-print-statistics'; fi ) \
\
&& \
\
duplicity remove-all-but-n-full \
${KEEP_FULL_BACKUPS} \
${BACKUP_DESTINATION}/system \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" != '--dry-run' ]; then echo '--force'; fi)
# backup of additional directories
for DIR in ${ADD_DIRS[@]}
do
duplicity cleanup \
--extra-clean \
${BACKUP_DESTINATION}${DIR} \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" != '--dry-run' ]; then echo '--force'; fi) \
>/dev/null \
\
&& \
\
duplicity \
--full-if-older-than 1W \
--exclude-if-present '.backup-ignore' \
$(if [ -e ${DIR}/.backup-exclude-list ]
then
excl=""
while read line
do
[ -z "$line" ] && continue # skip empty lines
excl="$excl --exclude ${DIR}/$line"
done <"${DIR}/.backup-exclude-list"
echo "$excl "
fi) \
${DIR} \
${BACKUP_DESTINATION}${DIR} \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" == '--dry-run' ]; then echo '--dry-run'; fi ) \
$(if [ "$1" != '--dry-run' ]; then echo '--no-print-statistics'; fi ) \
\
&& \
\
duplicity remove-all-but-n-full \
${KEEP_FULL_BACKUPS} \
${BACKUP_DESTINATION}${DIR} \
--log-file /var/log/duplicity.log \
--verbosity error \
$(if [ "$1" != '--dry-run' ]; then echo '--force'; fi)
done
# unset confidential variables
unset PASSPHRASE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment