Print Friendly

In my continuing quest to use Google Apps as best I can, I’ve been reading up on the Google Blogger API.

I thought that automatically backing up a blog on Blogger would be easy, but it turned out to be a more complex script that I had originally thought.

Authentication was the part that I was missing. Using curl, I can acquire the authentication information like so:

curl https://www.google.com/accounts/ClientLogin -s -d Email=smj@littleprojects.org -d Passwd=mypassword -d accountType=GOOGLE -d source=blog-backup -d service=blogger

From this line, you get output like so:

012345678902234567890323456789042345678905234567890623456789072345678908234567890
SID=DQAAAHYBADCv2pSv7nflacDNwz3zEDUGtrSvNVDcpkSfddi77b3U5sEaHmP8YLWhmA36F9rk85mL
8J5dqo4apn0T1vKz0fPGI9Xtnuet6cuE2ZzYvrNIwbSC_HjTqF4zudNQnnlDuD2wqZT-g1qXI8KhGAQZV4NexHZoQPlabTsGuRZeIBxj1ALSID=EUBBBIaBADCl-kNxvRVmcQghpt3cqSMfEooKR9flLOUZqwgP9OrZS83gse-KSdTNeXhxsET7FYenDhceP9lIPOmesH-t9qh-AWUHjjMdZEbUNeF9mWyzln6Z-FajaiG-cVFkqW0ZJ8ZbnCP30xXj6xFK6QxaAcqy_9Pej8jhEnxS9E61ftQGPgAuth=EUBBIacAAADK-kNxvRVmcQghpt3cqSMfEooLNMflLNIQqwgP9OrZS83gs-KSdTNeXhxsET7FYePWmaD8Vsy1V4LSUGMUP48Je2TO8OcjBj6HgAtPhiZeX-gKDfagZDK44j4n-Tkb44nhOnp2_QPSnBj3Z2vYwOEDjjG3Q53aQVC2132JKOuGh

The line we’re interested in is the one starting with “Auth=”. This is what we will use to authenticate to blogger so that we can grab our blog backup.

Part two consists of downloading the XML backup of all of your posts.

I knew that I could go to the following URL to get a backup of my blog posts:
http://www.blogger.com/feeds/blogid/archive

where I fill in blogid with the blogID supplied by your URL on Blogger. For example, as I type this, the URL in the address bar is

http://www.blogger.com/post-create.g?blogID=6964696676319111700&postID=8574983142196621787

which tells me that my blogID is 6964696676319111700.

So, to download the blog backup, I use the following URL:
http://www.blogger.com/feeds/6964696676319111700/archive

With the use of the tool curl and some Bourne Shell scripting, the following script can be used to automatically download my XML file containing a backup of my blog from Blogger.

#!/bin/sh
 
# Authentication and authorization
export Auth=`curl https://www.google.com/accounts/ClientLogin -s -d Email=smj@littleprojects.org -d Passwd=mypassword -d accountType=GOOGLE -d source=blog-backup -d service=blogger | grep "Auth="`
 
# Get the xml file and store it into blog-backup.xml
curl -H "Authorization: GoogleLogin ${Auth}" "http://www.blogger.com/feeds/6964696676319111700/archive" &gt; blog-backup.xml<span style="font-size: 85%;">

Now I set cron to run this script once a week and I will have a backup of my blog entries should something horrible befall blogger; or I choose another blogging service.

References: