Backing up your del.icio.us bookmarks

Triggered by recent events, I’ve written a little script that backs up my del.icio.us bookmarks to my local disk. It’s a Ruby script and runs only on Unix systems such as Mac OS X.

When run, it will do this:

  • Call the del.icio.us API to check if your bookmarks have been updated,
  • if there are new posts, fetch them using the API,
  • store them as a timestamped, gzipped XML file in the directory where the script runs.

My system runs this automatically every hour, using a cronjob. To set up a cronjob, open the Terminal, enter crontab -e, and enter something like this:

43 * * /Users/richard/delicious-backups/delicious-backup.rb

This will run the script 43 minutes after every full hour, if the computer is on.

Here’s the script, delicious-backup.rb. Replace username and password.

#!/usr/bin/ruby
user = "username"
pw = "password"
header = "User-Agent: delicious-backup.rb"
api_url = "https://api.del.icio.us/v1/posts"
script = $0
update_xml = `curl -u #{user}:#{pw} -H "#{header}" #{api_url}/update`
exit 1 unless update_xml =~ /"(\d\d\d\d-\d\d-\d\dT.*?)"/
file = File.dirname(script) + "/" + $1.gsub(/:/, '') + ".xml.gz"
exit 0 if FileTest.exist? file
sleep 2
curl_cmd = "curl -u #{user}:#{pw} -H \"#{header}\" #{api_url}/all"
exit 1 unless system "#{curl_cmd} | gzip > #{file}"

I note that the design of the del.icio.us API made this extremely simple and quite pleasant. RESTful APIs are elegant.

This entry was posted in General. Bookmark the permalink.

1 Response to Backing up your del.icio.us bookmarks

  1. MUslar says:

    Great, works absolutely flawles after realizing ruby was not in my path ,-)

Comments are closed.