-
-
Save kepford/2001804 to your computer and use it in GitHub Desktop.
duplicity_backup by mig5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Duplicity Backup script | |
# written by mig5 | |
# Functions that define which API to use | |
function amazon_s3() { | |
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXX | |
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXX | |
DEST=s3+http://gbd_${SERVER}/$dir | |
} | |
function rackspace_cloud() { | |
export CLOUDFILES_USERNAME=XXXXXXXXXXXXXXXXXXX | |
export CLOUDFILES_APIKEY=XXXXXXXXXXXXXXXXXXX | |
DEST=cf+http://gbd_${SERVER}_$dir | |
} | |
if [ ! `whoami` = "root" ] ; then | |
echo "You must run this script as root" | |
exit 1 | |
fi | |
## Configurable variables | |
# Which API/provider to backup to? | |
# Options: amazon_s3 / rackspace_cloud | |
PROVIDER=amazon_s3 | |
# Server name | |
SERVER=`hostname -f` | |
# How often should we make a full backup? Recommended: 3 months | |
FULL_BACKUPS="3M" | |
# Remove old backups? 0 for no, 1 for yes | |
REMOVE_OLD_BACKUPS=1 | |
# How often should we purge old backups? Recommended: 12 months. | |
REMOVE_OLDER_THAN="12M" | |
# Used for Duplicity's GPG encryption | |
export PASSPHRASE=XXXXXXXXXXXXXXXXXXXXXX | |
# Args to pass to duplicity | |
backup_options="--full-if-older-than $FULL_BACKUPS --exclude-other-filesystems" | |
maintenance_options="remove-older-than $REMOVE_OLDER_THAN --force" | |
# An array of directories to back up | |
DIRS=`ls -1 / | egrep -v "cdrom|dev|initrd|lib64|lost|media|mnt|nonexistent|proc|selinux|sys|tmp|vmlinuz"` | |
## Backup code below. You should not need to edit anything here. | |
# Loop over each dir and perform the backup. | |
for dir in ${DIRS[@]}; do | |
echo "Backing up /$dir..." | |
# A special clause for /root. We don't want the local duplicity cache data | |
if [ $dir = "root" ]; then | |
extra_options="--exclude /root/.cache" | |
fi | |
if [ $dir = "home" ]; then | |
extra_options="--exclude /home/jenkins/.cache" | |
fi | |
# Decide which API to use based on the provider set. | |
$PROVIDER | |
duplicity $backup_options $extra_options /$dir $DEST || exit 1 | |
unset extra_options | |
if [ $REMOVE_OLD_BACKUPS -eq 1 ]; then | |
# Do some maintenance on the remote end to clean up old backups | |
echo "Performing routine maintenance on /$dir..." | |
duplicity $maintenance_options $DEST || exit 1 | |
fi | |
done | |
unset PASSPHRASE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment