Full backup script ...
 
Notifications
Clear all

Full backup script zextras carbonio

8 Posts
3 Users
3 Reactions
890 Views
(@raystinger)
Joined: 8 months ago
Posts: 37
Topic starter  

i want to present script backup of zextras carbonio (default instalations )

 just copy paste on script and save as xxxx.sh

chmod +x  nameofscript.sh

 

details of script

#!/bin/bash

#day calculator script 


#yesterday
d=`date -d "yesterday" '+%d_%B_%Y'` 

#today

d=`date  '+%d_%B_%Y'` 





chown -R zextras:zextras /home/carbonio_backup/

cd /home/carbonio_backup/
mkdir user_mail_$d

cd user_mail_$d

echo copying all email data and password ....

sudo -u zextras /opt/zextras/bin/zmprov -l gad > domains_$d.txt  
sudo -u zextras /opt/zextras/bin/zmprov -l gaa > emails_$d.txt  

mkdir account_$d
mkdir password_$d
mkdir inbox_$d


chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/account_$d
chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/password_$d
chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/inbox_$d

echo  backing up all inbox account ....

for email in `cat /home/carbonio_backup/user_mail_$d/emails_$d.txt`; do /opt/zextras/bin/zmmailbox -z -m $email -t 0 getRestURL '/?fmt=tgz' > /home/carbonio_backup/user_mail_$d/inbox_$d/$email.tgz ; echo $email ; done   >> "/home/carbonio_backup/log_backup.log" 

sleep 3
echo  backing up all account details ....

for i in `cat emails_$d.txt`; do /opt/zextras/bin/zmprov ga $i | grep -i Name: > /home/carbonio_backup/user_mail_$d/account_$d/$i.txt ; done  >> "/home/carbonio_backup/log_backup.log" 

sleep 3
echo  backing up all account passwords  ....

for i in `cat emails_$d.txt`; do /opt/zextras/bin/zmprov -l ga $i userPassword | grep userPassword: | awk '{ print $2}' > /home/carbonio_backup/user_mail_$d/password_$d/$i.shadow; done >> "/home/carbonio_backup/log_backup.log" 


sleep 3

tar -czvf /home/carbonio_backup/full_backup/carbonio_data_$d.tar.gz /home/carbonio_backup/user_mail_$d  >> "/home/backup_carbonio/log_backup.log" 

echo backup finished ...







note :

this script will backup on /home mount point so make sure you have enough space to backup

feel free to discus and i will update for group and distributions list later

 


   
Quote
(@raystinger)
Joined: 8 months ago
Posts: 37
Topic starter  

updated script with following backup

1. all user mailbox data

2. user account details

3. user account password

4. group and distribution list

 

 

before do make sure u do this with zextras user

su - zextras

zmlocalconfig -e socket_so_timeout=3000000

 

then u can go to admin panel https://xxx.xxx.xxx.xxx:6071/carbonioAdmin

 

go to domain--> your domain to backup --> general -->public service protocol choose HTTPS ( must do )

then copy this script save as yourscript.sh and chmod +x on your /home folder

 

 

#!/bin/bash

#hari kemarin
d=`date -d "yesterday" '+%d_%B_%Y'`

#hari ini

d=`date '+%d_%B_%Y'`

echo

$d

chown -R zextras:zextras /home/carbonio_backup/

cd /home/carbonio_backup/
mkdir user_mail_$d

cd user_mail_$d

echo copying all email data and password ....

sudo -u zextras /opt/zextras/bin/zmprov -l gad > domains_$d.txt
sudo -u zextras /opt/zextras/bin/zmprov -l gaa > emails_$d.txt

mkdir account_$d
mkdir password_$d
mkdir inbox_$d
mkdir distribution_list$d

chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/account_$d
chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/password_$d
chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/inbox_$d
chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/distribution_list$d

echo backup all distribution list

/opt/zextras/bin/zmprov gadl > /home/carbonio_backup/user_mail_$d/distributionlist_$d.txt >> "/home/carbonio_backup/log_backup.log"

for i in `cat /home/carbonio_backup/user_mail_$d/distributionlist_$d.txt`; do zmprov gdlm $i > chown -R zextras:zextras /home/carbonio_backup/user_mail_$d/distribution_list$d/$i.txt ;echo "$i"; done >> "/home/carbonio_backup/log_backup.log"

echo backing up all inbox account ....

for email in `cat /home/carbonio_backup/user_mail_$d/emails_$d.txt`; do /opt/zextras/bin/zmmailbox -z -m $email -t 0 getRestURL '/?fmt=tgz' > /home/carbonio_backup/user_mail_$d/inbox_$d/$email.tgz ; echo $email ; done >> "/home/carbonio_backup/log_backup.log"

sleep 3
echo backing up all account details ....

for i in `cat emails_$d.txt`; do /opt/zextras/bin/zmprov ga $i | grep -i Name: > /home/carbonio_backup/user_mail_$d/account_$d/$i.txt ; done >> "/home/carbonio_backup/log_backup.log"

sleep 3
echo backing up all account passwords ....

for i in `cat emails_$d.txt`; do /opt/zextras/bin/zmprov -l ga $i userPassword | grep userPassword: | awk '{ print $2}' > /home/carbonio_backup/user_mail_$d/password_$d/$i.shadow; done >> "/home/carbonio_backup/log_backup.log"

echo compressing into 1 file ...
sleep 3

tar -czvf /home/carbonio_backup/full_backup/carbonio_data_$d.tar.gz /home/carbonio_backup/user_mail_$d
sleep 3

echo deleting separate folder ...

rm -rf /home/carbonio_backup/user_mail_$d

echo all done!
sleep 15

 


   
ReplyQuote
(@sharif)
Admin
Joined: 2 years ago
Posts: 591
 

@raystinger 

Hi,

It is great.

Alternatively, you can dump LDAP data to get a comprehensive backup. like:

/opt/zextras/common/sbin/slapcat -F /opt/zextras/data/ldap/config -b "" -s "cn=cos,cn=zimbra" -H ldap:///???(&(objectClass=zimbraCos)(!(cn=default))(!(cn=defaultExternal))) -l /opt/zextras/backup/coses.ldif

and

/opt/zextras/backup# /opt/zextras/common/sbin/slapcat -F /opt/zextras/data/ldap/config -b "" -H ldap:///???(&(!(entryDN:dnSubTreeMatch:=cn=zimbra))) > /opt/zextras/backup/provisioning.ldif

And later you can upload the LDAP data using slapadd (/opt/zextras/common/sbin/slapadd)

 

But thanks for your contribution to our community 🙏

 

Regards,

Sharif


   
ReplyQuote
(@raystinger)
Joined: 8 months ago
Posts: 37
Topic starter  

@sharif yes i will try to help others base on my knowledge since im handled zimbra

from zero to hero always practice and backup its must for prevent bad accident for any actions


   
ReplyQuote
(@sigtrap)
Joined: 1 year ago
Posts: 38
 

So will the scripts (zmprov/zmailbox and slapcat) also backup the contacts and calendar items including shared calendars?

How do you restore the backups taken with the two versions if you need to start from a clean installation?

//Sigtrap


   
ReplyQuote
(@raystinger)
Joined: 8 months ago
Posts: 37
Topic starter  

@sigtrap no , this is only backed up user mail (name details ) , user password , user inbox data and distribution group. i will try expand research for complete backup later


   
ReplyQuote
(@sigtrap)
Joined: 1 year ago
Posts: 38
 

After using your backup script, how do you restore the backup to a clean new Carbonio installation?


   
ReplyQuote
(@raystinger)
Joined: 8 months ago
Posts: 37
Topic starter  

@sigtrap 

 

just do and make sure the path correct 

 

#!/bin/bash
#Script for creating the email accounts createacct.sh

d=`date -d "yesterday" '+%d_%B_%Y'`

#hari ini

d="28_March_2024"

echo

$d

USERPASS="/home/carbonio_backup/user_mail_$d/password"
USERDATA="/home/carbonio_backup/user_mail_$d/account"
USERS="/home/carbonio_backup/user_mail_$d/emails.txt"
for i in `cat $USERS`
do
givenName=$(grep givenName: $USERDATA/$i.txt | cut -d ":" -f2)
displayName=$(grep displayName: $USERDATA/$i.txt | cut -d ":" -f2)
shadowpass=$(cat $USERPASS/$i.shadow)
tmpPass="CHANGEme"
carbonio prov ca $i CHANGEme cn "$givenName" displayName "$displayName" givenName "$givenName"
carbonio prov ma $i userPassword "$shadowpass"
done


   
sigtrap reacted
ReplyQuote