Skip to main content

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"