Automatic Delicious Backups Under Leopard ¬
2009-01-26
I’ve been using delicious.com, nee del.icio.us, for my bookmarks on and off since early 2006, but only recently have I decided to really keep all my bookmarks there. Yahoo!‘s future has been somewhat questionable as of late and I’m not entirely sure I like the idea of not having my data backed up in a place where I can get at if the service goes down. I don’t really have control over the former, but the latter I do.
Delicious has a tool to export your bookmarks that gives you an HTML bookmark file for easy importing into a browser, but, alas, it’s not really scriptable. However, they do offer a way to dump all your bookmarks to xml using their API.
So, I whipped up the following bash
script to perform the backup and tossed it in ~/bin/deliciousBackup
:
#!/bin/bash
# # deliciousBackup - delicious.com bookmarks backup # # See: http://delicious.com/help/api#posts_all # # v0.1 2009-01-25 - Morgan Aldridge <morgant@makkintosshu.com> # Initial version. #
user='<username>' pass='<password>' date=`date "+%Y-%m-%d"` src='https://api.del.icio.us/v1/posts/all' dst='Users/<username>/Documents/Backups'
curl -s --user $user:$pass $src | bzip2 > $dst/delicious.com-$user-$date.xml.bz2
I needed to make deliciousBackup
executable, but also wanted to make sure it wasn’t readable by any other user/group since it contains my password in plain text:
chmod 700 ~/bin/deliciousBackup
Of course, if someone ever had direct access to my hard drive they could still pull my Delicious password from that file, so consider yourself warned.
I prefer to run most of my backup scripts and such using launchd
instead of cron
since it follows my home folder sync better, so I tossed the following .plist in ~/Library/LaunchAgents/com.makkintosshu.deliciousBackup-morgant.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string><tld>.<domain>.delciousBackup-<user></string>
<key>ProgramArguments</key>
<array>
<string>/Users/<user>/bin/deliciousBackup</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>12</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
The following call loaded my LaunchAgent without a logout:
launchctl load ~/Library/LaunchAgents/com.makkintosshu.deliciousBackup-morgant.plist
You’ll note that the LaunchAgent runs every day at noon. That’s because I currently run this on my MacBook Air which may not be online most nights, but is usually online by mid-day.
Feel free to use this method if you’re so inclined.