Bottom Line: If you’re a Pinboard user, you can automate backing up your bookmarks to Dropbox with cURL and launchd.
I’ve mentioned launchd in past posts a time… or two. It’s a behind-the-scenes program that lets you schedule stuff to happen at a given time (Sundays at 3 AM) or time interval (every 15 minutes) on your Mac.
I saw a post today by Marcelo Somers at behindcompanies.com that alerted me to a clever way to back up Pinboard using cURL. His method involves a web server ant IFTTT, and had a few issues with my special-character-containing password (courtesy of LastPass), so I decided to tinker with it a bit.
I was able to get it running great, including URL encoding the password, with the script below. Anything with square brackets means you need to fill in your info there (and omit the square brackets).
#!/bin/bash # Original post at http://n8henrie.com/2012/12/pinboard-backups-with-curl-and-launchd/ curl -k -u "[username]:[password]" "https://api.pinboard.in/v1/posts/all?format=json" -o "/Users/[username]/Dropbox/[pathToBackup]/[filename].json"
I named the script pinboardBackup.sh (which you’ll see in the .plist). Don’t forget to chmod +x to make it executable.
I have it set to be run by launchd every night at 3 AM with this (again, fix the part with square brackets):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <!-- Original post at http://n8henrie.com/2012/12/pinboard-backups-with-curl-and-launchd/ --> <dict> <key>Label</key> <string>com.n8henrie.pinboardBackup</string> <key>ProgramArguments</key> <array> <string>/Users/[username]/Dropbox/[pathToScript]/pinboardBackup.sh</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>03</integer> <key>Minute</key> <integer>00</integer> </dict> </dict> </plist>
All together, this will download the backup in JSON format and put it in a Dropbox folder for me. I have Hazel manage the backups to make sure I don’t get overwhelmed with too many. I will probably decrease the interval to weekly pretty soon, I think daily is a bit much.
Thanks for keeping the comments and questions below (instead of via email) so that everyone can benefit from discussion.