2f07d0e2160bf15ca8b7d67fdf44e627e65ccb0b

Author
Leszek Piątek <lpiatek@gmail.com>
Committer
Leszek Piątek <lpiatek@gmail.com>
Date

Message

Adding -e, --cleanup flag...

Diff

 1diff --git a/duplicity-backup.sh b/duplicity-backup.sh
 2index 5e122b2718b7ae32de518d756ceee442339945b2..50d49674a4fb4da131a9a46e941364ca58e9b437 100755
 3--- a/duplicity-backup.sh
 4+++ b/duplicity-backup.sh
 5@@ -52,6 +52,10 @@ echo "USAGE:
 6     -b, --backup               runs an incremental backup
 7     -f, --full                 forces a full backup
 8     -v, --verify               verifies the backup
 9+    -e, --cleanup              cleanup the backup (eg. broken sessions), by default using
10+                               duplicity --force flag, use --dry-run to actually log what
11+                               will be cleaned up without removing (see man duplicity
12+                               > ACTIONS > cleanup for details)
13     -l, --list-current-files   lists the files currently backed up in the archive
14     -s, --collection-status    show all the backup sets in the archive
15 
16@@ -83,7 +87,7 @@ echo "USAGE:
17 # Some expensive argument parsing that allows the script to
18 # be insensitive to the order of appearance of the options
19 # and to handle correctly option parameters that are optional
20-while getopts ":c:t:bfvlsnd-:" opt; do
21+while getopts ":c:t:bfvelsnd-:" opt; do
22   case $opt in
23     # parse long options (a bit tricky because builtin getopts does not
24     # manage long options and I don't want to impose GNU getopt dependancy)
25@@ -146,6 +150,7 @@ while getopts ":c:t:bfvlsnd-:" opt; do
26     b) COMMAND="backup";;
27     f) COMMAND="full";;
28     v) COMMAND="verify";;
29+    e) COMMAND="cleanup";;
30     l) COMMAND="list-current-files";;
31     s) COMMAND="collection-status";;
32     n) DRY_RUN="--dry-run ";; # dry run
33@@ -631,6 +636,17 @@ duplicity_backup()
34   }
35 }
36 
37+duplicity_cleanup_failed()
38+{
39+  {
40+    eval "${ECHO}" "${DUPLICITY}" "${OPTION}" "${VERBOSITY}" "${STATIC_OPTIONS}" \
41+    "${DEST}" \
42+    >> "${LOGFILE}"
43+  } || {
44+    BACKUP_ERROR=1
45+  }
46+}
47+
48 setup_passphrase()
49 {
50   if [ ! -z "${GPG_ENC_KEY}" -a ! -z "${GPG_SIGN_KEY}" -a "${GPG_ENC_KEY}" != "${GPG_SIGN_KEY}" ]; then
51@@ -790,6 +806,20 @@ case "${COMMAND}" in
52     echo -e "Verify complete.  Check the log file for results:\n>> ${LOGFILE}"
53   ;;
54 
55+  "cleanup")
56+    OPTION="cleanup"
57+
58+    if [ -z "${DRY_RUN}" ]; then
59+      STATIC_OPTIONS="--force"
60+    fi
61+
62+    echo -e "-------[ Cleaning up Destination ]-------\n" >> "${LOGFILE}"
63+    setup_passphrase
64+    duplicity_cleanup_failed
65+
66+    echo -e "Cleanup complete." >> "${LOGFILE}"
67+  ;;
68+
69   "restore")
70     ROOT=${DEST}
71     OPTION="restore"