Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-2010, 07:01 AM
Advanced Member
 
Posts: 178
Default Script to backup all Zimbra calendars

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)

Quote:
#!/usr/bin/python

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()

userfile.close()

# 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\""
os.system(command)

command2 = "bzip2 \"" + backupdir + "/" + cur_user + "-" + calendar_name + ".ics\""
os.system(command2)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.