How can I migrate to DAViCal using already generated .ics files?

If you can export your current user calendars to several iCalendar files, then migrating to DAViCal should be fairly easy.

Importing .ics Files into DAViCal using the import tool
The tools section in the admin web interface provides an easy to use tool for importing existing .ics-files. To use it, create a directory on your server where the .ics files will reside. Each .ics file should be named according to the person's username in DAViCal with the '.ics' suffix, so if the username was 'andrew' then the filename would be 'andrew.ics' and so forth.

Once that directory is populated with the .ics files, enter the server path into the screen and a name for the created calendars and click 'Submit'. Calendars will be imported into the path ".../caldav.php/username/calendarname/". For example if you chose the path to store your ics as "schedule" then the path for andrew's new calendar will be  http://davical.example.net/caldav.php/andrew/schedule/  and so forth.

Importing .ics Files manually
If for some reason you cannot use the provided tool, it's also possible to go through the import process manually. It requires more steps and you'll most likely need some scripting skills but it's really not that complicated.

Enable full collection writing in DAViCal
You have to set the following options in your DAViCal configuration file:

$c->readonly_webdav_collections = FALSE; $c->writable_dav_collections = TRUE;

Create an administrative account
Use the default admin user or create a new one with 'Administrator' flag. It will be used to create every single calendar.

Import the calendars
We will use curl to add our existing calendars.

I have used the following script to batch the neccessary curl commands. It expects the following tree structure:

exported_calendars/ ├── aacal │   └── aacal.ics ├── agenda1 │   ├── agenda1:Agenda1Prueba.ics │   └── agenda1.ics ...


 * 1) !/bin/bash

URLBASE=http://davical_host/caldav.php USR_ADMIN=admin_user PASSWORD_ADMIN=admin_passwd

if [ ! -d exported_calendars/ ]; then echo "Missing exported_calendars/" exit 1 fi
 * 1) Exported files

find exported_calendars/ -name *.ics | while read i; do       # Format: # exported_calendars/user/name.ics USR=`echo "$i"|cut -f 2 -d '/'` CALENDAR_NAME=`echo "$i"|cut -f 3 -d '/'|sed 's_\.ics$__g'`

# Default calendar is 'home' (change it here) # Other calendars (user:xxx) get translated into 'xxx' EXPSIMPLE=s/^${USR}\$/home/g CALENDAR_NAME=`echo "$CALENDAR_NAME"|sed "$EXPSIMPLE"|sed 's_^.*:\(.*\)$_\1_g'`

echo DEBUG \[$i\] $USR, $CALENDAR_NAME >&2

# Use cURL URL=${URLBASE}/${USR}/${CALENDAR_NAME}/ curl --insecure --basic --request PUT --header \ "Content-Type: text/calendar; charset=utf-8" \ -u ${USR_ADMIN}:${PASSWORD_ADMIN} \ --data-binary @${i} \ $URL if [ $? -ne 0 ]; then echo ERROR with user $USR, calendar $CALENDAR_NAME >&2 fi done

This way every calendar gets put on caldav.php/username/calendar_name.

Disable full collection writing in DAViCal
Set previously changed settings about DAV collections to default values:

$c->readonly_webdav_collections = TRUE; $c->writable_dav_collections = FALSE;

Fixing collection user assignation
If your users were not created/synchronized before the calendar import proccess, then your DAV collections lack the user_no column on DB, so those collections are not associated to the users. This can be seen in DAViCal interface on each user, which has associated no collections. Although users can access their own collections, some calendar clients such as iCal or Sunbird don't behave correctly with this situation.

When you have all your users created (they logged in for the first time and they got created, or you just launched a synchronization) then you can use the following commands to launch an SQL query to correct all the user_no NULL values. SQL query by courtesy of karora:

$ psql davical \ -c "UPDATE collection SET user_no = (SELECT user_no FROM usr WHERE username = substring(parent_container,2,length(parent_container)-2)) WHERE user_no IS NULL;""
 * 1) su postgres

After that, every collection should be associated to its owner.

Exporting iCalendar files from your current system
The procedure for exporting your existing calendars depend on your current calendar system. If you have the feeling the procedure for your particular system should be part of this page, please contact the mailing list for wiki write access.

Sun Java Enterprise System
Exporting from JES is really easy. The utility cscal lists current users and calendars, and csexport lets you export an specific calendar.

You can use the following script:


 * 1) !/bin/bash

EXECUTABLESDIR=/calendar/opt/SUNWics5/cal/lib OUTPUTDIR=/exported_calendars

UMASKINITIAL=`umask`

umask 000
 * 1) csexport exports calendars using 'icsuser' as the user
 * 2) Let him write on /exported_calendars

cd $EXECUTABLESDIR mkdir -p $OUTPUTDIR


 * 1) cscal output is as follows:
 * 2)  perula: owner=perula status=enabled
 * 3) We sort it to make it easier to generate directories
 * 1) We sort it to make it easier to generate directories
 * 1) We sort it to make it easier to generate directories

$EXECUTABLESDIR/cscal list |awk '{print $2, $1, $3}'|sed 's_^owner=__g'|sort> $OUTPUTDIR/calendar-list

cat $OUTPUTDIR/calendar-list | while read i; do       CURRENT_USER=`echo "$i"|awk '{print $1}'`
 * 1) Let's create a directory for each user, and his/her calendars will be
 * 2) exported inside it

# Remove trailing ':' from main calendars # Additional calendars are not affected by this CURRENT_CALENDAR=`echo "$i"|awk '{print $2}'|sed 's_:$__g'`

# Create user directory and export calendar mkdir -p $OUTPUTDIR/$CURRENT_USER $EXECUTABLESDIR/csexport -c $CURRENT_CALENDAR calendar \ $OUTPUTDIR/$CURRENT_USER/${CURRENT_CALENDAR}.ics done

umask $UMASKINITIAL

This will generate a /exported_calendars directory (name by default) with the following tree structure:

exported_calendars/ ├── aacal │   └── aacal.ics ├── agenda1 │   ├── agenda1:Agenda1Prueba.ics │   └── agenda1.ics ...