Vous êtes sur la page 1sur 2

@rtduweb

BASH : Backup de ZIMBRA OpenSource Edition

Zimbra dans sa version gratuite ne possède pas la fonction de backup intégrée.


Ce script permet la sauvegarde de tous les comptes de chaque domaine, un dump LDAP et MYSQL et rend compte de son éxecution par mail.

#!/bin/sh

# Variables
DATE=`/bin/date +%d-%m-%Y`
BCK_DIR="/opt/backup/$DATE"
BCK_SYS="/opt/backup/$DATE/system-Zimbra"
LOG="/opt/backup/$DATE/save.log"
NORMAL="\\033[0;39m"
ROUGE="\\033[1;31m"
PASSWD=`zmlocalconfig -s | grep mysql_root_password | awk -F" " '{print $3}'`
mkdir -p $BCK_DIR
mkdir $BCK_SYS
touch $LOG

echo " " | tee -a $LOG


echo -e $ROUGE"*************************************************" | tee -a $LOG
echo "* Debut de la sauvegarde du `/bin/date +%d/%m/%Y` *" | tee -a $LOG
echo "*************************************************" | tee -a $LOG
echo -e $NORMAL" " | tee -a $LOG

# Copie du fichier localconfig


echo "- `/bin/date +%H:%M:%S`: Lancement copie fichier localconfig" | tee -a $LOG
cp /opt/zimbra/conf/localconfig.xml $BCK_SYS | tee -a $LOG
echo "- `/bin/date +%H:%M:%S`: Fin copie fichier localconfig" | tee -a $LOG
echo " " | tee -a $LOG

# Backup LDAP
echo "- `/bin/date +%H:%M:%S`: Lancement du backup ldap" | tee -a $LOG
/opt/zimbra/libexec/zmslapcat $BCK_SYS | tee -a $LOG
echo "- `/bin/date +%H:%M:%S`: Fin du backup ldap" | tee -a $LOG
echo " " | tee -a $LOG

# Backup MySQL
echo "- `/bin/date +%H:%M:%S`: Lancement du dump Mysql" | tee -a $LOG
/opt/zimbra/mysql/bin/mysqldump -S /opt/zimbra/db/mysql.sock -u root -p$PASSWD --host localhost --port 7306 --all-databases --single-transaction > $BCK_SYS/zimbra-mysql.sq
echo "- `/bin/date +%H:%M:%S`: Fin du dump Mysql" | tee -a $LOG
echo " " | tee -a $LOG

# Lancement exportation mailbox


echo "- `/bin/date +%H:%M:%S`: Lancement exportation mailbox" | tee -a $LOG
echo "- Sauvegarde de tous les comptes existants des domaines :" | tee -a $LOG
/opt/zimbra/bin/zmprov gad | tee -a $LOG
echo " " | tee -a $LOG
for i1 in `zmprov gad`
do
mkdir $BCK_DIR/$i1
for i2 in `/opt/zimbra/bin/zmprov -l gaa $i1`
do
# echo /opt/zimbra/bin/zmmailbox -z -m $i getRestURL \"//?fmt=tgz\" \> $BCK_DIR/$i.tgz
#/opt/zimbra/bin/zmmailbox -z -m $i getRestURL "//?fmt=tgz" > $BCK_DIR/$i.tgz
/opt/zimbra/bin/zmmailbox -z -m $i2 getRestURL '//?fmt=zip' > $BCK_DIR/$i1/$i2.zip
done
done
RES=$?
if [ $RES != 0 ] ;
then
echo "- `/bin/date +%H:%M:%S` : PROBLEME La sauvegarde ZIMBRA est en erreur: code $RES" | tee -a $LOG | /opt/zimbra/postfix/sbin/sendmail root@domaine.fr -s "Erreur sauv
else
echo "La sauvegarde termine sans erreur (code error=$RES)" | tee -a $LOG
tree -L 3 $BCK_DIR | tee -a $LOG
fi

echo "- `/bin/date +%H:%M:%S`: Fin exportation mailbox" | tee -a $LOG


echo " " | tee -a $LOG
# Fin
echo -e $ROUGE"********************************************" | tee -a $LOG
echo "* Fin de la sauvegarde du `/bin/date +%d/%m/%Y` *" | tee -a $LOG
echo "******************************************** " | tee -a $LOG
echo -e $NORMAL " " | tee -a $LOG
exit 0

backup, bash, for, postfix, mysql, zimbra

Download Worlds no. 1 Video - Management Software for Free.


OUVRIR
Supports up to 8 cameras. The most feature-rich free VMS available on the market
milestonesys.com/videomanagement
scripting/backup-zimbra.txt · Dernière modification: 15/04/2016 à 21:15 (modification externe)

Vous aimerez peut-être aussi