Diff
1diff --git a/README.md b/README.md
2index 8287f78250de6bc21227962943ed79d22ed5057a..8de10d9581a40cb27dfb08c0acebab9502127ffe 100644
3--- a/README.md
4+++ b/README.md
5@@ -151,6 +151,10 @@ For the [Google Cloud Storage](https://cloud.google.com/storage/) storage backen
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@@ -220,15 +224,23 @@ Note that the commands `--restore-file` and `--restore-dir` are equivalent.
17
18 duplicity-backup.sh [-c config_file] --verify
19
20+**Clean the backup**
21+
22+ duplicity-backup.sh [-c config_file] --cleanup
23+
24 **Backup the script and gpg key in a encrypted tarfile (for safekeeping)**
25
26 duplicity-backup.sh [-c config_file] --backup-script
27
28
29-## Cron Usage Example
30+## Cron Usage Example (backup)
31
32 41 3 * * * /absolute/path/to/duplicity-backup.sh -c /etc/duplicity-backup.conf -b
33
34+## Cron Usage Example (cleanup)
35+
36+ 41 4 * * 1 /absolute/path/to/duplicity-backup.sh -c /etc/duplicity-backup.conf -e
37+
38
39 ## Known issues
40
41diff --git a/duplicity-backup.sh b/duplicity-backup.sh
42index 42c5d9a1574038d42ad773dd403662e13bf7ff4e..ff262af03e5bea5f6a4a8b5c44d8380c3c18cbd9 100755
43--- a/duplicity-backup.sh
44+++ b/duplicity-backup.sh
45@@ -52,6 +52,10 @@ echo "USAGE:
46 -b, --backup runs an incremental backup
47 -f, --full forces a full backup
48 -v, --verify verifies the backup
49+ -e, --cleanup cleanup the backup (eg. broken sessions), by default using
50+ duplicity --force flag, use --dry-run to actually log what
51+ will be cleaned up without removing (see man duplicity
52+ > ACTIONS > cleanup for details)
53 -l, --list-current-files lists the files currently backed up in the archive
54 -s, --collection-status show all the backup sets in the archive
55
56@@ -83,7 +87,7 @@ echo "USAGE:
57 # Some expensive argument parsing that allows the script to
58 # be insensitive to the order of appearance of the options
59 # and to handle correctly option parameters that are optional
60-while getopts ":c:t:bfvlsnd-:" opt; do
61+while getopts ":c:t:bfvelsnd-:" opt; do
62 case $opt in
63 # parse long options (a bit tricky because builtin getopts does not
64 # manage long options and I don't want to impose GNU getopt dependancy)
65@@ -146,6 +150,7 @@ while getopts ":c:t:bfvlsnd-:" opt; do
66 b) COMMAND="backup";;
67 f) COMMAND="full";;
68 v) COMMAND="verify";;
69+ e) COMMAND="cleanup";;
70 l) COMMAND="list-current-files";;
71 s) COMMAND="collection-status";;
72 n) DRY_RUN="--dry-run ";; # dry run
73@@ -631,6 +636,17 @@ duplicity_backup()
74 }
75 }
76
77+duplicity_cleanup_failed()
78+{
79+ {
80+ eval "${ECHO}" "${DUPLICITY}" "${OPTION}" "${VERBOSITY}" "${STATIC_OPTIONS}" \
81+ "${DEST}" \
82+ >> "${LOGFILE}"
83+ } || {
84+ BACKUP_ERROR=1
85+ }
86+}
87+
88 setup_passphrase()
89 {
90 if [ ! -z "${GPG_ENC_KEY}" -a ! -z "${GPG_SIGN_KEY}" -a "${GPG_ENC_KEY}" != "${GPG_SIGN_KEY}" ]; then
91@@ -790,6 +806,20 @@ case "${COMMAND}" in
92 echo -e "Verify complete. Check the log file for results:\n>> ${LOGFILE}"
93 ;;
94
95+ "cleanup")
96+ OPTION="cleanup"
97+
98+ if [ -z "${DRY_RUN}" ]; then
99+ STATIC_OPTIONS="--force"
100+ fi
101+
102+ echo -e "-------[ Cleaning up Destination ]-------\n" >> "${LOGFILE}"
103+ setup_passphrase
104+ duplicity_cleanup_failed
105+
106+ echo -e "Cleanup complete." >> "${LOGFILE}"
107+ ;;
108+
109 "restore")
110 ROOT=${DEST}
111 OPTION="restore"