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