Last active
August 29, 2015 14:06
-
-
Save mrsarm/a970c02f08ffa136f1a4 to your computer and use it in GitHub Desktop.
Backup Duplicity Script: perform files backup with `duplicity` tool, in local mode or through the network
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 file script. | |
| # | |
| # The backup is performed with `duplicity`, | |
| # in local mode or through the network with | |
| # SCP, SFTP.., so all the tools must be | |
| # installed in both hosts (source and destination). | |
| # | |
| # The initial archive contains all | |
| # information (full backup) and in the future | |
| # executions only the changed information | |
| # is added (incremental backup). | |
| # | |
| # To restore a backup, just executes the following | |
| # command where the backup reside: | |
| # | |
| # $ duplicity restore BCK_FOLDER <protocol>://PATH_DEST | |
| # | |
| # If we wanted to restore just the file "Mail/article" | |
| # in /home/me as it was three days ago into | |
| # a remote folder in user@host:/home/me/restored_file: | |
| # | |
| # $ duplicity restore -t 3D --file-to-restore Mail/article \ | |
| # /backup/some_dir scp://user@host/home/me/restored_file | |
| # | |
| # 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:// | |
| # WARN: Use rsync:// protocol if the destination protocol is not 22, | |
| # but the destination folder must be created before the first execute | |
| # (rsync can't create folders like the others protocols). | |
| # See: http://duplicity.nongnu.org | |
| DESTINATION="file:///backup/" | |
| # Duplicity command line options | |
| DUPLICITY_OPTS="--no-encryption --volsize 100" | |
| # 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 file system backup ... " 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 : Doing backup of '$BASE_NAME'" 2>&1 | tee -a $LOG | |
| duplicity $1 $DUPLICITY_OPTS "$f" "$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 : ... File system backup 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 : ... File system backup 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