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 yourmail@example.com 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:


 * 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 = [

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 peter.pan@example.com getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/peter.pan.ics
/opt/zimbra/bin/zmmailbox -z -m bruce.banner@example.com getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/bruce.banner.ics
/opt/zimbra/bin/zmmailbox -z -m clark.kent@example.com getRestURL "/Calendar/?fmt=ics" > /tmp/Calendars/clark.kent.ics
/opt/zimbra/bin/zmmailbox -z -m mario.merola@example.com 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.