diff --git a/README.md b/README.md index 3c2c196..a9c1077 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ Zmbackup is a reliable Bash shell script developed to help you in your daily tas [![Build Status](https://travis-ci.org/lucascbeyeler/zmbackup.svg?branch=master)](https://travis-ci.org/lucascbeyeler/zmbackup) [![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-BETA-red.svg) -![Release](https://img.shields.io/badge/Release-1.2.0%20BETA%204-green.svg) +![Branch](https://img.shields.io/badge/Branch-DEV-red.svg) +![Release](https://img.shields.io/badge/Release-1.2.0%20BETA%205-green.svg) Features ------------ @@ -70,7 +70,7 @@ Inside the project folder, execute the script **install.sh** and follow all the # ./wizard.sh # su - zimbra $ zmbackup -v - zmbackup version: 1.2.0 BETA 4 + zmbackup version: 1.2.0 BETA 5 ``` Usage @@ -189,7 +189,7 @@ Want to contribute to the project? ------------------ * **We are looking for Beta Testers to use the latest release of Zmbackup at this moment.** Want to help? Install a Zimbra server in your note, create some accounts and keep using Zmbackup. Any problem you find can be reported in Issues and our Google Group, and will be fixed in the next release. - * **Valid version:** 1.2.0 BETA 4 + * **Valid version:** 1.2.0 BETA 5 * **We are looking for peoples to correct and keep up to date the documentation:** At this moment the documentation is only this README.md file, but I have plans to expand to a real documentation using Read the Docs. Do you have time and want to write? You can fork this project and start right now! Remember to document only 1.2.0 content there! diff --git a/install.sh b/install.sh index 75a2fd6..5260a35 100755 --- a/install.sh +++ b/install.sh @@ -13,10 +13,23 @@ source installScript/depDownload.sh source installScript/deploy.sh source installScript/menu.sh source installScript/vars.sh +source installScript/help.sh ################################################################################ # INSTALL MAIN CODE ################################################################################ + +# +# Help code +################################################################################ +if [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then + show_help + exit 0 +fi + +# +# Checking your environment +################################################################################ check_env $1 # diff --git a/installScript/deploy.sh b/installScript/deploy.sh index 130c3f2..b6002ad 100644 --- a/installScript/deploy.sh +++ b/installScript/deploy.sh @@ -130,6 +130,7 @@ function deploy_upgrade(){ ################################################################################ function uninstall() { echo "Removing... Please wait while we made some changes." + source $ZMBKP_CONF/zmbackup.conf echo -ne ' (0%)\r' rm -rf $ZMBKP_SHARE $ZMBKP_SRC/zmbhousekeep > /dev/null 2>&1 rm -rf $OSE_INSTALL_DIR/.parallel @@ -144,4 +145,10 @@ function uninstall() { 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' + echo "Preserve Backup Storage?[n/Y]" + read OPT + if [[ $OPT != 'N' && $OPT != 'n' ]]; then + echo "Removing backup storage..." + rm -rf $WORKDIR/* + fi } diff --git a/installScript/help.sh b/installScript/help.sh new file mode 100644 index 0000000..c8b9737 --- /dev/null +++ b/installScript/help.sh @@ -0,0 +1,20 @@ +#!/bin/bash +################################################################################ +# Command Help Option +################################################################################ + +################################################################################ +# show_help: It will show a quick help about each command from install.sh +################################################################################ +function show_help (){ + printf "usage: install.sh [options]" + + # All the basic options. + printf "\n\nOptions:\n" + + printf "\n -r, --remove : Uninstall Zmbackup and remove all the files" + printf "\n --force-upgrade : Force install.sh upgrade your installation - does not remove the configuration files." + printf "\n -h, --help : Show this help" + + printf "\n\n\n" +} diff --git a/installScript/vars.sh b/installScript/vars.sh index ed6bdaf..285dbec 100644 --- a/installScript/vars.sh +++ b/installScript/vars.sh @@ -26,5 +26,5 @@ ZMBKP_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) 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 4" # Zmbackup's latest version +ZMBKP_VERSION="zmbackup version: 1.2.0 - BETA 5" # Zmbackup's latest version SESSION_TYPE="TXT" # Zmbackup's default session type diff --git a/project/config/zmbackup.cron b/project/config/zmbackup.cron index 388fff4..c5def02 100644 --- a/project/config/zmbackup.cron +++ b/project/config/zmbackup.cron @@ -16,5 +16,5 @@ MAILTO=root 30 1 * * 0 zimbra zmbackup -f 30 1 * * 1-6 zimbra zmbackup -i 0 1 * * * zimbra zmbackup -f -dl -0 30 * * * zimbra zmbackup -f -al +30 0 * * * zimbra zmbackup -f -al 0 0 * * * zimbra zmbackup -hp diff --git a/project/lib/bash/BackupAction.sh b/project/lib/bash/BackupAction.sh index de3aa26..a71c812 100644 --- a/project/lib/bash/BackupAction.sh +++ b/project/lib/bash/BackupAction.sh @@ -11,6 +11,7 @@ # ACOBJECT - User Account; ################################################################################ function __backupFullInc(){ + SDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) ldap_backup $1 $2 if [ $ERRCODE -eq 0 ]; then mailbox_backup $1 @@ -18,9 +19,10 @@ function __backupFullInc(){ if [[ $SESSION_TYPE == 'TXT' ]]; then echo $SESSION:$1:$(date +%m/%d/%y) >> $TEMPSESSION elif [[ $SESSION_TYPE == "SQLITE3" ]]; then - DATE=$(date +%Y-%m-%dT%H:%M:%S.%N) + EDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) SIZE=$(du -ch $WORKDIR/$i* | grep total | cut -f1) - echo "insert into backup_account (email,sessionID,account_size) values ('$1','$SESSION','$SIZE');" >> $TEMPSQL + echo "insert into backup_account (email,sessionID,account_size, initial_date, \ + conclusion_date) values ('$1','$SESSION','$SIZE','$SDATE','$EDATE');" >> $TEMPSQL fi fi fi @@ -36,14 +38,16 @@ function __backupFullInc(){ # ALOBJECT - Alias; ################################################################################ function __backupLdap(){ + SDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) ldap_backup $1 $2 if [ $ERRCODE -eq 0 ]; then if [[ $SESSION_TYPE == 'TXT' ]]; then echo $SESSION:$1:$(date +%m/%d/%y) >> $TEMPSESSION elif [[ $SESSION_TYPE == "SQLITE3" ]]; then - DATE=$(date +%Y-%m-%dT%H:%M:%S.%N) + EDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) SIZE=$(du -ch $WORKDIR/$i* | grep total | cut -f1) - echo "insert into backup_account (email,sessionID,account_size) values ('$1','$SESSION','$SIZE');" >> $TEMPSQL + echo "insert into backup_account (email,sessionID,account_size, initial_date, \ + conclusion_date) values ('$1','$SESSION','$SIZE','$SDATE','$EDATE');" >> $TEMPSQL fi fi } @@ -56,14 +60,16 @@ function __backupLdap(){ # ACOBJECT - User Account; ################################################################################ function __backupMailbox(){ + SDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) mailbox_backup $1 $2 if [ $ERRCODE -eq 0 ]; then if [[ $SESSION_TYPE == 'TXT' ]]; then echo $SESSION:$1:$(date +%m/%d/%y) >> $TEMPSESSION elif [[ $SESSION_TYPE == "SQLITE3" ]]; then - DATE=$(date +%Y-%m-%dT%H:%M:%S.%N) + EDATE=$(date +%Y-%m-%dT%H:%M:%S.%N) SIZE=$(du -ch $WORKDIR/$i* | grep total | cut -f1) - echo "insert into backup_account (email,sessionID,account_size) values ('$1','$SESSION','$SIZE');" >> $TEMPSQL + echo "insert into backup_account (email,sessionID,account_size, initial_date, \ + conclusion_date) values ('$1','$SESSION','$SIZE','$SDATE','$EDATE');" >> $TEMPSQL fi fi } @@ -101,7 +107,9 @@ function backup_main() echo "SESSION: $SESSION started on $(date)" >> $TEMPSESSION elif [[ $SESSION_TYPE == "SQLITE3" ]]; then DATE=$(date +%Y-%m-%dT%H:%M:%S.%N) - sqlite3 $WORKDIR/sessions.sqlite3 "insert into backup_session(sessionID,initial_date,type,status) values ('$SESSION','$DATE','$STYPE','IN PROGRESS')" > /dev/null 2>&1 + sqlite3 $WORKDIR/sessions.sqlite3 "insert into backup_session(sessionID,\ + initial_date,type,status) values \ + ('$SESSION','$DATE','$STYPE','IN PROGRESS')" > /dev/null 2>&1 fi if [[ "$SESSION" == "full"* ]] || [[ "$SESSION" == "inc"* ]]; then cat $TEMPACCOUNT | parallel --no-notice --jobs $MAX_PARALLEL_PROCESS \ @@ -121,7 +129,9 @@ function backup_main() DATE=$(date +%Y-%m-%dT%H:%M:%S.%N) SIZE=$(du -sh $WORKDIR/$i | awk {'print $1'}) sqlite3 $WORKDIR/sessions.sqlite3 < $TEMPSQL > /dev/null 2>&1 - sqlite3 $WORKDIR/sessions.sqlite3 "update backup_session set conclusion_date='$DATE',size='$SIZE',status='FINISHED' where sessionID='$SESSION'" > /dev/null 2>&1 + sqlite3 $WORKDIR/sessions.sqlite3 "update backup_session set conclusion_date='$DATE',\ + size='$SIZE',status='FINISHED' where \ + sessionID='$SESSION'" > /dev/null 2>&1 fi logger -i -p local7.info "Zmbackup: Backup session $SESSION finished on $(date)" echo "Backup session $SESSION finished on $(date)" diff --git a/project/lib/bash/HelpAction.sh b/project/lib/bash/HelpAction.sh index 4af2eac..696d215 100644 --- a/project/lib/bash/HelpAction.sh +++ b/project/lib/bash/HelpAction.sh @@ -17,22 +17,23 @@ function show_help (){ # All the basic options. printf "\n\nOptions:\n" - printf "\n -f, --full : Execute full backup of an account, a list of accounts, or all accounts." - printf "\n -i, --incremental : Execute incremental backup for an account, a list of accounts, or all accounts." - printf "\n -l, --list : List all backup sessions that still exist in your disk." - 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." + printf "\n -f, --full : Execute full backup of an account, a list of accounts, or all accounts." + printf "\n -i, --incremental : Execute incremental backup for an account, a list of accounts, or all accounts." + printf "\n -l, --list : List all backup sessions that still exist in your disk." + 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." + printf "\n -h, --help : Show this help" # All the options related to Full Backups printf "\n\nFull Backup Options:\n" - printf "\n -m, --mail : Execute a backup of an account, but only the mailbox." - printf "\n -dl, --distributionlist : Execute a backup of a distributionlist instead of an account." - printf "\n -al, --alias : Execute a backup of an alias instead of an account." - printf "\n -ldp, --ldap : Execute a backup of an account, but only the ldap entry." + printf "\n -m, --mail : Execute a backup of an account, but only the mailbox." + printf "\n -dl, --distributionlist : Execute a backup of a distributionlist instead of an account." + printf "\n -al, --alias : Execute a backup of an alias instead of an account." + printf "\n -ldp, --ldap : Execute a backup of an account, but only the ldap entry." # All the options related to Restore Backups printf "\n\nRestore Backup Options:\n" diff --git a/project/lib/bash/MigrationAction.sh b/project/lib/bash/MigrationAction.sh index 2f4eb95..92f63fb 100644 --- a/project/lib/bash/MigrationAction.sh +++ b/project/lib/bash/MigrationAction.sh @@ -19,9 +19,9 @@ function create_session(){ } ############################################################################### -# importsession: Migrate the sessions from the txt file to the sqlite3 database +# importsessionSQL: Migrate the sessions from the txt file to the sqlite3 database ############################################################################### -function importsession(){ +function importsessionSQL(){ for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do SESSIONID=$i OPT=$(echo $i | cut -d"-" -f1 ) @@ -59,22 +59,42 @@ function importsession(){ 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'}) + SIZE=$(du -ch $WORKDIR/$i | grep total | awk {'print $1'}) STATUS="FINISHED" - sqlite3 sessions.sqlite3 "insert into backup_session values ('$SESSIONID','$INITIAL','$CONCLUSION','$SIZE','$OPT','$STATUS')" + sqlite3 $WORKDIR/sessions.sqlite3 "insert into backup_session values ('$SESSIONID',\ + '$INITIAL','$CONCLUSION','$SIZE','$OPT','$STATUS')" done } ############################################################################### -# importaccounts: Migrate the accounts from the txt file to the sqlite3 database +# importaccountsSQL: Migrate the accounts from the txt file to the sqlite3 database ############################################################################### -function importaccounts(){ +function importaccountsSQL(){ for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do - SESSIONID=$i + DATE=$(sqlite3 $WORKDIR/sessions.sqlite3 "select conclusion_date from backup_session where 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 $WORKDIR/sessions.sqlite3 "insert into backup_account (email,sessionID,account_size) values ('$EMAIL','$SESSIONID','$SIZE')" > /dev/null + SIZE=$(du -ch $WORKDIR/$i/$EMAIL* | grep total | awk {'print $1'}) + sqlite3 $WORKDIR/sessions.sqlite3 "insert into backup_account (email,sessionID,\ + account_size,initial_date, conclusion_date) \ + values ('$EMAIL','$i','$SIZE','$DATE','$DATE')" > /dev/null + done + done +} + +############################################################################### +# importaccountsTXT: Migrate the accounts from the txt file to the sqlite3 database +############################################################################### +function importsessionTXT(){ + sqlite3 $WORKDIR/sessions.sqlite3 "select sessionID,conclusion_date from backup_session" | while read SESSION; do + MONTH=$(echo $i | cut -d'|' -f2 | cut -d'-' -f2) + DAY=$(echo $i | cut -d'|' -f2 | cut -d'-' -f3 | cut -d'T' -f1) + YEAR=$(echo $i | cut -d'|' -f2 | cut -d'-' -f1) + HOUR=$(echo $i | cut -d'|' -f2 | cut -d'-' -f3 | cut -d'T' -f2) + MINUTE=$(echo $i | cut -d'|' -f2 | cut -d'-' -f3 | cut -d':' -f2) + echo "SESSION: $SESSION started on $(date -d '$MONTH/$DAY/$YEAR $HOUR:$MINUTE')" >> $WORKDIR/sessions.txt + sqlite3 $WORKDIR/sessions.sqlite3 "select email from backup_account where sessionID='$SESSION'" | while read SESSION; do + echo "$SESSION:$ACCOUNT:$MONTH/$DAY/$YEAR" >> $WORKDIR/sessions.txt done done } @@ -86,12 +106,13 @@ function migration(){ if [[ $SESSION_TYPE == "SQLITE3" ]] && ! [[ -f $WORKDIR/sessions.sqlite3 ]]; then echo "Starting the migration - please wait until the conclusion" create_session - importsession - importaccounts + importsessionSQL + importaccountsSQL rm $WORKDIR/sessions.txt echo "Migration completed" elif [[ $SESSION_TYPE == "TXT" ]] && ! [[ -f $WORKDIR/sessions.txt ]]; then create_session + importsessionSQL rm $WORKDIR/sessions.sqlite3 echo "Migration completed" else diff --git a/project/lib/bash/MiscAction.sh b/project/lib/bash/MiscAction.sh index 278f0be..4f6762e 100644 --- a/project/lib/bash/MiscAction.sh +++ b/project/lib/bash/MiscAction.sh @@ -103,100 +103,6 @@ function constant(){ fi } -################################################################################ -# list_sessions: Just call the correct function based on $SESSION_TYPE -################################################################################ -function list_sessions() -{ - if [[ $SESSION_TYPE == 'TXT' ]]; then - list_sessions_txt - elif [[ $SESSION_TYPE == "SQLITE3" ]]; then - list_sessions_sqlite3 - else - echo "Invalid File Format - Nothing to do." - fi -} - -################################################################################ -# list_sessions_txt: List all the sessions stored inside the server - TXT -################################################################################ -function list_sessions_txt () -{ - printf "+---------------------------+------------+----------+----------------------------+\n" - printf "| Session Name | Date | Size | Description |\n" - printf "+---------------------------+------------+----------+----------------------------+\n" - for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do - - # Load variables - SIZE=$(du -h $WORKDIR/$i | awk {'print $1'}) - if [[ $i == "mbox"* ]]; then - QTDE=$(ls $WORKDIR/$i/*.tgz | wc -l) - else - QTDE=$(ls $WORKDIR/$i/*.ldiff | wc -l) - fi - 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 - - # Printing the information as a table - printf "| %-25s | %s/%s/%s | %-8s | %-26s |\n" $i $MONTH $DAY $YEAR $SIZE "$OPT" - done - printf "+---------------------------+------------+----------+----------------------------+\n" -} - -################################################################################ -# list_sessions_sqlite3: List all the sessions stored inside the server - SQLITE3 -################################################################################ -function list_sessions_sqlite3 () -{ - printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" - printf "| Session Name | Start | Ending | Size | Description |\n" - printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" - sqlite3 $WORKDIR/sessions.sqlite3 'select * from backup_session' | while read i ; do - NAME=$(echo $i | cut -d'|' -f1) - SMONTH=$(echo $i | cut -d'|' -f2 | cut -d'-' -f2) - SDAY=$(echo $i | cut -d'|' -f2 | cut -d'-' -f3 | cut -d'T' -f1) - SYEAR=$(echo $i | cut -d'|' -f2 | cut -d'-' -f1) - EMONTH=$(echo $i | cut -d'|' -f3 | cut -d'-' -f2) - EDAY=$(echo $i | cut -d'|' -f3 | cut -d'-' -f3 | cut -d'T' -f1) - EYEAR=$(echo $i | cut -d'|' -f3 | cut -d'-' -f1) - SIZE=$(echo $i | cut -d'|' -f4) - OPT=$(echo $i | cut -d'|' -f5) - printf "| %-25s | %s/%s/%s | %s/%s/%s | %-8s | %-26s |\n" $NAME $SMONTH $SDAY $SYEAR $EMONTH $EDAY $EYEAR $SIZE "$OPT" - done - printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" -} - ################################################################################ # validate_config: Validate if all the values are informed and set the default if not ################################################################################ diff --git a/project/lib/bash/ParallelAction.sh b/project/lib/bash/ParallelAction.sh index 3875f7e..2385bd9 100644 --- a/project/lib/bash/ParallelAction.sh +++ b/project/lib/bash/ParallelAction.sh @@ -35,7 +35,13 @@ function ldap_backup() function mailbox_backup() { if [[ "$INC" == "TRUE" ]]; then - DATE=$(grep $1 $WORKDIR/sessions.txt | tail -1 | awk -F: '{print $3}' | cut -d'-' -f2) + if [[ $SESSION_TYPE == 'TXT' ]]; then + DATE=$(grep $1 $WORKDIR/sessions.txt | tail -1 | awk -F: '{print $3}' | cut -d'-' -f2) + elif [[ $SESSION_TYPE == 'SQLITE3' ]]; then + DATE=$(sqlite3 $WORKDIR/sessions.sqlite3 "select MAX(initial_date) \ + from backup_account where email='$1' and \ + (sessionID like 'full%' or sessionID like 'inc%' or sessionID like 'mbox%')") + fi AFTER='&'"start="$(date -d $DATE +%s)"000" fi ERR=$((wget --timeout=5 --tries=2 -O $TEMPDIR/$1.tgz --user $ADMINUSER --password $ADMINPASS \ diff --git a/project/lib/bash/SessionAction.sh b/project/lib/bash/SessionAction.sh new file mode 100644 index 0000000..1df3bfa --- /dev/null +++ b/project/lib/bash/SessionAction.sh @@ -0,0 +1,98 @@ +#!/bin/bash +################################################################################ +# Session List Functions +################################################################################ + +################################################################################ +# list_sessions: Just call the correct function based on $SESSION_TYPE +################################################################################ +function list_sessions() +{ + if [[ $SESSION_TYPE == 'TXT' ]]; then + list_sessions_txt + elif [[ $SESSION_TYPE == "SQLITE3" ]]; then + list_sessions_sqlite3 + else + echo "Invalid File Format - Nothing to do." + fi +} + +################################################################################ +# list_sessions_txt: List all the sessions stored inside the server - TXT +################################################################################ +function list_sessions_txt () +{ + printf "+---------------------------+------------+----------+----------------------------+\n" + printf "| Session Name | Date | Size | Description |\n" + printf "+---------------------------+------------+----------+----------------------------+\n" + for i in $(egrep 'SESSION:' $WORKDIR/sessions.txt | egrep 'started' | awk '{print $2}' | sort | uniq); do + + # Load variables + SIZE=$(du -h $WORKDIR/$i | awk {'print $1'}) + if [[ $i == "mbox"* ]]; then + QTDE=$(ls $WORKDIR/$i/*.tgz | wc -l) + else + QTDE=$(ls $WORKDIR/$i/*.ldiff | wc -l) + fi + 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 + + # Printing the information as a table + printf "| %-25s | %s/%s/%s | %-8s | %-26s |\n" $i $MONTH $DAY $YEAR $SIZE "$OPT" + done + printf "+---------------------------+------------+----------+----------------------------+\n" +} + +################################################################################ +# list_sessions_sqlite3: List all the sessions stored inside the server - SQLITE3 +################################################################################ +function list_sessions_sqlite3 () +{ + printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" + printf "| Session Name | Start | Ending | Size | Description |\n" + printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" + sqlite3 $WORKDIR/sessions.sqlite3 'select * from backup_session' | while read i ; do + NAME=$(echo $i | cut -d'|' -f1) + SMONTH=$(echo $i | cut -d'|' -f2 | cut -d'-' -f2) + SDAY=$(echo $i | cut -d'|' -f2 | cut -d'-' -f3 | cut -d'T' -f1) + SYEAR=$(echo $i | cut -d'|' -f2 | cut -d'-' -f1) + EMONTH=$(echo $i | cut -d'|' -f3 | cut -d'-' -f2) + EDAY=$(echo $i | cut -d'|' -f3 | cut -d'-' -f3 | cut -d'T' -f1) + EYEAR=$(echo $i | cut -d'|' -f3 | cut -d'-' -f1) + SIZE=$(echo $i | cut -d'|' -f4) + OPT=$(echo $i | cut -d'|' -f5) + printf "| %-25s | %s/%s/%s | %s/%s/%s | %-8s | %-26s |\n" $NAME $SMONTH $SDAY $SYEAR $EMONTH $EDAY $EYEAR $SIZE "$OPT" + done + printf "+---------------------------+--------------+--------------+----------+----------------------------+\n" +} diff --git a/project/lib/sqlite3/database.sql b/project/lib/sqlite3/database.sql index c0cb183..59a77d5 100644 --- a/project/lib/sqlite3/database.sql +++ b/project/lib/sqlite3/database.sql @@ -12,5 +12,7 @@ sessionID varchar not null, account_size varchar not null, email varchar not null, + initial_date timestamp not null, + conclusion_date timestamp, foreign key (sessionID) references backup_session(sessionID) ); diff --git a/project/zmbackup b/project/zmbackup index 4f4e36b..1e88262 100644 --- a/project/zmbackup +++ b/project/zmbackup @@ -36,7 +36,7 @@ ################################################################################ # zmbackup: # -# 03/09/2017 - Version 1.2.0 - By Lucas Costa Beyeler +# 07/09/2017 - Version 1.2.0 - By Lucas Costa Beyeler # # ################################################################################ @@ -57,6 +57,7 @@ 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 +source /usr/local/lib/zmbackup/bash/SessionAction.sh ################################################################################ # ZMBACKUP MAIN CODE @@ -149,8 +150,15 @@ case "$1" in restore_main_mailbox $3 $4 ;; * ) - show_help - printf "\n\nError! Incorrect option\n" + if [[ "$SESSION" == "full"* ]] || [[ "$SESSION" == "inc"* ]]; then + constant + checkpid + restore_main_ldap $2 $3 + restore_main_mailbox $2 $3 + else + show_help + printf "\n\nError! Incorrect option\n" + fi ;; esac fi @@ -175,7 +183,7 @@ case "$1" in show_help ;; "-v"|"--version" ) - echo "zmbackup version: 1.2.0 - BETA 4" + echo "zmbackup version: 1.2.0 - BETA 5" ;; "-m"|"--migrate" ) migration