From 5c99b4c3cadca02bb91767896281a192e99099c3 Mon Sep 17 00:00:00 2001 From: "Federico C. Guizzardi" Date: Mon, 26 Aug 2013 09:51:36 +0200 Subject: [PATCH 1/5] fixed variable name (cherry picked from commit 19c80a83a2819bdac73dfe4bc08e270205a9a666) --- duplicity-backup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 235586b..0228866 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -522,7 +522,7 @@ get_lock INCLUDE= EXCLUDE= -EXLUDEROOT= +EXCLUDEROOT= case "$COMMAND" in "backup-script") From dd05ff68b6bc593edd2b13ee950d510f883ddd0e Mon Sep 17 00:00:00 2001 From: zertrin Date: Wed, 13 Nov 2013 19:55:47 +0100 Subject: [PATCH 2/5] Add support for mail sending via msmtp (adapted cherry-pick from commit 7f8b9b6e2fb49ce3bae166674a06754e5940ea04 of Dosenpfand) --- duplicity-backup.conf.example | 1 + duplicity-backup.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index c81aaf7..168e28c 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -209,6 +209,7 @@ MAIL="mailx" # default command for Linux mail #MAIL="mail" # for CentOS, if "mailx" fails try this one #MAIL="ssmtp" #MAIL="sendmail" +#MAIL="msmtp" # TROUBLESHOOTING: If you are having any problems running this script it is # helpful to see the command output that is being generated to determine if the diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 0228866..6dec36f 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -271,6 +271,8 @@ email_logfile() EMAIL_SUBJECT=${EMAIL_SUBJECT:="duplicity-backup alert ${LOG_FILE}"} if [ "$MAIL" = "ssmtp" ]; then echo """Subject: ${EMAIL_SUBJECT}""" | cat - ${LOGFILE} | ${MAILCMD} -s ${EMAIL_TO} + elif [ "$MAIL" = "msmtp" ]; then + echo """Subject: ${EMAIL_SUBJECT}""" | cat - ${LOGFILE} | ${MAILCMD} ${EMAIL_TO} elif [ "$MAIL" = "mailx" ]; then EMAIL_FROM=${EMAIL_FROM:+"-r ${EMAIL_FROM}"} cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO} From e9af0ab3c1e90efc865568ca57eae2e591e1faf8 Mon Sep 17 00:00:00 2001 From: zertrin Date: Wed, 13 Nov 2013 20:08:34 +0100 Subject: [PATCH 3/5] Some little modifications and additions in the doc of the config file --- duplicity-backup.conf.example | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example index 168e28c..04d8f09 100644 --- a/duplicity-backup.conf.example +++ b/duplicity-backup.conf.example @@ -2,7 +2,7 @@ # # Copyright (c) 2008-2010 Damon Timm. # Copyright (c) 2010 Mario Santagiuliana. -# Copyright (c) 2012 Marc Gallet. +# Copyright (c) 2012-2013 Marc Gallet. # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software @@ -25,6 +25,9 @@ # Latest code available at: # http://github.com/zertrin/duplicity-backup # +# List of contributors: +# https://github.com/zertrin/duplicity-backup/graphs/contributors +# # ---------------------------------------------------------------------------- # # ############################################# @@ -87,7 +90,7 @@ ROOT="/home" # BACKUP DESTINATION INFORMATION # In my case, I use Amazon S3 use this - so I made up a unique # bucket name (you don't have to have one created, it will do it -# for you). If you don't want to use Amazon S3, you can backup +# for you). If you don't want to use Amazon S3, you can backup # to a file or any of duplicity's supported outputs. # # The s3+http scheme uses the default aws s3 hostname. @@ -97,12 +100,19 @@ ROOT="/home" # remote file size check will work. #DEST="s3://host/backup-bucket/backup-folder/" DEST="s3+http://foobar-backup-bucket/backup-folder/" +# # Other possible locations +# Be sure to check duplicity's man page to know how to use them +# (http://duplicity.nongnu.org/duplicity.1.html) +# #DEST="ftp://user[:password]@other.host[:port]/some_dir" #DEST="rsync://user@host.com[:port]//absolute_path" #DEST="scp://user[:password]@other.host[:port]/[/]some_dir" #DEST="ssh://user[:password]@other.host[:port]/[/]some_dir" +#DEST="sftp://user[:password]@other.host[:port]/[/]some_dir" #DEST="file:///home/foobar_user_name/new-backup-test/" +#DEST="imap[s]://user[:password]@host.com[/from_address_prefix]" +#DEST="webdav[s]://user[:password]@other.host[:port]/some_dir" # DESTINATION BACKEND PASSWORD # Instead of setting the password needed for the backup destination in the @@ -116,7 +126,7 @@ DEST="s3+http://foobar-backup-bucket/backup-folder/" # INCLUDE LIST OF DIRECTORIES # Here is a list of directories to include; if you want to include -# everything that is in root, leave this list empty. +# everything that is in ROOT, leave this list empty. # # Here is an example with multiple locations: #INCLIST=( "/home/*/Documents" \ From 03ef054cf3c08635a40402c1fa932e184463cb59 Mon Sep 17 00:00:00 2001 From: zertrin Date: Wed, 13 Nov 2013 21:36:34 +0100 Subject: [PATCH 4/5] Add the --restore-dir synonym and update the documentation accordingly --- README.md | 48 +++++++++++++++++++++++++++------------------ duplicity-backup.sh | 18 ++++++++++++----- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 659425c..7d01c56 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Optionally, you can set up an email address where the log file will be sent, whi This version is a rewriting of the code originally written by [Damon Timm](https://github.com/thornomad), including many patches that have been brought to the original scripts by various forks on Github. + ## Contributing Latest version of the code is available at http://github.com/zertrin/duplicity-backup @@ -53,7 +54,7 @@ The script looks for its configuration by reading the config file specified by t If no config file was given on the command line, the script will try to find the file specified in the `CONFIG` parameter at the beginning of the script (default: `duplicity-backup.conf` in the script's directory). So be sure to either: -* specify the configuration file path on the command line **[recommended]** +* specify the configuration file path on the command line with the -c option **[recommended]** * or to edit the `CONFIG` parameter in the script to match the actual location of your config file. **[deprecated]** NOTE: to ease future updates of the script, you may prefer NOT to edit the script at all and to specify systematically the path to your config file on the command line with the `-c` or `--config` option. @@ -68,19 +69,22 @@ NOTE: to ease future updates of the script, you may prefer NOT to edit the scrip -b, --backup runs an incremental backup -f, --full forces a full backup - -v, --verify verifies the backup - --restore [PATH] restores the entire backup to [path] - --restore-file [FILE_TO_RESTORE] [DESTINATION] - restore a specific file - -l, --list-current-files lists the files currently backed up in the archive -s, --collection-status show all the backup sets in the archive - -t, --time TIME specify the time from which to restore or list - files (duplicity time format) - --backup-script automatically backup the script and secret key to + --restore [PATH] restores the entire backup to [path] + --restore-file [FILE_TO_RESTORE] [DESTINATION] + restore a specific file + --restore-dir [DIR_TO_RESTORE] [DESTINATION] + restore a specific directory + + -t, --time TIME specify the time from which to restore or list files + (see duplicity man page for the format) + + --backup-script automatically backup the script and secret key(s) to the current working directory + -n, --dry-run perform a trial run with no changes made -d, --debug echo duplicity commands to logfile @@ -101,37 +105,41 @@ NOTE: to ease future updates of the script, you may prefer NOT to edit the scrip **Restore your entire backup:** + # You will be prompted for a restore directory duplicity-backup.sh [-c config_file] --restore -*You will be prompted for a restore directory* - + # You can also provide a restore folder on the command line. duplicity-backup.sh [-c config_file] --restore /home/user/restore-folder -*You can also provide a restore folder on the command line.* +**Restore a specific file or directory in the backup:** -**Restore a specific file in the backup:** +Note that the commands --restore-file and --restore-dir are equivalent. + # You will be prompted for a file to restore to the current directory duplicity-backup.sh [-c config_file] --restore-file -*You will be prompted for a file to restore to the current directory* - + # Restores the file img/mom.jpg to the current directory duplicity-backup.sh [-c config_file] --restore-file img/mom.jpg -*Restores the file img/mom.jpg to the current directory* - + # Restores the file img/mom.jpg to /home/user/i-love-mom.jpg duplicity-backup.sh [-c config_file] --restore-file img/mom.jpg /home/user/i-love-mom.jpg -*Restores the file img/mom.jpg to /home/user/i-love-mom.jpg* + # Restores the directory rel/dir/path to /target/restorepath + duplicity-backup.sh [-c config_file] --restore-dir rel/dir/path /target/restorepath **List files in the remote archive** duplicity-backup.sh [-c config_file] --list-current-files +**See the collection status (i.e. all the backup sets in the remore archive)** + + duplicity-backup.sh [-c config_file] --collection-status + **Verify the backup** duplicity-backup.sh [-c config_file] --verify -**Backup the script and gpg key (for safekeeping)** +**Backup the script and gpg key in a encrypted tarfile (for safekeeping)** duplicity-backup.sh [-c config_file] --backup-script @@ -150,6 +158,8 @@ To see exactly what is happening when you run duplicity-backup, either pass the This will stop the script from running and will, instead, output the generated command into your log file. You can then check to see if what is being generated is causing an error or if it is duplicity causing you woe. You can also try the `-n` or `dry-run` option. This will make duplicity to calculate what would be done, but do not perform any backend actions. Together with info verbosity level (-v8) duplicity will list all files that will be affected. This way you will know exactly which files will be backed up or restored. + + ## Wish List * send mails only on failure diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 6dec36f..0a338ac 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -48,14 +48,21 @@ echo "USAGE: -b, --backup runs an incremental backup -f, --full forces a full backup -v, --verify verifies the backup + -l, --list-current-files lists the files currently backed up in the archive + -s, --collection-status show all the backup sets in the archive + --restore [PATH] restores the entire backup to [path] --restore-file [FILE_TO_RESTORE] [DESTINATION] restore a specific file - -l, --list-current-files lists the files currently backed up in the archive - -s, --collection-status show all the backup sets in the archive - --backup-script automatically backup the script and secret key to - the current working directory + --restore-dir [DIR_TO_RESTORE] [DESTINATION] + restore a specific directory + -t, --time TIME specify the time from which to restore or list files + (see duplicity man page for the format) + + --backup-script automatically backup the script and secret key(s) to + the current working directory + -n, --dry-run perform a trial run with no changes made -d, --debug echo duplicity commands to logfile @@ -88,7 +95,8 @@ while getopts ":c:t:bfvlsnd-:" opt; do fi ;; # --restore-file [file to restore] [restore dest] - restore-file) + # --restore-dir [path to restore] [restore dest] + restore-file|restore-dir) COMMAND=$OPTARG # We try to find the first optional value [file to restore] if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then From 54f9aaf27acc2964ffb083b7d06435533fc7ce80 Mon Sep 17 00:00:00 2001 From: Zertrin Date: Wed, 13 Nov 2013 21:56:12 +0100 Subject: [PATCH 5/5] Complete the half-done work of previous commit --- duplicity-backup.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index 0a338ac..26dc124 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -82,7 +82,7 @@ echo "USAGE: while getopts ":c:t:bfvlsnd-:" opt; do case $opt in # parse long options (a bit tricky because builtin getopts does not - # manage long options and i don't want to impose GNU getopt dependancy) + # manage long options and I don't want to impose GNU getopt dependancy) -) case "$OPTARG" in # --restore [restore dest] @@ -597,16 +597,17 @@ case "$COMMAND" in duplicity_backup ;; - "restore-file") + "restore-file"|"restore-dir") ROOT=$DEST - OPTION= + OPTION="restore" if [ ! -z "$TIME" ]; then STATIC_OPTIONS="$STATIC_OPTIONS --time $TIME" fi if [[ ! "$FILE_TO_RESTORE" ]]; then - echo "Which file do you want to restore (eg, mail/letter.txt):" + echo "Which file or directory do you want to restore?" + echo "(give the path relative to the root of the backup eg, mail/letter.txt):" read -e FILE_TO_RESTORE echo fi @@ -633,7 +634,7 @@ case "$COMMAND" in setup_passphrase echo "Restoring now ..." - #use INCLUDE variable without create another one + #use INCLUDE variable without creating another one INCLUDE="--file-to-restore ${FILE_TO_RESTORE}" duplicity_backup ;;