f66427f2093e97b2f0b62e806e82e78eb415531d
- Author
- zertrin <zrk951@gmail.com>
- Committer
- zertrin <zrk951@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/CHANGELOG b/CHANGELOG
2index 545e9651114e8835a6183c9c057b810301a717e0..15739d2736a7edf7ec4edc938b1e1a63dec17dd0 100644
3--- a/CHANGELOG
4+++ b/CHANGELOG
5@@ -1,3 +1,11 @@
6+0.8 (05 August 2012)
7+===================
8+ * Improved argument parsing. Now the script is insensitive to the order of appearance of the options and handles correctly optional options parameters
9+ * Re-added possibility to specify the config file on the command line, which is now the recommended way to do (facilitating script updates)
10+ * Added dry-run command line option (-n or --dry-run)
11+ * Added many short versions of long options (-b, -f, -v, -l, -s)
12+ * Fix "unary operator expected warning" in some rare cases
13+
14 0.7.1 (9 July 2012)
15 ===================
16 * Adding 'duplicity-backup.conf' to .gitignore
17diff --git a/README b/README
18index 5199f148dc96e874dc8f62e6815c20a0e8b1c977..da54be285e506afee8c4c60be3c78a40be61f75c 100644
19--- a/README
20+++ b/README
21@@ -2,13 +2,15 @@ ABOUT THIS SCRIPT
22 =================
23
24 This bash script was designed to automate and simplify the remote backup process
25-of duplicity on Amazon S3 primarily. Other backup destinations are possible.
26+of duplicity on Amazon S3 primarily. Other backup destinations are possible
27+(FTP, SFTP, SCP, rsync, file...), i.e. any of duplicity's supported outputs.
28+
29 After your script is configured, you can easily backup, restore, verify and
30 clean (either via cron or manually) your data without having to remember lots of
31 different command options and passphrases.
32
33 Most importantly, you can easily backup the script and your gpg key in a
34-convenient passphrase-encrypted file. This comes in in handy if/when your
35+convenient passphrase-encrypted file. This comes in in handy if/when your
36 machine ever does go belly up.
37
38 Optionally, you can set up an email address where the log file will be sent,
39@@ -38,10 +40,10 @@ file, but make a copy of it and edit this one. Be sure to replace all the
40 *foobar* values with your real ones. Almost every value needs to be configured
41 in someway.
42
43-You can use multiple copies of the script with different settings for different
44-backup scenarios. It is designed to run as a cron job and will log information
45-to a text file (including remote file sizes, if you have s3cmd installed). Be
46-sure to make the script executable (chmod +x) before you hit the gas.
47+You can use one copy of the script with different settings for different backup
48+scenarios. It is designed to run as a cron job and will log information to a
49+text file (including remote file sizes, if you have s3cmd installed). Be sure to
50+make the script executable (chmod +x) before you hit the gas.
51
52 REQUIREMENTS
53 ============
54@@ -57,9 +59,47 @@ CONFIGURATION
55
56 The configuration takes place in a separate config file and is documented there.
57
58-The script looks for its configuration by reading the config file specified in
59-the CONFIG parameter at the beggining of the script. Be sure to edit it to match
60-the actual location of your config file.
61+You want to copy duplicity-backup.conf.example to another place that suits your
62+needs (for example /etc/duplicity-backup.conf)
63+
64+The script looks for its configuration by reading the config file specified by
65+the command line option -c or --config (see USAGE)
66+
67+If no config file was given on the command line, the script will try to find the
68+file specified in the CONFIG parameter at the beggining of the script (defaults
69+to "duplicity-backup.conf" in the script's directory).
70+
71+So be sure either:
72+- to specify the configuration file path on the command line [recommended]
73+- or to edit the CONFIG parameter in thescript to match the actual location of
74+ your config file. [deprecated]
75+
76+NOTE: to ease future updates of the script, you may prefer NOT to edit the
77+ script at all and to specify systematically the path to your config file
78+ on the command line with the -c or --config option.
79+
80+USAGE
81+=====
82+
83+ duplicity-backup.sh [options]
84+
85+ Options:
86+ -c, --config CONFIG_FILE specify the config file to use
87+
88+ -b, --backup runs an incremental backup
89+ -f, --full forces a full backup
90+
91+ -v, --verify verifies the backup
92+ --restore [PATH] restores the entire backup to [path]
93+ --restore-file [FILE_TO_RESTORE] [DESTINATION]
94+ restore a specific file
95+
96+ -l, --list-current-files lists the files currently backed up in the archive
97+ -s, --collection-status show all the backup sets in the archive
98+
99+ --backup-script automatically backup the script and secret key to
100+ the current working directory
101+ -n, --dry-run perform a trial run with no changes made
102
103 COMMON USAGE EXAMPLES
104 =====================
105@@ -68,36 +108,36 @@ COMMON USAGE EXAMPLES
106 $ duplicity-backup.sh
107
108 * Run an incremental backup:
109- $ duplicity-backup.sh --backup
110+ $ duplicity-backup.sh [-c config_file] --backup
111
112 * Force a one-off full backup:
113- $ duplicity-backup.sh --full
114+ $ duplicity-backup.sh [-c config_file] --full
115
116 * Restore your entire backup:
117- $ duplicity-backup.sh --restore
118+ $ duplicity-backup.sh [-c config_file] --restore
119 You will be prompted for a restore directory
120
121diff --git a/duplicity-backup.sh b/duplicity-backup.sh
122index c8c957eaf5ab3bbdbb92f7664a57a2efeebe7d0b..e899d5c05ab0d3e739c2957dbf3d4eb6214c2771 100755
123--- a/duplicity-backup.sh
124+++ b/duplicity-backup.sh
125@@ -27,20 +27,121 @@
126 #
127 # ---------------------------------------------------------------------------- #
128
129-# Set config file (don't forget to copy duplicity-backup.conf.example to
130-# match that path)
131+# Default config file (don't forget to copy duplicity-backup.conf.example to
132+# match that path)
133+# NOTE: It can be useful not to edit this script at all to ease future updates
134+# so the config file can be specified directly on the command line too
135+# with the -c option.
136 CONFIG="duplicity-backup.conf"
137
138 ##############################################################
139 # Script Happens Below This Line - Shouldn't Require Editing #
140 ##############################################################
141
142+usage(){
143+echo "USAGE:
144+ `basename $0` [options]
145+
146+ Options:
147+ -c, --config CONFIG_FILE specify the config file to use
148+
149+ -b, --backup runs an incremental backup
150+ -f, --full forces a full backup
151+ -v, --verify verifies the backup
152+ --restore [PATH] restores the entire backup to [path]
153+ --restore-file [FILE_TO_RESTORE] [DESTINATION]
154+ restore a specific file
155+ -l, --list-current-files lists the files currently backed up in the archive
156+ -s, --collection-status show all the backup sets in the archive
157+ --backup-script automatically backup the script and secret key to
158+ the current working directory
159+ -n, --dry-run perform a trial run with no changes made
160+
161+ CURRENT SCRIPT VARIABLES:
162+ ========================
163+ DEST (backup destination) = ${DEST}
164+ INCLIST (directories included) = ${INCLIST[@]:0}
165+ EXCLIST (directories excluded) = ${EXCLIST[@]:0}
166+ ROOT (root directory of backup) = ${ROOT}
167+ LOGFILE (log file path) = ${LOGFILE}
168+"
169+}
170+
171+# Some expensive argument parsing that allows the script to
172+# be insensitive to the order of appearance of the options
173+# and to handle correctly option parameters that are optional
174+while getopts ":c:bfvlsn-:" opt; do
175+ case $opt in
176+ # parse long options (a bit tricky because builtin getopts does not
177+ # manage long options and i don't want to impose GNU getopt dependancy)
178+ -)
179+ case "$OPTARG" in
180+ # --restore [restore dest]
181+ restore)
182+ COMMAND=$OPTARG
183+ # We try to find the optional value [restore dest]
184+ if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
185+ RESTORE_DEST=${!OPTIND}
186+ OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
187+ fi
188+ ;;
189+ # --restore-file [file to restore] [restore dest]
190+ restore-file)
191+ COMMAND=$OPTARG
192+ # We try to find the first optional value [file to restore]
193+ if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
194+ FILE_TO_RESTORE=${!OPTIND}
195+ OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
196+ else
197+ continue # no value for the restore-file option, skip the rest
198+ fi
199+ # We try to find the second optional value [restore dest]
200+ if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
201+ RESTORE_DEST=${!OPTIND}
202+ OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
203+ fi
204+ ;;
205+ config) # set the config file from the command line
206+ # We try to find the config file
207+ if [ ! -z "${!OPTIND:0:1}" -a ! "${!OPTIND:0:1}" = "-" ]; then
208+ CONFIG=${!OPTIND}
209+ OPTIND=$(( $OPTIND + 1 )) # we found it, move forward in arg parsing
210+ fi
211+ ;;
212+ dry-run)
213+ ECHO=$(which echo)
214+ ;;
215+ *)
216+ COMMAND=$OPTARG
217+ ;;
218+ esac
219+ ;;
220+ # here are parsed the short options
221+ c) CONFIG=$OPTARG;; # set the config file from the command line
222+ b) COMMAND="backup";;
223+ f) COMMAND="full";;
224+ v) COMMAND="verify";;