erikb

Prev Next TECH TECH
Tip: make a backup copy of your Google Calendar this [2008-10-19]

I bought a new mobile phone this week. I installed synchronization of the phone's calendar with my Google calendar. I use Goosync for this - a nice and free utility that works just fine.

In step 2 I synced my mobile with my contacts in Outlook. I use Outlook only for contacts, no email, no tasks, no calendar. What I didn't realize was that when the phone did this sync with Outlook it made a reset of the calendar (since the Outlook calendar was empty, of course).

In step 3 (a bit later) I did a sync of my phone using Goosync. I think you can see what this lead to: all of my Google Calendar was reset. For the sync service it looked like I had cancelled all my appointments in my mobile phone calendar and now wanted to update that fact to the main calendar. Oh man... there is no undo in Goosync, the phone or Google I can tell you.

Many ugly words later I sat down and made a small script that downloads my Google Calendar to my computer and rotates a log of old backups. Use it if you like. If you use an online calendar as your only calendar you do need some kind of backup. There are more ways than I described to loose your calendar entries.

For this script to work you need access to (unix) shell commands and the wget command. If you use Linux everything is probably already there. If you use Windows you might look into installing Cygwin. I scheduled this script to run each morning using crontab. The same can be done on Windows using the builtin scheduler.

#!/bin/bash
# make sure wget is on your path
PATH=$PATH:/it/sw/gnu/bin/

# EDIT: how many previous versions to keep
NUMBACKUP=9
# EDIT: the backup files are saved in this folder
DIR=/home/erikb/private/cal
# EDIT: URL to your calendar (ICS version), look in your settings at Google
URL=http://www.google.com/calendar/ical/USERNAME%40gmail.com/public/basic.ics
# name of file when downloaded, given by the URL above
TMP=basic.ics
# filename for saved backups
PRE=gcal.ics

### Enough settings, do the backup thing now

# goto backup folder
cd $DIR
# clean up old stuff, just in case
rm -f $TMP
# shift backups
COUNTER=$NUMBACKUP
while [  $COUNTER -gt 0 ]; do
    let i=$COUNTER-1
    mv -f $i.$PRE $COUNTER.$PRE 
    echo "mv -f $i.$PRE $COUNTER.$PRE"
    let COUNTER=COUNTER-1 
done

# download calendar
wget $URL
# rename file
mv -f $TMP 0.$PRE
# clean up, just in case
rm -f $TMP
Prev Next