2004-11-20

Blogger backup

So you're vain enough to have a blog. You're probably vain enough to want a backup of your words of wisdom. Here you go:

#!/usr/bin/ruby -w

if ARGV.length() != 1
print("usage: blogger-backup.rb <blog-name>\n")
exit(1)
end

blog_name=ARGV[0]
blog_uri="http://#{blog_name}.blogspot.com/"

print("Downloading #{blog_uri}...\n")
blog_content=`curl #{blog_uri}`

blog_content.split("\n").each() {
|line|
if line =~ /"(#{blog_uri}(\d+_\d+_\d+_\S+_archive\.html))"/
next_archive_uri=$1
next_filename=$2
system("curl -o #{next_filename} #{next_archive_uri}")
end
}

Note that each time this is run, it downloads each month of the blog from scratch. A kinder version might go back in time and stop when it finds one it's seen before, though that assumes you never update really old posts.

Update 2007-03-14: the version shown here is for "old" blogger; for a version that works with "new" blogger, and which also copes with images, download the salma-hayek library and check out bin/blogger-backup.rb, which will always be the latest version of this script.