Last active
August 29, 2015 14:10
-
-
Save mrsarm/e1868ffc95d260dd3ad2 to your computer and use it in GitHub Desktop.
Script to remove old backup files made with duplicity
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 | |
| # | |
| # Script to remove old backup files made with duplicity. | |
| # | |
| # See the `duplicity` home page for more information: | |
| # http://duplicity.nongnu.org | |
| # | |
| # Author: (2014) Mariano Ruiz <[email protected]> | |
| # | |
| # List of source folders to backup. | |
| # Each path must be quoted, and separated each other | |
| # with a white space | |
| FOLDERS=("$HOME/Desktop" "$HOME/Documents" "$HOME/Music") | |
| # Destination folder (can be a remote address). | |
| # The protocol must be specified, even it's a | |
| # local path. Supported protocols: | |
| # file:// (local), ftp://, sftp:// and scp:// | |
| # See: http://duplicity.nongnu.org | |
| DESTINATION="file:///backup" | |
| # Time after backups are deleted | |
| TIME_LIMIT="15D" | |
| # Duplicity command line options | |
| DUPLICITY_OPTS="remove-older-than $TIME_LIMIT --force" | |
| # Log file | |
| LOG="$HOME/backup-duplicity.log" | |
| # Date format printed into the log | |
| DATE_FORMAT="+%Y-%m-%d %T" | |
| echo "`date "$DATE_FORMAT"` INFO : Starting to remove old system backup files ... " 2>&1 | tee -a $LOG | |
| T_START=$(date +%s) # To calculate the process time | |
| EXIT_CODE=0 | |
| for f in "${FOLDERS[@]}"; do | |
| BASE_NAME=`basename "$f"` | |
| FULL_NAME="$DESTINATION/$BASE_NAME" | |
| echo "`date "$DATE_FORMAT"` INFO : Removing old backups ($TIME_LIMIT) of '$BASE_NAME'" 2>&1 | tee -a $LOG | |
| duplicity $1 $DUPLICITY_OPTS "$FULL_NAME" 2>&1 | tee -a $LOG | |
| EXIT_CODE=$(( (${PIPESTATUS[0]}) + ($EXIT_CODE) )) | |
| done | |
| T_DIFF=$(( $(date +%s) - $T_START )) | |
| if [ "$EXIT_CODE" != "0" ]; then | |
| echo "`date "$DATE_FORMAT"` ERROR : ... Removing old system backup files done with errors (elapsed time `date -u -d @"$T_DIFF" +'%-Hh %-Mm %-Ss'`). Check the log above." 2>&1 | tee -a $LOG | |
| exit -1 | |
| fi | |
| echo "`date "$DATE_FORMAT"` INFO : ... Removing old system backup files done in `date -u -d @"$T_DIFF" +'%-Hh %-Mm %-Ss'`." 2>&1 | tee -a $LOG | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment