Thursday 28 July 2016

How to Backup and Restore El Capitan Calendar Server (caldav)

With Server 5.1, the socket location to connect to the caldav database changed.

Make sure Calendar Server is switched OFF for this whole procedure....

sudo serveradmin stop calendar

To backup your existing calendar database...

/Applications/Server.app/Contents/ServerRoot/usr/bin/pg_dump -h /var/run/caldavd/PostgresSocket/ -U caldav caldav -c -f ~/Desktop/caldav.sql

To restore it, you may first want to drop the existing database...

sudo dropdb -h /var/run/caldavd/PostgresSocket -U caldav caldav

then create a new one...

sudo createdb -h /var/run/caldavd/PostgresSocket -U caldav caldav

Then import the backup you made at the start....

sudo cat caldav.sql | sudo psql -h /var/run/caldavd/PostgresSocket -U caldav caldav

Now you can start the service again...

sudo serveradmin start calendar

NOTE: If you receive an error using DROPDB about the database being accessed by other users, try this..

Manually connect to psql...

sudo psql -h /var/run/caldavd/PostgresSocket -U caldav caldav

Find and kick all active connections..

SELECT
 pg_terminate_backend (pg_stat_activity.pid)
FROM
 pg_stat_activity
WHERE

 pg_stat_activity.datname = 'target_database';

Quit PSQL...

\q

Then try the dropdb again...

sudo dropdb -h /var/run/caldavd/PostgresSocket -U caldav caldav



No comments:

Post a Comment