Created
September 15, 2012 01:44
-
-
Save dmp1ce/3726009 to your computer and use it in GitHub Desktop.
Duplicity backup script
This file contains hidden or 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 | |
# Backup all important files on my computer using Duplicity | |
# Folders to include | |
include_directories=(/home/me /etc) | |
# Folders to exclude | |
exclude_directories=() | |
# duplicity path to backup to. | |
destination=ssh://otherComputer/backup/myComputer | |
# Set passphrase | |
export PASSPHRASE="Secure passphrase here. Don't forget to back me up!" | |
# Log directory | |
LOG_DIRECTORY=/home/me/log | |
# ======= NOTICE ================================ | |
# You probably don't need to edit below this line. | |
# You have been warned! | |
# ================================================ | |
# Setup some variables | |
SCRIPT_FILENAME=$(basename $0) | |
TIMESTAMP=`date +%m%d%Y-%H%M` | |
BACKUP_LOG_FILE="$LOG_DIRECTORY/$SCRIPT_FILENAME""_$TIMESTAMP.log" | |
# If duplicity is already running then exit | |
if [ $(ps aux | grep 'duplicity' | grep -v "grep\|$SCRIPT_FILENAME" | wc -l | tr -s "\n") -ne 0 ]; then | |
echo "Duplicity is already running, exiting." | |
exit | |
fi | |
include_parameters="" | |
for include_directory in ${include_directories[*]} | |
do | |
include_parameters="$include_parameters --include $include_directory" | |
done | |
exclude_parameters="" | |
for exclude_directory in ${exclude_directories[*]} | |
do | |
exclude_parameters="$exclude_parameters --exclude $exclude_directory" | |
done | |
# Run duplicity without logs to check for prompts. | |
duplicity collection-status \ | |
$include_parameters $exclude_parameters \ | |
--exclude '**' \ | |
"$destination" | |
# Run duplicity backup. | |
duplicity \ | |
$include_parameters $exclude_parameters \ | |
--exclude '**' \ | |
--full-if-older-than 1Y \ | |
/ "$destination" 2>&1 | tee $BACKUP_LOG_FILE | |
# Only keep around 1 full backup. | |
echo -e '\n\n==== REMOVE OLD BACKUP SETS ====\n\n' >> $BACKUP_LOG_FILE | |
duplicity remove-all-but-n-full 1 \ | |
"$destination" 2>&1 | tee -a $BACKUP_LOG_FILE | |
# Clear passphrase | |
export PASSPHRASE= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment