37b35a499bd9d6b4573680013b029d0901c1d259

Author
Zertrin <zertrin@gmail.com>
Committer
Zertrin <zertrin@gmail.com>
Date

Message

Inclusion of two patches written by [shamer] + modified config file management.

Diff

This diff is truncated to protect this page.

  1diff --git a/CHANGELOG b/CHANGELOG
  2index 25cba55a49081b897015ad643364cb1c7a9e2907..3249ff0063cf90b03d274bcc3b4e24d4391151ab 100644
  3--- a/CHANGELOG
  4+++ b/CHANGELOG
  5@@ -1,3 +1,12 @@
  6+0.6.1 (5 May 2012)
  7+=================
  8+Inclusion of two patches written by [shamer] + modified config file management.
  9+
 10+  * Added option to use ssmtp to send mail [shamer]
 11+  * Added lock file to prevent running multiple instances simultaneously [shamer]
 12+  * Modified config file management (no more specified on the command line, must be specified as an parameter at the beginning of the script)
 13+  * Fixed bad check_variables() behaviour when not using Amazon S3 storage backend without commenting AWS API keys
 14+
 15 0.6 Version Six (4 May 2012)
 16 ============================
 17 This is a rework of the script to include some github patches that were brought to the original script in order to make the script more generic than only Amazon S3 oriented and fix a few issues.
 18diff --git a/README b/README
 19index a208c9c709ae9a13f755ae1d226ae04de908e91f..4f49a391e8e57516d92cd41a19c7641baf5232b6 100644
 20--- a/README
 21+++ b/README
 22@@ -14,9 +14,9 @@ machine ever does go belly up.
 23 Optionally, you can set up an email address where the log file will be sent,
 24 which is useful when the script is used via cron.
 25 
 26-This version is a rewriting of the code originally written by Damon Timm, including many
 27-patches that have been brought to the original scripts by various forks
 28-on Github.
 29+This version is a rewriting of the code originally written by Damon Timm,
 30+including many patches that have been brought to the original scripts by
 31+various forks on Github.
 32 
 33 Latest version of the code available at:
 34 http://github.com/zertrin/duplicity-backup
 35@@ -51,6 +51,15 @@ REQUIREMENTS
 36 * s3cmd (optional)
 37 * mailx (optional)
 38 
 39+CONFIGURATION
 40+=============
 41+
 42+The configuration takes place directly in the script and is documented there.
 43+
 44+You can optionnaly specifiy a custom config file in the CONFIG parameter at the
 45+very beginning. Any parameter specified in this custom config file will
 46+override thoses specified in the script.
 47+
 48 COMMON USAGE EXAMPLES
 49 =====================
 50 
 51diff --git a/duplicity-backup.sh b/duplicity-backup.sh
 52index d3c03e2e52aa278e76b63290f2a7989ec962b341..0bf880b73d049d984e1b9f20096424a054ee95f0 100755
 53--- a/duplicity-backup.sh
 54+++ b/duplicity-backup.sh
 55@@ -27,6 +27,10 @@
 56 #
 57 # ---------------------------------------------------------------------------- #
 58 
 59+# Set config file (uncomment if you want to use a separate config file)
 60+# Its content override config below !
 61+#CONFIG="/some/path/to/config/file"
 62+
 63 # AMAZON S3 INFORMATION
 64 # Comment out this lines if you're not using S3
 65 AWS_ACCESS_KEY_ID="foobar_aws_key_id"
 66@@ -132,6 +136,10 @@ EMAIL_TO=
 67 EMAIL_FROM=
 68 EMAIL_SUBJECT=
 69 
 70+# command to use to send mail (uncomment to activate functionnality)
 71+#MAIL="mailx"
 72+#MAIL="ssmtp"
 73+
 74 # TROUBLESHOOTING: If you are having any problems running this script it is
 75 # helpful to see the command output that is being generated to determine if the
 76 # script is causing a problem or if it is an issue with duplicity (or your
 77@@ -144,21 +152,7 @@ EMAIL_SUBJECT=
 78 # Script Happens Below This Line - Shouldn't Require Editing #
 79 ##############################################################
 80 
 81-# Read config file
 82-CONFIG=
 83-while :
 84-do
 85-    case $1 in
 86-        -c | --config)
 87-            CONFIG=$2
 88-            shift 2
 89-            ;;
 90-        *)
 91-            break
 92-            ;;
 93-    esac
 94-done
 95-
 96+# Read config file if specified
 97 if [ ! -z "$CONFIG" -a -f "$CONFIG" ];
 98 then
 99   . $CONFIG
100@@ -174,7 +168,10 @@ export PASSPHRASE
101 LOGFILE="${LOGDIR}${LOG_FILE}"
102 DUPLICITY="$(which duplicity)"
103 S3CMD="$(which s3cmd)"
104-MAIL="$(which mailx)"
105+
106+# File to use as a lock. The lock is used to insure that only one instance of
107+# the script is running at a time.
108+LOCKFILE=${LOGDIR}backup.lock
109 
110 if [ $ENCRYPTION = "yes" ]; then
111   ENCRYPT="--encrypt-key=${GPG_KEY} --sign-key=${GPG_KEY}"
112@@ -193,7 +190,10 @@ CONFIG_VAR_MSG="Oops!! ${0} was unable to run!\nWe are missing one or more impor
113 if [ ! -x "$DUPLICITY" ]; then
114   echo "ERROR: duplicity not installed, that's gotta happen first!" >&2
115   exit 1
116-elif  [ `echo ${DEST} | cut -c 1,2` = "s3" ]; then
117+fi
118+
119+if  [ `echo ${DEST} | cut -c 1,2` = "s3" ]; then
120+  DEST_IS_S3=true
121   if [ ! -x "$S3CMD" ]; then
122     echo $NO_S3CMD; S3CMD_AVAIL=false
123   elif [ ! -f "${HOME}/.s3cfg" ]; then
124@@ -201,22 +201,76 @@ elif  [ `echo ${DEST} | cut -c 1,2` = "s3" ]; then
125   else
126     S3CMD_AVAIL=true
127   fi
128+else
129+  DEST_IS_S3=false
130 fi
131 
132-if [ ! -d ${LOGDIR} ]; then
133-  echo "Attempting to create log directory ${LOGDIR} ..."
134-  if ! mkdir -p ${LOGDIR}; then
135-    echo "Log directory ${LOGDIR} could not be created by this user: ${USER}"
136+check_variables ()
137+{
138+  if [[ ${ROOT} = "" || ${DEST} = "" || ${INCLIST} = "" || \
139+         ${GPG_KEY} = "foobar_gpg_key" || \
140+         ${PASSPHRASE} = "foobar_gpg_passphrase" || \
141+         ${LOGDIR} = "/home/foobar_user_name/logs/test2/" || \
142+         ( ${DEST_IS_S3} = true && ${AWS_ACCESS_KEY_ID} = "foobar_aws_key_id" ) || \
143+         ( ${DEST_IS_S3} = true && ${AWS_SECRET_ACCESS_KEY} = "foobar_aws_access_key" ) ]]; then
144+    echo -e ${CONFIG_VAR_MSG}
145+    exit 1
146+  fi
147+}
148+
149+check_logdir()
150+{
151+  if [ ! -d ${LOGDIR} ]; then
152+    echo "Attempting to create log directory ${LOGDIR} ..."
153+    if ! mkdir -p ${LOGDIR}; then
154+      echo "Log directory ${LOGDIR} could not be created by this user: ${USER}"