Deli.cio.us bookmark backups via the shell

2 minute read

I had one of those weird little sinking feelings this morning as I looked at my friends’ facebook feeds. One of my friends, AG had been keeping his bookmarking on magnolia, which apparently suffered a major outage today and took some of his precious bookmarking with him. When I checked at time of posting the service was still down and they say they’ve got data corruption and loss. Not good.

Little uh-oh moment right then, realizing that I had no backups of my delicious bookmarks which, ever since Yahoo released the fantastic Firefox delicious add-on, I’ve been using in-the-cloud bookmarking exclusively. I was suddenly recalling someone’s Stallman-esque blog rant about how the cloud was all fine provided :

  1. Get your stuff out of the cloud service in a non-propreitary format (ok, check)
  2. Had it backed up consistently (hmmm…)

I’d sinned against the second.

Being me, some scripting off a cron job seemed like the best way to handle this. I don’t need an up to the minute backup or anything but making sure I have a disaster recovery somewhere (in case Yahoo gets bought by Microsoft or something and reliability and sanity goes out the window) is probably important.

Now delicious has a very nice API I know, since I can use it to suck down my recent bookmarks to the blog (though passed on that since it cluttered things up). A simple check showed I could use curl to grab all my bookmarks in XML format (with their tags and timestamps on hitting delicious) with a pretty simple command. I added in a date command for timestamping and :

1
curl -k --user username: -o delicious_bookmarks_$(date +"%d-%m-%Y-%H-%M-%S").xml -O 'https://api.del.icio.us/v1/posts/all'

So, from there, it’s a simple matter of throwing it into a shell script and having it fire off as a cron job and making sure I get a mail when it fires – in case something bad happens.

1
2
3
#!/bin/sh
cd /where/you/want/your/backups/to/go/
curl -k --user username:password -o delicious_bookmarks_backup_$(date +"%d-%m-%Y-%H-%M-%S").xml -O 'https://api.del.icio.us/v1/posts/all'

Um, remember to chmod the file to make it executable chmod u+x filename or it’s note going to execute when you call it.

Then just crontab -e and add a line pointing at the script to your crontab :

1
00 13 * * * /path/to/script/delicious_bookmarks_backup.sh 2>&1 | mail -s "Daily Delicious bookmarks backup" yourmail@someplace.eh

So, just in case you’re new to crontab, this cron entry fires this job off daily at 1PM local time, dates the xml backup and then fires off a mail to your account (if you’re like me and have a local postfix mail server running that you ssh tunnel to your main mail server). If you don’t want to do this on your local laptop as I do (mostly because I have an automated backup service which backs up to the cloud), you could also run the same cron job on a web server somewhere.

dev tools