Pages

Saturday, 2 November 2013

Backing up Google Calendar

The same thing applies as it did with mail. If your calendar is important to you (and it is to ladysolly), then having it in one place just isn't good enough. The fact that you can access that one place via several devices, doesn't make it much safer. If Google accidentally deletes your calendar (or if you do), you're stuffed. There has to be a copy elsewhere. Here's how.

First, sign in to Google, and go to their Calendar app.  On the left, you'll see "My calendars" and under that, your name, such as ladysolly. Hover the mouse over the name, and you'll see a link for a drop-down box, on that drop-down, click on "Calendar Settings".

Near the bottom, you'll see "Private address". Click on the red "XML" link and a box will pop up with a long address that starts with https and ends with basic. Copy and paste that address into a text editor. Do the same with the green "ICAL" link, that ends with basic.ics.

ICAL is a format that can be fed straight into  many calendar apps. XML is an even more generic file format. I'm backing up both. ICAL is better if you're using one of the apps that recognises it, XML is more generic.

Now go to your linux computer. If you don't have a linux computer, I'm sure that you can get Windows or Macs to do the same thing, but I have no idea how. Do this:


wget https://address-you-just-got-above/basic

Your computer will go and get the file. You can look at the file if you want,

So now, we want to set up an automated backup system. I wrote the following program, which I called calendar.pl.


#!/usr/bin/perl
$epoch = time;
`wget https://address-you-just-got-above/basic.ics`;
`wget https://address-you-just-got-above/basic`;
rename "basic.ics", "/home/ladysolly/calendar/basic.ics.$epoch";
rename "basic", "/home/ladysolly/calendar/basic.$epoch";
exit;

And set the permissions to 755 with chmod 755 calendar.pl

It's pretty obvious what that does. It gets the two files from Google, and renames then with a timestamp, so that when it fetches a file, that doesn't overwrite the old one. Why do that? Consider the following scenario - Google loses all your data, so you still have a calendar on Google, but it has nothing in it. Or maybe you do something that accidentally wipes it. Whatever - if you overwrite the previous file each time that you do a backup, then as soon as you back up that empty calendar, you no longer have a backup.

So then I make a file called crontab

25 05 * * * /home/ladysolly/calendar/calendar.pl

and I do crontab crontab

And now, every day at 5:25 am, ladysolly's calendar will be backed up to one of my servers.

Job done.

4 comments:

  1. I like the simplicity of this. Have attached a SATA drive to my Cubieboard (a Chinese Pi on steroids!) and will use this for my cloud backups. I agree with you - many people think of the cloud as a backup - I backup my dropbox directories to my home NAS regularly!

    BTW - to introduce myself, we met once - I was president of Oxford Brookes Computer Society and you were my first guest speaker and entertained the modest crowd assembled - thank you :-)

    ReplyDelete
  2. That must have been a long time ago!

    ReplyDelete
  3. I think around 1994 - wow - thinking about it some more - just shy of 20 years. And I was a (fairly) mature student then. Those halcyon days ...

    ReplyDelete
  4. Congratulations on starting your blog.

    I once tried out a web filtering product for someone who was thinking of selling it. So I installed it on my computer, and waited to see what would happen.

    The same day, I needed some nuts and bolts, so I went to Screwfix, a great place for getting such bits and bobs online.

    It blocked me.

    It didn't like the "screw" part of the name.

    Good luck with your webfilter. I suspect that what you're trying to do there is only possible in the vivid imagination of politicians forced to "do something" about "the internet".

    ReplyDelete