From 445785436fba77c29739614c581c9f1c94f1a597 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 08:06:50 -0300 Subject: [PATCH 01/23] Fix - zmbackup account wasn't beeing created --- installScript/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 4427a22..75f0980 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -79,7 +79,7 @@ function deploy_new() { echo -ne '################### (95%)\r' # Creating Zmbackup backup user - sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov ca zmbackup@$DOMAIN '$ZMBKP_PASSWORD' zimbraIsAdminAccount TRUE zimbraAdminAuthTokenLifetime 1" > /dev/null 2>&1 + sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov ca '$ZMBKP_ACCOUNT' '$ZMBKP_PASSWORD' zimbraIsAdminAccount TRUE zimbraAdminAuthTokenLifetime 1" > /dev/null 2>&1 echo -ne '#################### (100%)\r' } @@ -114,6 +114,6 @@ function uninstall() { echo -ne '########## (50%)\r' rm -rf $ZMBKP_LIB $ZMBKP_CONF $ZMBKP_SRC/zmbackup echo -ne '############### (75%)\r' - sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov da zmbackup@$DOMAIN" > /dev/null 2>&1 + sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov da $ZMBKP_ACCOUNT" > /dev/null 2>&1 echo -ne '#################### (100%)\r' } From 1f5098b844ba5c3c785bb1b4f7eb012ed9780ea8 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 08:15:25 -0300 Subject: [PATCH 02/23] Including checks for the version --- installScript/check.sh | 10 ++++++++-- installScript/vars.sh | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/installScript/check.sh b/installScript/check.sh index 1f8d9a4..7895b18 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -14,13 +14,19 @@ function check_env() { printf "[ROOT]\n" fi printf " Old Zmbackup Install... " - su - $OSE_USER -c "which zmbackup" > /dev/null 2>&1 + VERSION=$((su - $OSE_USER -c "zmbackup -v") 2> /dev/null) if [ $? != 0 ]; then printf "[NEW INSTALL]\n" UPGRADE="N" - else + elif [[ $1 = '--remove' ]] && [[ $1 = '-r' ]]; then + printf "[UNINSTALL] - EXECUTING UNINSTALL ROUTINE\n" + UPGRADE="N" + elif [[ $VERSION = $ZMBKP_VERSION ]]; then printf "[OLD VERSION] - EXECUTING UPGRADE ROUTINE\n" UPGRADE="Y" + else + printf "[NEWEST VERSION] - Nothing to do..." + exit 0 fi printf " Checking OS... " which apt > /dev/null 2>&1 diff --git a/installScript/vars.sh b/installScript/vars.sh index 846d178..e9994c4 100644 --- a/installScript/vars.sh +++ b/installScript/vars.sh @@ -26,3 +26,4 @@ ZMBKP_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) # Zmbacku MAX_PARALLEL_PROCESS="3" # Zmbackup's number of threads ROTATE_TIME="30" # Zmbackup's max of days before housekeeper LOCK_BACKUP=true # Zmbackup's backup lock +ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA" # Zmbackup's latest version From 1b759e75097ce88dd008940c7ff4c3813145afa9 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 09:27:09 -0300 Subject: [PATCH 03/23] Fix install.sh - Upgrade only occur when the version was the same --- installScript/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installScript/check.sh b/installScript/check.sh index 7895b18..3d70ced 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -21,7 +21,7 @@ function check_env() { elif [[ $1 = '--remove' ]] && [[ $1 = '-r' ]]; then printf "[UNINSTALL] - EXECUTING UNINSTALL ROUTINE\n" UPGRADE="N" - elif [[ $VERSION = $ZMBKP_VERSION ]]; then + elif [[ $VERSION != $ZMBKP_VERSION ]]; then printf "[OLD VERSION] - EXECUTING UPGRADE ROUTINE\n" UPGRADE="Y" else From a2c5588904e3fe10186ef71f7d0b2541de58442f Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:13:09 -0300 Subject: [PATCH 04/23] Bugfix - Blacklist wasn't being created --- installScript/deploy.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 75f0980..8a6378c 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -6,14 +6,14 @@ ################################################################################ function blacklist_gen(){ for ACCOUNT in $(sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov -l gaa"); do - if [[ "$ACCOUNT" == "galsync."* ]] && \ - [[ "$ACCOUNT" == "virus-"* ]] && \ - [[ "$ACCOUNT" == "ham."* ]] && \ - [[ "$ACCOUNT" == "admin@"* ]] && \ - [[ "$ACCOUNT" == "spam."* ]] && \ - [[ "$ACCOUNT" == "zmbackup@"* ]] && \ - [[ "$ACCOUNT" == "postmaster@"* ]] && \ - [[ "$ACCOUNT" == "root@"* ]]; then + if [[ "$ACCOUNT" = "galsync."* ]] && \ + [[ "$ACCOUNT" = "virus-"* ]] && \ + [[ "$ACCOUNT" = "ham."* ]] && \ + [[ "$ACCOUNT" = "admin@"* ]] && \ + [[ "$ACCOUNT" = "spam."* ]] && \ + [[ "$ACCOUNT" = "zmbackup@"* ]] && \ + [[ "$ACCOUNT" = "postmaster@"* ]] && \ + [[ "$ACCOUNT" = "root@"* ]]; then echo $ACCOUNT >> /etc/zmbackup.conf fi done @@ -111,8 +111,13 @@ function uninstall() { echo "Removing... Please wait while we made some changes." echo -ne ' (0%)\r' rm -rf $ZMBKP_SHARE $ZMBKP_SRC/zmbhousekeep > /dev/null 2>&1 - echo -ne '########## (50%)\r' + echo -ne '##### (25%)\r' rm -rf $ZMBKP_LIB $ZMBKP_CONF $ZMBKP_SRC/zmbackup + echo -ne '########## (50%)\r' + if [[ -f $ZMBKP_CONF/blacklist.conf ]]; then + install --backup=numbered -o $OSE_USER -m 600 $MYDIR/project/config/blacklist.conf $ZMBKP_CONF + blacklist_gen + fi echo -ne '############### (75%)\r' sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov da $ZMBKP_ACCOUNT" > /dev/null 2>&1 echo -ne '#################### (100%)\r' From 8fe13e061800399caef995b39553855767ab992c Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:16:13 -0300 Subject: [PATCH 05/23] Bugfix - --remove stopped working after editing check.sh --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index e001120..5d5b905 100755 --- a/install.sh +++ b/install.sh @@ -22,7 +22,7 @@ source installScript/vars.sh # Uninstall code ################################################################################ if [[ $1 == "--remove" ]] || [[ $1 == "-r" ]]; then - check_env + check_env $1 if [[ $SO = "ubuntu" ]]; then remove_ubuntu else From f6806622ea56c336198606677c7fe70296f95d3a Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:17:40 -0300 Subject: [PATCH 06/23] Bugfix - --remove stopped working after editing check.sh --- installScript/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installScript/check.sh b/installScript/check.sh index 3d70ced..fe917a3 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -18,7 +18,7 @@ function check_env() { if [ $? != 0 ]; then printf "[NEW INSTALL]\n" UPGRADE="N" - elif [[ $1 = '--remove' ]] && [[ $1 = '-r' ]]; then + elif [[ $1 == '--remove' ]] && [[ $1 == '-r' ]]; then printf "[UNINSTALL] - EXECUTING UNINSTALL ROUTINE\n" UPGRADE="N" elif [[ $VERSION != $ZMBKP_VERSION ]]; then From 305fd690c39e2d32c8889333d0067bfa2cd8a285 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:21:44 -0300 Subject: [PATCH 07/23] Bugfix - --remove stopped working after editing check.sh --- installScript/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installScript/check.sh b/installScript/check.sh index fe917a3..c582134 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -18,7 +18,7 @@ function check_env() { if [ $? != 0 ]; then printf "[NEW INSTALL]\n" UPGRADE="N" - elif [[ $1 == '--remove' ]] && [[ $1 == '-r' ]]; then + elif [[ $1 == '--remove' ]] || [[ $1 == '-r' ]]; then printf "[UNINSTALL] - EXECUTING UNINSTALL ROUTINE\n" UPGRADE="N" elif [[ $VERSION != $ZMBKP_VERSION ]]; then From bf1e185598078f91934b724db30ba6128a3d4c58 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:36:50 -0300 Subject: [PATCH 08/23] Bugfix - Blacklist wasn't being created --- installScript/deploy.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 8a6378c..9161cd4 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -6,13 +6,13 @@ ################################################################################ function blacklist_gen(){ for ACCOUNT in $(sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov -l gaa"); do - if [[ "$ACCOUNT" = "galsync."* ]] && \ - [[ "$ACCOUNT" = "virus-"* ]] && \ - [[ "$ACCOUNT" = "ham."* ]] && \ - [[ "$ACCOUNT" = "admin@"* ]] && \ - [[ "$ACCOUNT" = "spam."* ]] && \ - [[ "$ACCOUNT" = "zmbackup@"* ]] && \ - [[ "$ACCOUNT" = "postmaster@"* ]] && \ + if [[ "$ACCOUNT" = "galsync."* ]] || \ + [[ "$ACCOUNT" = "virus-"* ]] || \ + [[ "$ACCOUNT" = "ham."* ]] || \ + [[ "$ACCOUNT" = "admin@"* ]] || \ + [[ "$ACCOUNT" = "spam."* ]] || \ + [[ "$ACCOUNT" = "zmbackup@"* ]] || \ + [[ "$ACCOUNT" = "postmaster@"* ]] || \ [[ "$ACCOUNT" = "root@"* ]]; then echo $ACCOUNT >> /etc/zmbackup.conf fi From cca7c8612b89e360ac34416598d305acc88cccad Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:40:38 -0300 Subject: [PATCH 09/23] Bugfix - Message was being put in the wrong place --- installScript/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installScript/check.sh b/installScript/check.sh index c582134..10f4a1c 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -25,7 +25,7 @@ function check_env() { printf "[OLD VERSION] - EXECUTING UPGRADE ROUTINE\n" UPGRADE="Y" else - printf "[NEWEST VERSION] - Nothing to do..." + echo "[NEWEST VERSION] - Nothing to do..." exit 0 fi printf " Checking OS... " From caa44d3db15aa2fdac68c21ad0b3e020b3d9f143 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:44:30 -0300 Subject: [PATCH 10/23] Bugfix - Message was being put in the wrong place --- installScript/deploy.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 9161cd4..488bc44 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -6,15 +6,15 @@ ################################################################################ function blacklist_gen(){ for ACCOUNT in $(sudo -H -u $OSE_USER bash -c "/opt/zimbra/bin/zmprov -l gaa"); do - if [[ "$ACCOUNT" = "galsync."* ]] || \ - [[ "$ACCOUNT" = "virus-"* ]] || \ - [[ "$ACCOUNT" = "ham."* ]] || \ - [[ "$ACCOUNT" = "admin@"* ]] || \ - [[ "$ACCOUNT" = "spam."* ]] || \ - [[ "$ACCOUNT" = "zmbackup@"* ]] || \ - [[ "$ACCOUNT" = "postmaster@"* ]] || \ - [[ "$ACCOUNT" = "root@"* ]]; then - echo $ACCOUNT >> /etc/zmbackup.conf + if [[ "$ACCOUNT" = "galsync"* ]] || \ + [[ "$ACCOUNT" = "virus"* ]] || \ + [[ "$ACCOUNT" = "ham"* ]] || \ + [[ "$ACCOUNT" = "admin"* ]] || \ + [[ "$ACCOUNT" = "spam"* ]] || \ + [[ "$ACCOUNT" = "zmbackup"* ]] || \ + [[ "$ACCOUNT" = "postmaster"* ]] || \ + [[ "$ACCOUNT" = "root"* ]]; then + echo $ACCOUNT >> $ZMBKP_CONF/blacklist.conf fi done } From f7c7583b0b9b1c16a99df2756e351304324f6b53 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:54:12 -0300 Subject: [PATCH 11/23] Parallel can't create folder .parallel inside Zimbra's home dir - Permission denied --- installScript/deploy.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 488bc44..211afdc 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -36,7 +36,8 @@ function deploy_new() { echo -ne '#### (20%)\r' # Copy files - echo "will cite" | parallel --bibtex > /dev/null 2>&1 + mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will_cite + chown -R zimbra. $OSE_INSTALL_DIR/.parallel install -o $OSE_USER -m 700 $MYDIR/project/zmbackup $ZMBKP_SRC echo -ne '##### (25%)\r' cp -R $MYDIR/project/lib/* $ZMBKP_LIB From 61b8f14ce5399d2bec18e25b99ad640039bcbe97 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:55:08 -0300 Subject: [PATCH 12/23] Parallel can't create folder .parallel inside Zimbra's home dir - Permission denied --- installScript/deploy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 211afdc..9364e97 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -112,6 +112,7 @@ function uninstall() { echo "Removing... Please wait while we made some changes." echo -ne ' (0%)\r' rm -rf $ZMBKP_SHARE $ZMBKP_SRC/zmbhousekeep > /dev/null 2>&1 + rm -rf $OSE_INSTALL_DIR/.parallel echo -ne '##### (25%)\r' rm -rf $ZMBKP_LIB $ZMBKP_CONF $ZMBKP_SRC/zmbackup echo -ne '########## (50%)\r' From ea1da1d6e6f643c9fb2245621be882e5a5a291e6 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:57:01 -0300 Subject: [PATCH 13/23] Parallel can't create folder .parallel inside Zimbra's home dir - Permission denied --- installScript/deploy.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 9364e97..a880088 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -35,9 +35,11 @@ function deploy_new() { test -d $ZMBKP_LIB || mkdir -p $ZMBKP_LIB echo -ne '#### (20%)\r' - # Copy files + # Disable Parallel's message - Zmbackup remind the user about GNU Parallel mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will_cite chown -R zimbra. $OSE_INSTALL_DIR/.parallel + + # Copy file install -o $OSE_USER -m 700 $MYDIR/project/zmbackup $ZMBKP_SRC echo -ne '##### (25%)\r' cp -R $MYDIR/project/lib/* $ZMBKP_LIB @@ -94,8 +96,11 @@ function deploy_upgrade(){ rm -rf $ZMBKP_SHARE $ZMBKP_SRC/zmbhousekeep > /dev/null 2>&1 echo -ne '########## (50%)\r' + # Disable Parallel's message - Zmbackup remind the user about GNU Parallel + mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will_cite + chown -R zimbra. $OSE_INSTALL_DIR/.parallel + # Copy files - echo "will cite" | parallel --bibtex > /dev/null 2>&1 install -o $OSE_USER -m 700 $MYDIR/project/zmbackup $ZMBKP_SRC echo -ne '############### (75%)\r' test -d $ZMBKP_LIB || mkdir -p $ZMBKP_LIB From 112acd556a94f856d26fd94e27ddf1553869fa67 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 10:59:12 -0300 Subject: [PATCH 14/23] Parallel can't create folder .parallel inside Zimbra's home dir - Permission denied --- installScript/deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installScript/deploy.sh b/installScript/deploy.sh index a880088..6a45c03 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -36,7 +36,7 @@ function deploy_new() { echo -ne '#### (20%)\r' # Disable Parallel's message - Zmbackup remind the user about GNU Parallel - mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will_cite + mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will-cite chown -R zimbra. $OSE_INSTALL_DIR/.parallel # Copy file @@ -97,7 +97,7 @@ function deploy_upgrade(){ echo -ne '########## (50%)\r' # Disable Parallel's message - Zmbackup remind the user about GNU Parallel - mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will_cite + mkdir $OSE_INSTALL_DIR/.parallel && touch $OSE_INSTALL_DIR/.parallel/will-cite chown -R zimbra. $OSE_INSTALL_DIR/.parallel # Copy files From 68cc992ae9789151e0b01a10c80a839eec1e002a Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 11:16:28 -0300 Subject: [PATCH 15/23] Bugfix - including zmbackup inside the blacklist --- README.md | 4 ++-- installScript/deploy.sh | 1 + installScript/vars.sh | 2 +- project/zmbackup | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cafcfa1..1b98a2b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Zmbackup is a reliable Bash shell script developed to help you in your daily tas [![Zimbra Version](https://img.shields.io/badge/Zimbra%20OSE-8.7.11-orange.svg)](https://www.zimbra.com/downloads/zimbra-collaboration-open-source/) ![Linux Distro](https://img.shields.io/badge/platform-CentOS%20%7C%20Red%20Hat%20%7C%20Ubuntu-blue.svg) ![Branch](https://img.shields.io/badge/Branch-Development-red.svg) -![Release](https://img.shields.io/badge/Release-1.2.0%20BETA-green.svg) +![Release](https://img.shields.io/badge/Release-1.2.0%20BETA-3-green.svg) Features ------------ @@ -67,7 +67,7 @@ Inside the project folder, execute the script **install.sh** and follow all the # cd zmbackup # ./wizard.sh $ zmbackup -v - zmbackup version: 1.2.0 BETA + zmbackup version: 1.2.0 BETA 3 ``` Usage diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 6a45c03..98948be 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -17,6 +17,7 @@ function blacklist_gen(){ echo $ACCOUNT >> $ZMBKP_CONF/blacklist.conf fi done + echo $ZMBKP_ACCOUNT >> $ZMBKP_CONF/blacklist.conf } ################################################################################ diff --git a/installScript/vars.sh b/installScript/vars.sh index e9994c4..ee071a9 100644 --- a/installScript/vars.sh +++ b/installScript/vars.sh @@ -26,4 +26,4 @@ ZMBKP_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) # Zmbacku MAX_PARALLEL_PROCESS="3" # Zmbackup's number of threads ROTATE_TIME="30" # Zmbackup's max of days before housekeeper LOCK_BACKUP=true # Zmbackup's backup lock -ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA" # Zmbackup's latest version +ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA 3" # Zmbackup's latest version diff --git a/project/zmbackup b/project/zmbackup index 535bf95..694020b 100644 --- a/project/zmbackup +++ b/project/zmbackup @@ -174,7 +174,7 @@ case "$1" in show_help ;; "-v"|"--version" ) - echo "zmbackup version: 1.2.0 - BETA" + echo "zmbackup version: 1.2.0 - BETA 3" ;; * ) show_help From b7aa6db82659fe7ee5ad22d5c9184f22a5f57886 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 11:26:43 -0300 Subject: [PATCH 16/23] Bugfix - lock_backup stopped working --- project/lib/bash/ParallelAction.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/lib/bash/ParallelAction.sh b/project/lib/bash/ParallelAction.sh index 29ab5f1..3875f7e 100644 --- a/project/lib/bash/ParallelAction.sh +++ b/project/lib/bash/ParallelAction.sh @@ -109,7 +109,7 @@ function ldap_filter() grep -Fxq $1 /etc/zmbackup/blacklist.conf if [[ $? -eq 0 ]]; then echo "WARN: $1 found inside blacklist - Nothing to do." - elif [[ "$EXIST" = "$(date +%m/%d/%y)" && "$LOCK_BACKUP" == "TRUE" ]]; then + elif [[ "$EXIST" = "$(date +%m/%d/%y)" && "$LOCK_BACKUP" == "true" ]]; then echo "WARN: $1 already has backup today. Nothing to do." else echo $1 >> $TEMPACCOUNT From c16750648c8580eb9b6ea339df9fc1693cde74ef Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 11:41:22 -0300 Subject: [PATCH 17/23] Bugfix - lock_backup stopped working --- project/lib/bash/MiscAction.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/project/lib/bash/MiscAction.sh b/project/lib/bash/MiscAction.sh index 6be37fe..528255f 100644 --- a/project/lib/bash/MiscAction.sh +++ b/project/lib/bash/MiscAction.sh @@ -282,4 +282,5 @@ function export_vars(){ export LDAPPASS export MAILHOST export WORKDIR + export LOCK_BACKUP } From 24c21ed993d52313be294d517eb35e2ef4f05ab5 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 11:44:24 -0300 Subject: [PATCH 18/23] Bugfix - lock_backup stopped working and Uninstall says that dependencies are installed --- installScript/depDownload.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installScript/depDownload.sh b/installScript/depDownload.sh index 4e3bbbd..1cd9b47 100644 --- a/installScript/depDownload.sh +++ b/installScript/depDownload.sh @@ -46,7 +46,7 @@ function remove_ubuntu() { echo "Removing dependencies. Please wait..." apt-get --purge remove -y parallel wget httpie > /dev/null 2>&1 if [[ $? -eq 0 ]]; then - echo "Dependencies installed with success!" + echo "Dependencies removed with success!" else echo "Dependencies wasn't removed in your server" echo "Please check if you have connection with the internet and apt-get is" From 71ce742d80219c8d3c8de42a91db1bf844ad95fe Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 18:27:35 -0300 Subject: [PATCH 19/23] Including tasks for migration from sessions.txt to sessions.sqlite3 --- project/config/zmbackup.conf | 7 +++ project/lib/bash/SqliteAction.sh | 81 ++++++++++++++++++++++++++++++++ project/lib/sqlite3/database.sql | 29 ++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 project/lib/bash/SqliteAction.sh create mode 100644 project/lib/sqlite3/database.sql diff --git a/project/config/zmbackup.conf b/project/config/zmbackup.conf index 87ee9a6..7616b03 100644 --- a/project/config/zmbackup.conf +++ b/project/config/zmbackup.conf @@ -90,3 +90,10 @@ ROTATE_TIME={ROTATE_TIME} # DEFAULT: true LOCK_BACKUP={LOCK_BACKUP} + +# SESSION_TYPE - This option define the default place where zmbackup should store the +# information of each session. Valid values can be TXT - for session.txt +# - or SQLITE3 - for SQLite3 driver. +# DEFAULT: TXT + +SESSION_TYPE={SESSION_TYPE} diff --git a/project/lib/bash/SqliteAction.sh b/project/lib/bash/SqliteAction.sh new file mode 100644 index 0000000..c23c341 --- /dev/null +++ b/project/lib/bash/SqliteAction.sh @@ -0,0 +1,81 @@ +#!/bin/bash +################################################################################ +# Database Actions - Sqlite Drive +################################################################################ + +############################################################################### +# create_session: Migrate the entire sessions.txt to SQLite database +############################################################################### +function create_session(){ + if [[ $SESSION_TYPE == 'TXT' ]]; then + touch $WORKDIR/sessions.txt + echo "Session file recreated" + elif [[ $SESSION_TYPE == "SQLITE3" ]]; then + sqlite3 $WORKDIR/sessions.sqlite3 < /usr/local/lib/zmbackup/sqlite3/database.sql + else + echo "Invalid File Format - Nothing to do." + fi +} + +############################################################################### +# importsession: Migrate the sessions from the txt file to the sqlite3 database +############################################################################### +function importsession(){ + for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do + SESSIONID=$i + OPT=$(echo $i | cut -d"-" -f1 ) + case $OPT in + "full") + OPT="Full Backup" + YEAR=$(echo $i | cut -c6-9) + MONTH=$(echo $i | cut -c10-11) + DAY=$(echo $i | cut -c12-13) + ;; + "inc") + OPT="Incremental Backup" + YEAR=$(echo $i | cut -c5-8) + MONTH=$(echo $i | cut -c9-10) + DAY=$(echo $i | cut -c11-12) + ;; + "distlist") + OPT="Distribution List Backup" + YEAR=$(echo $i | cut -c10-13) + MONTH=$(echo $i | cut -c14-15) + DAY=$(echo $i | cut -c16-17) + ;; + "alias") + OPT="Alias Backup" + YEAR=$(echo $i | cut -c7-10) + MONTH=$(echo $i | cut -c11-12) + DAY=$(echo $i | cut -c13-14) + ;; + "ldap") + OPT="Account Backup - Only LDAP" + YEAR=$(echo $i | cut -c6-9) + MONTH=$(echo $i | cut -c10-11) + DAY=$(echo $i | cut -c12-13) + ;; + esac + INITIAL=$YEAR'-'$MONTH'-'$DAY"T00:00:00.000" + CONCLUSION=$YEAR'-'$MONTH'-'$DAY"T00:00:00.000" + SIZE=$(du -h $WORKDIR/$i | awk {'print $1'}) + STATUS="FINISHED" + sqlite3 $DATABASE "insert into backup_session values ('$SESSIONID','$INITIAL','$CONCLUSION','$SIZE','$OPT','$STATUS')" + done +} + +############################################################################### +# importaccounts: Migrate the accounts from the txt file to the sqlite3 database +############################################################################### +function importaccounts(){ + for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do + SESSIONID=$i + for j in $(egrep $i $WORKDIR/sessions.txt | grep -v 'SESSION:' | sort | uniq); do + EMAIL=$(echo $j | cut -d":" -f2) + SIZE=$(du -h $WORKDIR/$i/$EMAIL.tgz | awk {'print $1'}) + sqlite3 $DATABASE "insert into backup_account (email) values ('$EMAIL')" > /dev/null + ID=$(sqlite3 $DATABASE "select accountID from backup_account where email='$EMAIL'") + sqlite3 $DATABASE "insert into session_account (accountID,sessionID,account_size) values ('$ID','$SESSIONID','$SIZE')" > /dev/null + done + done +} diff --git a/project/lib/sqlite3/database.sql b/project/lib/sqlite3/database.sql new file mode 100644 index 0000000..24101ff --- /dev/null +++ b/project/lib/sqlite3/database.sql @@ -0,0 +1,29 @@ + create table backup_session( + sessionID varchar primary key, + initial_date timestamp not null, + conclusion_date timestamp not null, + size varchar not null, + type varchar not null, + status varchar not null + ); + + create table backup_account( + accountID integer primary key autoincrement unique, + email varchar not null); + + create table session_account( + id integer primary key autoincrement, + accountID int not null, + sessionID varchar not null, + account_size varchar not null, + foreign key (accountID) references backup_account(accountID), + foreign key (sessionID) references backup_session(sessionID) + ); + + create table backup_queue( + id integer primary key autoincrement, + accountID int not null, + sessionID varchar not null, + foreign key (accountID) references backup_account(accountID), + foreign key (sessionID) references backup_session(sessionID) + ); From e2526b772a557f630e3f6c57a566345f54dc6e75 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 18:30:43 -0300 Subject: [PATCH 20/23] Fixing README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b98a2b..e588dc1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Zmbackup is a reliable Bash shell script developed to help you in your daily tas [![Zimbra Version](https://img.shields.io/badge/Zimbra%20OSE-8.7.11-orange.svg)](https://www.zimbra.com/downloads/zimbra-collaboration-open-source/) ![Linux Distro](https://img.shields.io/badge/platform-CentOS%20%7C%20Red%20Hat%20%7C%20Ubuntu-blue.svg) ![Branch](https://img.shields.io/badge/Branch-Development-red.svg) -![Release](https://img.shields.io/badge/Release-1.2.0%20BETA-3-green.svg) +![Release](https://img.shields.io/badge/Release-1.2.0%20BETA%203-green.svg) Features ------------ From d143673f4b860655c48da0eda5031baf63418744 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 19:39:28 -0300 Subject: [PATCH 21/23] Including migration option - from SQLITE3 to TXT and TXT to SQLITE3 --- project/lib/bash/HelpAction.sh | 2 ++ .../{SqliteAction.sh => MigrationAction.sh} | 18 ++++++++++++++++++ project/lib/bash/MiscAction.sh | 6 ++++++ project/zmbackup | 4 ++++ 4 files changed, 30 insertions(+) rename project/lib/bash/{SqliteAction.sh => MigrationAction.sh} (83%) diff --git a/project/lib/bash/HelpAction.sh b/project/lib/bash/HelpAction.sh index c581841..138ebce 100644 --- a/project/lib/bash/HelpAction.sh +++ b/project/lib/bash/HelpAction.sh @@ -12,6 +12,7 @@ function show_help (){ printf "\n zmbackup [-r] [options] " printf "\n zmbackup [-r] [-ro] " printf "\n zmbackup [-d] " + printf "\n zmbackup [-m]" # All the basic options. printf "\n\nOptions:\n" @@ -22,6 +23,7 @@ function show_help (){ printf "\n -r, --restore : Restore the backup inside the users account." printf "\n -d, --delete : Delete a session of backup." printf "\n -hp, --housekeep : Execute the Housekeep to remove old sessions - Zmbhousekeep" + printf "\n -m, --migrate : Migrate the database from TXT to SQLITE3 and vice versa." printf "\n -v, --version : Show the zmbackup version." # All the options related to Full Backups diff --git a/project/lib/bash/SqliteAction.sh b/project/lib/bash/MigrationAction.sh similarity index 83% rename from project/lib/bash/SqliteAction.sh rename to project/lib/bash/MigrationAction.sh index c23c341..5e5b090 100644 --- a/project/lib/bash/SqliteAction.sh +++ b/project/lib/bash/MigrationAction.sh @@ -79,3 +79,21 @@ function importaccounts(){ done done } + +############################################################################### +# migration: Execute migration action +############################################################################### +function migration(){ + create_session + if [[ $SESSION_TYPE == "SQLITE3" ]] && ! [[ -f $WORKDIR/sessions.sqlite3 ]]; then + echo "Starting the migration - please wait until the conclusion" + importsession + importaccounts + echo "Migration completed" + rm $WORKDIR/sessions.txt + elif [[ $SESSION_TYPE == "TXT" ]] && ! [[ -f $WORKDIR/sessions.txt ]]; then + rm $WORKDIR/sessions.sqlite3 + else + echo "Nothing to do." + fi +} diff --git a/project/lib/bash/MiscAction.sh b/project/lib/bash/MiscAction.sh index 528255f..ebfa355 100644 --- a/project/lib/bash/MiscAction.sh +++ b/project/lib/bash/MiscAction.sh @@ -241,6 +241,12 @@ function validate_config(){ logger -i -p local7.err "Zmbackup: You need to define the variable ROTATE_TIME." exit 2 fi + + if [ -z "$SESSION_TYPE" ]; then + echo "You need to define the variable SESSION_TYPE." + logger -i -p local7.err "Zmbackup: You need to define the variable SESSION_TYPE." + exit 2 + fi } ################################################################################ diff --git a/project/zmbackup b/project/zmbackup index 694020b..ef81d9f 100644 --- a/project/zmbackup +++ b/project/zmbackup @@ -56,6 +56,7 @@ source /usr/local/lib/zmbackup/bash/ListAction.sh source /usr/local/lib/zmbackup/bash/BackupAction.sh source /usr/local/lib/zmbackup/bash/RestoreAction.sh source /usr/local/lib/zmbackup/bash/DeleteAction.sh +source /usr/local/lib/zmbackup/bash/MigrationAction.sh ################################################################################ # ZMBACKUP MAIN CODE @@ -176,6 +177,9 @@ case "$1" in "-v"|"--version" ) echo "zmbackup version: 1.2.0 - BETA 3" ;; + "-m"|"--migrate" ) + migration + ;; * ) show_help printf "\n\nError! Incorrect options\n\n" From 086384c7edced08b9f1c2a59b13c4ad773149277 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 19:46:19 -0300 Subject: [PATCH 22/23] Modifying Zmbackup install script to reflect the new function --- installScript/check.sh | 1 + installScript/deploy.sh | 1 + installScript/menu.sh | 6 ++++++ installScript/vars.sh | 3 ++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/installScript/check.sh b/installScript/check.sh index 10f4a1c..c7b9e7a 100644 --- a/installScript/check.sh +++ b/installScript/check.sh @@ -69,6 +69,7 @@ function check_config() { echo "Zmbackup Backups Days Max: $ROTATE_TIME" echo "Zmbackup Number of Threads: $MAX_PARALLEL_PROCESS" echo "Zmbackup Backup Lock: $LOCK_BACKUP" + echo "Zmbackup Session Default Type: $SESSION_TYPE" echo "" echo "Press ENTER to continue or CTRL+C to cancel." read diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 98948be..cd82c26 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -66,6 +66,7 @@ function deploy_new() { sed -i "s|{OSE_INSTALL_ADDRESS}|${OSE_INSTALL_ADDRESS}|g" $ZMBKP_CONF/zmbackup.conf echo -ne '############## (70%)\r' sed -i "s|{OSE_INSTALL_LDAPPASS}|${OSE_INSTALL_LDAPPASS}|g" $ZMBKP_CONF/zmbackup.conf + sed -i "s|{SESSION_TYPE}|${SESSION_TYPE}|g" $ZMBKP_CONF/zmbackup.conf echo -ne '############### (75%)\r' sed -i "s|{OSE_USER}|${OSE_USER}|g" $ZMBKP_CONF/zmbackup.conf sed -i "s|{MAX_PARALLEL_PROCESS}|${MAX_PARALLEL_PROCESS}|g" $ZMBKP_CONF/zmbackup.conf diff --git a/installScript/menu.sh b/installScript/menu.sh index 01b0907..53938ad 100644 --- a/installScript/menu.sh +++ b/installScript/menu.sh @@ -102,6 +102,12 @@ function set_values() { printf "\nZmbackup should limit backups for one per day? - DEFAULT [$LOCK_BACKUP]:" read TMP LOCK_BACKUP=${TMP:-$LOCK_BACKUP} + + # Configure mail alert + printf "\nWhere you want to store Zmbackup's sessions? TXT or SQLITE3 - DEFAULT [$SESSION_TYPE]:" + read TMP + SESSION_TYPE=${TMP:-$SESSION_TYPE} + echo -e "\n\n" echo "##################################################################################" echo "# #" diff --git a/installScript/vars.sh b/installScript/vars.sh index ee071a9..7317bb9 100644 --- a/installScript/vars.sh +++ b/installScript/vars.sh @@ -26,4 +26,5 @@ ZMBKP_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) # Zmbacku MAX_PARALLEL_PROCESS="3" # Zmbackup's number of threads ROTATE_TIME="30" # Zmbackup's max of days before housekeeper LOCK_BACKUP=true # Zmbackup's backup lock -ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA 3" # Zmbackup's latest version +ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA 3" # Zmbackup's latest version +SESSION_TYPE="TXT" # Zmbackup's default session type From 97fc623f8da6c096514a75e4dfb675833d1f6626 Mon Sep 17 00:00:00 2001 From: lucascbeyeler Date: Sun, 23 Jul 2017 19:50:21 -0300 Subject: [PATCH 23/23] Bugfix - Wrong order of the functions executed by migration --- project/lib/bash/MigrationAction.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/lib/bash/MigrationAction.sh b/project/lib/bash/MigrationAction.sh index 5e5b090..ad3d1c2 100644 --- a/project/lib/bash/MigrationAction.sh +++ b/project/lib/bash/MigrationAction.sh @@ -84,14 +84,15 @@ function importaccounts(){ # migration: Execute migration action ############################################################################### function migration(){ - create_session if [[ $SESSION_TYPE == "SQLITE3" ]] && ! [[ -f $WORKDIR/sessions.sqlite3 ]]; then echo "Starting the migration - please wait until the conclusion" + create_session importsession importaccounts echo "Migration completed" rm $WORKDIR/sessions.txt elif [[ $SESSION_TYPE == "TXT" ]] && ! [[ -f $WORKDIR/sessions.txt ]]; then + create_session rm $WORKDIR/sessions.sqlite3 else echo "Nothing to do."