# restore a old zimbra snapshot, get its public IP and ssh to it.
# On Old Mail Server

## links: https://www.thegeekdiary.com/how-to-take-mailbox-backup-of-zimbra-account-from-cli/
## links https://nwildner.com/posts/2019-09-27-zimbra-cli-tips/

# ……………………………………………………………

## You may want to install a self signed cert if the restored image is older (ssl expired)
## Links: http://www.snapshotsofthemind.com/how-to-fix-annoying-zimbra-certificate-error-after-domain-name-change/

 # 1. Create and deploy selsigned certificate – Run under root account:

    /opt/zimbra/bin/zmcertmgr createca -new

    /opt/zimbra/bin/zmcertmgr deployca

    /opt/zimbra/bin/zmcertmgr createcrt -new -days 365

    /opt/zimbra/bin/zmcertmgr deploycrt self

# 2. Verify Deployed certificate:

    /opt/zimbra/bin/zmcertmgr viewdeployedcrt

# 3. Restart Zimbra – run under zimbra account:

    su – zimbra

    zmcontrol restart
# ……………………………………………………………

## Create a backul location accessible by zimbra
sudo su
mkdir -p /opt/zimbra/mail_backup
chmod 777 -R /opt/zimbra/mail_backup
chown zimbra:zimbra -R /opt/zimbra/mail_backup

## login as zimbra
su zimbra

## backup email
zmmailbox -z -m thilinat@sysdek.com getRestURL “//?fmt=tgz” > /opt/zimbra/mail_backup/thilinat@sysdek.com.tar.gz

# the above command wil take time, run “du -h /opt/zimbra/mail_backup/” from a new terminal to see the growth.
# chech disk space with “df -h” from time to time. the backup may consume the disk capacity in full.

## backup contacts
zmmailbox -z -m thilinat@sysdek.com getRestUrl “//?fmt=csv&query=under:Contacts” > /opt/zimbra/mail_backup/thilinat_contacts.csv

# on local PC

## Download backup
scp -i /home/ashain/Downloads/temp/ssh-keys/sysdek_servers.pem ubuntu@35.90.130.176:/opt/zimbra/mail_backup/thilinat@sysdek.com.tar.gz ~/Downloads

## Download CSV
scp -i /home/ashain/Downloads/temp/ssh-keys/sysdek_servers.pem ubuntu@35.90.130.176:/opt/zimbra/mail_backup/thilinat_contacts.csv ~/Downloads

# On Old Mail Server
## Import Backup
zmmailbox -z -m thilinat@sysdek.com postRestURL “//?fmt=tgz&resolve=reset” /mail_backup/thilinat@sysdek.com.tar.gz