chrispooledotcom

How to Backup Your Instapaper Links

01 June 2011

Reader beware: this article is a bit old!

Instapaper saves interesting articles you come across, so you can read them at a later date. Best of all, there’s a nice iPhone and iPad client, making reading longer articles a pleasure.

Here’s how to backup your links on a unix-like system (including Mac OS X):

#!/bin/bash -

username='john@example.com'
password='hunter2'
form_key=df7dfg7dfg7df89g
backup_dir="$HOME/"

cookies=cookies.txt
login_page='https://www.instapaper.com/user/login'
export_page='https://www.instapaper.com/export/html'

printf "Backing up Instapaper... "

curl -s -d "username=$username&password=$password" \
    $login_page -c $cookies > /dev/null 2>&1

curl -s -b $cookies -d "form_key=$form_key" $export_page \
    -c $cookies | bzip2 -c > \
    "$backup_dir"/instapaper-`date "+%Y%m%d%H%M"`.htm.bz2

if [[ -f $cookies ]]; then
    rm $cookies;
fi

# Remove Instapaper backup files older than 14 days
find "$backup_dir" -name 'instapaper-*.htm.bz2' -type f \
    -mtime +14 -maxdepth 1 -print0 | xargs -0I{} rm {}

printf "Done.\n"

Add your username and password, and then in your browser, view the source code to your Instapaper page, and search for form_key. It’ll have some strange value like the above. Replace the dummy value in the script with the value for your form_key.

Usage

Once this script is in an executable file, it can be called (manually or by cron or similar) to create a compressed backup file (currently in $HOME/). Backups older than 14 days will also get removed.