Zimbra backup open source for zimbra 8.x for 7 Days

The Script will take the backup in the /backup/zimbra/1 , /backup/zimbra/2 , /backup/zimbra/3 ,  /backup/zimbra/4 , /backup/zimbra/5 , /backup/zimbra/6 , /backup/zimbra/7 and after 7th day it will overwrite the day1 folder. 

This will keep the full backup for all the users in the 7 folders. 
In this script  replace the domain.com with your company domain name.
The Script can be schedule in cron tab jobs.


#!/bin/bash -x
DateToday=`date -I`
FolderZ=`date +%d`
X=$FolderZ
W2=7
W3=14
W4=21
W5=28
if [ "$X" -lt 8 ]
then
X=`expr $X - 0`
echo $X
elif [ "$X" -lt 15 ]
then
X=`expr $X - $W2`
elif [ "$X" -lt 22 ]
then
X=`expr $X - $W3`
elif [ "$X" -lt 29 ]
then
X=`expr $X - $W4`
else
X=`expr $X - $W5`
fi
echo $X
rm -rf /backup/zimbra/$X/*
su zimbra -c "/opt/zimbra/libexec/zmslapcat /backup/ldapbkp"
su zimbra -c "/opt/zimbra/libexec/zmslapcat -c /backup/ldapbkp"
sudo -u zimbra /opt/zimbra/bin/zmprov -l gaa -v | grep uid | grep -v spam | grep -v ham | grep -v zimbra | grep -v virus | grep -v galsync  > /tmp/usertmp
sed 's/uid: //g' /tmp/usertmp > /tmp/userlist$DateToday
#Backup of Zimbra mailboxes using zmmailbox
# Restore of mailbox should be performed using:
# /opt/zimbra/bin/zmmailbox -z -m user@host postRestURL -u https://HOST "//?fmt=tgz&resolve=skip" mailbox-name-date.tgz
BackupFolder="/backup/zimbra"
for MailBox in `cat /tmp/userlist$DateToday`
do
#echo $FolderZ
sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $MailBox@domain.com getRestURL "//?fmt=tgz" > /backup/zimbra/$X/$MailBox-$DateToday.tgz
done
cat /tmp/messagebkp /tmp/userlist$DateToday > /tmp/userlistmessage$DateToday
/opt/zimbra/postfix-2.10.3.2z/sbin/sendmail -t admin@domain.com < /tmp/userlistmessage$DateToday

Popular posts from this blog

Password Expiry notification for the users in zimbra 8.x within 7 Days for the email users

Hacking