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.

List directories with php and compare them

Sometimes it’s important to quickly highlight differences between two folders structure.

It could happen expecially when you are obliged to work on cheap environments, without console and you need to understand if there are differences among your local filesystem and the remote one.


$dir = __DIR__;
$scan_result = scandir( $dir );
foreach ( $scan_result as $key => $value ) {
  if (!in_array($value, array('.', '..'))) {
    if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) {
      print $value."<br/>";

You can copy the script in each directory and naming it scandir.php, than reach it by browser at the url http://path-to-your-base-folder/scandir.php.

In this way you have just executed the script, do it on each environment directory and occasionally compare them.

To compare there are Notepad++, git diff, WinMerge and plenty of open source tools.

Scandir is a php function, check it, I have wrote this code using an example I found there.