Hello all,

In case anyone is interested, I've attached a small python script which will backup all calendars (excluding externally subscribed .ics calendars) for Zimbra users. We use this to keep backups of calendars for longer periods of time than our actual mail backups (since the calendar backups are relatively small).

I'm not a professional programmer and there may be a better way of doing this, but this works pretty well for us. Its currently setup for Zimbra version 6.0.5 and I do not know how or if it will need to be modified for future versions.

The 'zimbrausers.txt' file is just a list of all accounts on a Zimbra system (including domain name)


import os
from time import strftime

# Open the list of Zimbra users and read it into a list
userfile = open("/opt/zimbra/accountlists/zimbrausers.txt",'r')
userlist = userfile.readlines()


# Set the current date - used to create and set the backup destination directory
cur_date = strftime("%Y-%m-%d")
backupdir = "/zimbra-backups/calendar-backups/" + cur_date
os.system("mkdir " + backupdir)

# Go through each user in the userlist
for user in userlist:
# The account name is obtained by dropping the \n at the end of each line
cur_account = user[:-1]
# The username is obtained by dropping the @ sign and anything after from each line and is used for the backup file name.
cur_user = user.split('@')[0]

# Assemble the command to get the list of all users calendar folders
# Exclude external folders on another account (thus excluding lines with @)
# Exclude externally subscribed .ics files
command = "zmmailbox -z -m " + cur_account + " gaf | grep -i appo | grep -v '\@' | grep -v .ics"

# Execute the command, read the output into a list
output = os.popen(command).readlines()

# For each entry in the list, split out the calendars, if they exist
for line in output:
calendar_name = line.split("/")[1][:-1]

command = "zmmailbox -z -m " + cur_account + " getRestURL /\"" + calendar_name + "\" > \"" + backupdir + "/" + cur_user + "-" + calendar_name + ".ics\""

command2 = "bzip2 \"" + backupdir + "/" + cur_user + "-" + calendar_name + ".ics\""