Skip to content

Commit

Permalink
Merge pull request #50 from lucascbeyeler/dev
Browse files Browse the repository at this point in the history
Zmbackup BETA 5 New Release
  • Loading branch information
lucascbeyeler authored Sep 8, 2017
2 parents f372032 + b5919dd commit 92b40e4
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 136 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
13 changes: 13 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
7 changes: 7 additions & 0 deletions installScript/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
20 changes: 20 additions & 0 deletions installScript/help.sh
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion installScript/vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion project/config/zmbackup.cron
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 18 additions & 8 deletions project/lib/bash/BackupAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
# 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
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
fi
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 \
Expand All @@ -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)"
Expand Down
25 changes: 13 additions & 12 deletions project/lib/bash/HelpAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 32 additions & 11 deletions project/lib/bash/MigrationAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
Loading

0 comments on commit 92b40e4

Please sign in to comment.