Dump calendars from Zimbra command line

An easy php snippet to produce the commands necessary to backup Zimbra calendars

Recently I bumped into a migration from Zimbra to another mail system provider; this migration regarded all accounts including, of course, them calendars, contacts and task.

We decided to use a tool named Transend that was among the suggested by AWS support, but for non interesting reasons, we also needed to get the calendars out of Zimbra.

Via zimbra cli it is very easy to do that:

/opt/zimbra/bin/zmmailbox -z -m [email protected] getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/youremail.ics

But … I had a lot accounts to care about, nevertheless I am normally very lazy in repeating dummy commands.
So I decided to write this little PHP snippet to produce the rows I need and than copy and past the result on zimbra cli.

The Script

Take a look at the following example with 4 accounts:

<?php

/**
 * You can of course use a simpler array,
 * but the file name with a @ is not the best you can have in your life.
 *  
 * */
$accounts = [
'peter.pan'=>'[email protected]',
'bruce.banner'=>'[email protected]',
'clark.kent'=>'[email protected]',
'mario.merola'=>'[email protected]',
];

foreach($accounts as $account => $email){
	echo "/opt/zimbra/bin/zmmailbox -z -m $email getRestURL \"/Calendar/?fmt=ics\" > /tmp/Calendars/$account.ics" . "\n";
}

the result will be:

/opt/zimbra/bin/zmmailbox -z -m [email protected] getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/peter.pan.ics
/opt/zimbra/bin/zmmailbox -z -m [email protected] getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/bruce.banner.ics
/opt/zimbra/bin/zmmailbox -z -m [email protected] getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/clark.kent.ics
/opt/zimbra/bin/zmmailbox -z -m [email protected] getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/mario.merola.ics

Now I am ready to copy and paste those lines on my Zimbra terminal and say “have a good week-end!” to the world.