How to Export and Import Calendar, Contacts, and Tasks in Zimbra (Single & Bulk Users)

Looking to migrate to ZCS? Ask here. Got a great tip or script that helped you migrate? Post it here.
Post Reply
hashir
Posts: 2
Joined: Thu May 29, 2025 6:07 pm

How to Export and Import Calendar, Contacts, and Tasks in Zimbra (Single & Bulk Users)

Post by hashir »

Single User Export

Old Server:

Code: Select all

$ zmmailbox -z -m hashir@domain.com getRestURL 'Calendar/?fmt=tgz' > /tmp/hashir-calendar.tgz
$ zmmailbox -z -m hashir@domain.com getRestURL 'Contacts/?fmt=tgz' > /tmp/hashir-contacts.tgz
$ zmmailbox -z -m hashir@domain.com getRestURL 'Tasks/?fmt=tgz' > /tmp/hashir-tasks.tgz
$ zmmailbox -z -m hashir@domain.com getRestURL 'Emailed Contacts/?fmt=tgz' > /tmp/hashir-emailcontacts.tgz
Copy the Calendar, Contacts, and Tasks file to the new server

Code: Select all

# scp /tmp/hashir-calendar.tgz /tmp/hashir-contacts.tgz /tmp/hashir-tasks.tgz /tmp/hashir-emailcontacts.tgz root@<new_server_ip>:/tmp/
Single User Import

New Server:

Code: Select all

# chown zimbra:zimbra /tmp/hashir-calendar.tgz /tmp/hashir-contacts.tgz /tmp/hashir-emailcontacts.tgz /tmp/hashir-tasks.tgz
# su - zimbra
$ zmmailbox -z -m hashir@domain.com postRestURL "//?fmt=tgz&resolve=skip" /tmp/hashir-calendar.tgz
$ zmmailbox -z -m hashir@domain.com postRestURL "//?fmt=tgz&resolve=skip" /tmp/hashir-contacts.tgz
$ zmmailbox -z -m hashir@domain.com postRestURL "//?fmt=tgz&resolve=skip" /tmp/hashir-emailcontacts.tgz
$ zmmailbox -z -m hashir@domain.com postRestURL "//?fmt=tgz&resolve=skip" /tmp/hashir-tasks.tgz
Empty a Folder Before Import (if needed)

Code: Select all

$ zmmailbox -z -m hashir@domain.com gaf | grep Calendar
$ zmmailbox -z -m hashir@domain.com ef /Calendar
$ zmmailbox -z -m hashir@domain.com ef /Emailed\ Contacts
-----------------------------------------------------------------------------------------------------------------

Bulk Users Export:

Old Server:

Create a folder for exports:

Code: Select all

# mkdir /tmp/all-users_calendars
Export all users’ calendars (skipping system accounts):

Code: Select all

$ for accts in $(zmprov -l gaa | grep -Ev "^(galsync|spam|ham|virus)"); do echo "Exporting account $accts"; zmmailbox -z -m $accts getRestURL 'Calendar/?fmt=tgz' > /tmp/all-users_calendars/$accts.tgz && echo "$accts Exported"
done
Copy only non-empty calendar exports:

Code: Select all

# mkdir /tmp/users_calendars
# find /tmp/ -name "*.tgz" -size +0k -exec cp {} users_calendars/ \;
Get list of accounts with non-empty calendars:

Code: Select all

# ls /tmp/all-users_calendars/ | sed 's/.tgz//g' >> all_calenders_accounts.txt
Transfer the exported files and account names to the new server:

Code: Select all

# scp -rv /tmp/users_calendars /tmp/all_calenders_accounts.txt root@<new_server_ip>:/tmp/
Bulk Users Import :

New Server:

Set correct permissions:

Code: Select all

# chown -R zimbra:zimbra /tmp/users_calendars
# chown zimbra:zimbra /tmp/all_calenders_accounts.txt


Import all user calendars:

Code: Select all

$ for accts in $(cat /tmp/all_calenders_accounts.txt); do echo "importing $accts"; zmmailbox -z -m $accts postRestURL "//?fmt=tgz&resolve=skip" /tmp/all-users_calendars/$accts.tgz; done
Similarly follow the same steps for Contacts and Tasks.
Post Reply