From 0d03acd797653a1f8771371e75a490f3b283bc75 Mon Sep 17 00:00:00 2001 From: Christo De Lange Date: Sat, 6 Jul 2013 15:24:26 -0400 Subject: [PATCH 1/6] Check privileges earlier so the 'su - zimbra' checks don't show unexepected errors --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 8432aa9..b3a01a1 100755 --- a/install.sh +++ b/install.sh @@ -40,6 +40,12 @@ ERR_NOBKPDIR="1" # No backup directory could be found ERR_NOROOT="2" # Script was run without root privileges ERR_DEPNOTFOUND="3" # Missing dependency +# Check if we have root before doing anything +if [ $(id -u) -ne 0 ]; then + echo "You need root privileges to install zmbkpose" + exit $ERR_NOROOT +fi + # Try to guess missing settings as best as we can test -z $ZIMBRA_HOSTNAME && ZIMBRA_HOSTNAME=`su - zimbra -c zmhostname` test -z $ZIMBRA_ADDRESS && ZIMBRA_ADDRESS=`grep $ZIMBRA_HOSTNAME /etc/hosts|awk '{print $1}'` @@ -74,12 +80,6 @@ echo "" echo "Press ENTER to continue or CTRL+C to cancel." read tmp -# Check if we have root before doing anything -if [ $(id -u) -ne 0 ]; then - echo "You need root privileges to install zmbkpose" - exit $ERR_NOROOT -fi - # Check for missing installer files # TODO: MD5 check of the files printf "Checking installer integrity... " From e8989b20649302722d682f723dbf4228053fa7e1 Mon Sep 17 00:00:00 2001 From: Christo De Lange Date: Sat, 6 Jul 2013 15:33:25 -0400 Subject: [PATCH 2/6] Provide a way to look up zimbra hostname in DNS --- install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index b3a01a1..987f38d 100755 --- a/install.sh +++ b/install.sh @@ -35,10 +35,11 @@ ZIMBRA_LDAPPASS="" # Leave empty to autodetect # Exit codes -ERR_OK="0" # No error (normal exit) +ERR_OK="0" # No error (normal exit) ERR_NOBKPDIR="1" # No backup directory could be found ERR_NOROOT="2" # Script was run without root privileges ERR_DEPNOTFOUND="3" # Missing dependency +ERR_HOSTNOTFOUND="543" # Missing dependency # Check if we have root before doing anything if [ $(id -u) -ne 0 ]; then @@ -49,6 +50,11 @@ fi # Try to guess missing settings as best as we can test -z $ZIMBRA_HOSTNAME && ZIMBRA_HOSTNAME=`su - zimbra -c zmhostname` test -z $ZIMBRA_ADDRESS && ZIMBRA_ADDRESS=`grep $ZIMBRA_HOSTNAME /etc/hosts|awk '{print $1}'` +test -z $ZIMBRA_ADDRESS && ZIMBRA_ADDRESS=`host -t A $ZIMBRA_HOSTNAME | head -1 | cut -d ' ' -f 4` +test -z $ZIMBRA_ADDRESS && { + echo "Cannot resolve $ZIMBRA_HOSTNAME to an address! Check DNS or /etc/hosts please." + exit $ERR_HOSTNOTFOUND +} test -z $ZIMBRA_LDAPPASS && ZIMBRA_LDAPPASS=`su - zimbra -c "zmlocalconfig -s zimbra_ldap_password"|awk '{print $3}'` if [ -z $ZIMBRA_BKPDIR ]; then test -d $ZIMBRA_DIR/backup && ZIMBRA_BKPDIR=$ZIMBRA_DIR/backup From d1a890240cd8c0d11c0e395b8811d55d7b3f50fd Mon Sep 17 00:00:00 2001 From: Christo DeLange Date: Sun, 7 Jul 2013 11:14:19 -0400 Subject: [PATCH 3/6] Ignore IDE files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..65519fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Intelli-IDE family +.idea From 8d46bba3e02038b39970fc388c1b1070f069f760 Mon Sep 17 00:00:00 2001 From: Christo DeLange Date: Mon, 8 Jul 2013 08:30:32 -0400 Subject: [PATCH 4/6] Standardize curl use --- src/zmbkpose | 81 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/src/zmbkpose b/src/zmbkpose index 04b8e15..4f5cfb7 100755 --- a/src/zmbkpose +++ b/src/zmbkpose @@ -190,9 +190,9 @@ backup_all_accounts_parallel() if [ $STAT -lt $MAX_PARALLEL_PROCESS ];then MAILHOST=$(grep -A1 ^$MAIL $LISTALLACCOUNTS| grep -v @) $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt let COUNT++ else @@ -207,9 +207,9 @@ backup_all_accounts_parallel() # Bloco de execução MAILHOST=$(grep -A1 ^$MAIL $LISTALLACCOUNTS| grep -v @) $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt let COUNT++ # Fim Bloco de execução @@ -241,9 +241,9 @@ backup_all_accounts () for MAIL in $(grep @ $LISTALLACCOUNTS); do MAILHOST=$(grep -A1 ^$MAIL $LISTALLACCOUNTS| grep -v @) $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt done @@ -284,9 +284,9 @@ backup_accounts_parallel () if [ $STAT -lt $MAX_PARALLEL_PROCESS ];then $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff MAILHOST=$(grep ^zimbraMailHost $TEMPDIR/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt let COUNT++ else @@ -300,9 +300,9 @@ backup_accounts_parallel () # Bloco de execução $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff MAILHOST=$(grep ^zimbraMailHost $TEMPDIR/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz & + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz & echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt let COUNT++ # Fim Bloco de execução @@ -367,9 +367,9 @@ incremental_all_accounts () else MAILHOST=$(grep -A1 ^$MAIL $LISTALLACCOUNTS| grep -v @) $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Junk.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Trash.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Junk.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Trash.tgz # " echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt fi @@ -431,9 +431,9 @@ backup_accounts () $(which ldapsearch) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -w $LDAPZIMBRAPASS -b '' -LLL "(zimbraMailDeliveryAddress=$MAIL)" > $TEMPDIR/$MAIL.ldiff MAILHOST=$(grep ^zimbraMailHost $TEMPDIR/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz > $TEMPDIR/$MAIL.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz > $TEMPDIR/$MAIL.Junk.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz > $TEMPDIR/$MAIL.Trash.tgz echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt ((K = K+1)) unset MAIL @@ -487,9 +487,9 @@ incremental_accounts () ((K = K+1)) else MAILHOST=$(grep ^zimbraMailHost $TEMPDIR/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Junk.tgz - $(which curl) -k -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Trash.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Junk.tgz + ${CURL} -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz\&query=after:\"$INCFROM\" > $TEMPDIR/$MAIL.Trash.tgz echo $SESSION:$MAIL:$(date +%m/%d/%y) >> $WORKDIR/sessions.txt ((K = K+1)) fi @@ -555,9 +555,9 @@ restore_accounts () ((K = K+1)) else MAILHOST=$(grep ^zimbraMailHost $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz ((K = K+1)) unset MAIL fi @@ -590,9 +590,9 @@ restore_on_box() for SESSIONACCOUNT in $(cat $BKPSACCOUNT | awk -F: '{print $1}'); do echo "Restoring from $SESSIONACCOUNT on $DEST" MAILHOST=$(grep ^zimbraMailHost $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff | awk '{print $2}') - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/Junk?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/Trash?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/Junk?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$DEST/Trash?fmt=tgz echo "$MAIL restored from $SESSIONACCOUNT on $DEST" done unset MAIL @@ -638,9 +638,9 @@ restore_LDAP_account () MAILHOST=$(grep ^zimbraMailHost $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff | awk '{print $2}') $(which ldapdelete) -r -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS $(grep ^dn: $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff | awk '{print $2}') 2>/dev/null $(which ldapadd) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS -f $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz echo "$MAIL restored from $SESSIONACCOUNT" done ((K = K+1)) @@ -684,9 +684,9 @@ restore_all_accounts_parallel () $(which ldapdelete) -r -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS $USERDN 2>/dev/null $(which ldapadd) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS -f $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz & - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz & - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz & echo "$MAIL restored" else @@ -707,9 +707,9 @@ restore_all_accounts_parallel () $(which ldapdelete) -r -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS $USERDN 2>/dev/null $(which ldapadd) -x -H $LDAPMASTERSERVER -D $LDAPZIMBRADN -c -w $LDAPZIMBRAPASS -f $WORKDIR/$SESSIONACCOUNT/$MAIL.ldiff - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz & - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz & - $(which curl) -k --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Junk.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Junk?fmt=tgz & + ${CURL} --data-binary @$WORKDIR/$SESSIONACCOUNT/$MAIL.Trash.tgz -u $ADMINUSER:$ADMINPASS https://$MAILHOST:7071/home/$MAIL/Trash?fmt=tgz & echo "$MAIL restored" fi @@ -834,6 +834,9 @@ if [ -z "$LOGFILE" ]; then exit 0 fi +# Initialize some standard external commands +CURL="$(which curl) -q -k" + # Criticize the parameters passed on the command line case "$1" in From 7523257f7cbeb1f8b075dcdfd9073c325b591d97 Mon Sep 17 00:00:00 2001 From: Christo DeLange Date: Mon, 8 Jul 2013 08:34:44 -0400 Subject: [PATCH 5/6] Standardize curl use --- src/zmbkpose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zmbkpose b/src/zmbkpose index 4f5cfb7..6d54fc5 100755 --- a/src/zmbkpose +++ b/src/zmbkpose @@ -835,7 +835,7 @@ if [ -z "$LOGFILE" ]; then fi # Initialize some standard external commands -CURL="$(which curl) -q -k" +CURL="$(which curl) -s -k" # Criticize the parameters passed on the command line From 07954aef80d7896eb420059197d8cc3b63fdb302 Mon Sep 17 00:00:00 2001 From: Christo DeLange Date: Mon, 8 Jul 2013 10:26:59 -0400 Subject: [PATCH 6/6] Support verbosity --- src/zmbkpose | 257 +++++++++++++++++++++++++++------------------------ 1 file changed, 134 insertions(+), 123 deletions(-) diff --git a/src/zmbkpose b/src/zmbkpose index 6d54fc5..adb7575 100755 --- a/src/zmbkpose +++ b/src/zmbkpose @@ -184,7 +184,7 @@ backup_all_accounts_parallel() for MAIL in $(grep @ $LISTALLACCOUNTS); do # Contador de processos curl simultaneos - # Simultaneous Curl Process counter + # Simultaneous Curl Process counter STAT=$(ps aux | grep -i curl | grep -v grep| wc -l) if [ $STAT -lt $MAX_PARALLEL_PROCESS ];then @@ -200,7 +200,7 @@ backup_all_accounts_parallel() do STAT=$(ps aux | grep -i curl | grep -v grep| wc -l) sleep 5 - #echo "Max process number reached ($STAT). Waiting slot." + [ $VERBOSE -gt 0 ] && echo "Max process number reached ($STAT). Waiting slot." done # Execution block @@ -835,136 +835,147 @@ if [ -z "$LOGFILE" ]; then fi # Initialize some standard external commands +VERBOSE=0 CURL="$(which curl) -s -k" # Criticize the parameters passed on the command line -case "$1" in -"-f" ) - if [ -z "$2" ]; then - if [ $PARALLEL_SUPPORT -eq 1 ];then - echo "Running the parallel backup" - backup_all_accounts_parallel - else - backup_all_accounts - fi - else - if [ -z "$3" ]; then - backup_accounts $2 - else - echo "Incorrect $@ params. Read --help." - show_help - fi - fi - -;; -"-i" ) - if [ -z "$2" ]; then - incremental_all_accounts - else - if [ -z "$3" ]; then - incremental_accounts $2 - fi - echo "Incorrect $@ params. Read the --help." - show_help - fi -;; -"-l" ) - if [ -z "$2" ]; then - list_sessions - else - echo "Incorrect $@ params. Read the --help." - show_help - fi -;; -"-r" ) +while [ ! -z "$1" ] ; do + case "$1" in + "-v" ) + shift + if [ -z "`echo $1 |egrep -e '^[0-9]*\$'`" ] ; then + show_help + else + VERBOSE=$1 + fi + "-f" ) if [ -z "$2" ]; then - echo "Incorrect $@ params. Read the --help." + if [ $PARALLEL_SUPPORT -eq 1 ];then + echo "Running the parallel backup" + backup_all_accounts_parallel + else + backup_all_accounts + fi + else + if [ -z "$3" ]; then + backup_accounts $2 + else + echo "Incorrect $@ params. Read --help." show_help - else - if [ -z "$4" ]; then - restore_accounts $2 $3 - else - echo "Incorrect $@ params. Read the --help." - show_help - fi - fi -;; -"-restoreAccount" ) + fi + fi + + ;; + "-i" ) if [ -z "$2" ]; then - echo "Incorrect $@ params. Read the --help." + incremental_all_accounts + else + if [ -z "$3" ]; then + incremental_accounts $2 + fi + echo "Incorrect $@ params. Read the --help." show_help - else - if [ -z "$3" ]; then - restore_LDAP_account $2 - else - if [ "$3" = "--LDAPOnly" ]; then - restore_LDAP_account $2 $4 - else - echo "Incorrect $@ params. Read the --help." - show_help - fi - fi - fi - -;; -"--restoreAllAccounts" ) - restore_all_accounts_parallel -;; -"--backupDistributionList" ) - backup_distribution_list -;; -"--backupAlias" ) - backup_alias -;; -"--restoreAlias" ) - restore_alias -;; -"--restoreDistributionList" ) - restore_distribution_list -;; -"--restoreOnAccount" ) - if ! [ -z $2 -o -z $3 ]; then - restore_on_box $2 $3 - fi -;; -"-d" ) - if [ -z "$2" ]; then - echo "Parameter -d accepts only number of days, or a number followed by weeks or months" - show_help - exit 0 - fi - if [ $2 -eq $2 2> /dev/null ]; then - if [ -z "$3" ]; then - OLDEST=`date +%Y%m%d%H%M%S -d "-$2 days"` - else - case "$3" in - "weeks" ) - OLDEST=`date +%Y%m%d%H%M%S -d "-$2 weeks"` - ;; - "months" ) - OLDEST=`date +%Y%m%d%H%M%S -d "-$2 months"` - ;; - * ) - echo "Parameter -d accepts only number of days, or a number followed by weeks or months" - show_help - exit 0 - ;; - esac - fi - rotate_backup $OLDEST - else - echo "Parameter -d accepts only number of days, or a number followed by weeks or months" - show_help - exit 0 - fi -;; + fi + ;; + "-l" ) + if [ -z "$2" ]; then + list_sessions + else + echo "Incorrect $@ params. Read the --help." + show_help + fi + ;; + "-r" ) + if [ -z "$2" ]; then + echo "Incorrect $@ params. Read the --help." + show_help + else + if [ -z "$4" ]; then + restore_accounts $2 $3 + else + echo "Incorrect $@ params. Read the --help." + show_help + fi + fi + ;; + "-restoreAccount" ) + if [ -z "$2" ]; then + echo "Incorrect $@ params. Read the --help." + show_help + else + if [ -z "$3" ]; then + restore_LDAP_account $2 + else + if [ "$3" = "--LDAPOnly" ]; then + restore_LDAP_account $2 $4 + else + echo "Incorrect $@ params. Read the --help." + show_help + fi + fi + fi -* ) - echo "Incorrect parameters $@. See help." - show_help -;; -esac + ;; + "--restoreAllAccounts" ) + restore_all_accounts_parallel + ;; + "--backupDistributionList" ) + backup_distribution_list + ;; + "--backupAlias" ) + backup_alias + ;; + "--restoreAlias" ) + restore_alias + ;; + "--restoreDistributionList" ) + restore_distribution_list + ;; + "--restoreOnAccount" ) + if ! [ -z $2 -o -z $3 ]; then + restore_on_box $2 $3 + fi + ;; + "-d" ) + if [ -z "$2" ]; then + echo "Parameter -d accepts only number of days, or a number followed by weeks or months" + show_help + exit 0 + fi + if [ $2 -eq $2 2> /dev/null ]; then + if [ -z "$3" ]; then + OLDEST=`date +%Y%m%d%H%M%S -d "-$2 days"` + else + case "$3" in + "weeks" ) + OLDEST=`date +%Y%m%d%H%M%S -d "-$2 weeks"` + ;; + "months" ) + OLDEST=`date +%Y%m%d%H%M%S -d "-$2 months"` + ;; + * ) + echo "Parameter -d accepts only number of days, or a number followed by weeks or months" + show_help + exit 0 + ;; + esac + fi + rotate_backup $OLDEST + else + echo "Parameter -d accepts only number of days, or a number followed by weeks or months" + show_help + exit 0 + fi + ;; + + * ) + echo "Incorrect parameters $@. See help." + show_help + ;; + esac + shift +done exit 0 # Ações do script