Friday, April 2, 2010

Groovy Google Sites Backup

I've recently started using the Google Apps version of Google Sites to augment my church's website with subsites that are easy to farm out to people with a passion for particular areas of our church's ministry. 

The one problem with using Google Sites (as opposed to an old-school FTP site) is that there is no backup.  While Google obviously has a good reputation, it still makes me a bit nervous to be without any kind of backup.  I discovered the Google Sites Liberation tool, which allows you to export your sites.  It is part of a larger effort by a team of Google engineers to make sure Google users have free access to their data.

Google Sites Liberation (GSL) is available as a Java JAR file download which you can run as a GUI application.  However, I wanted to automate the backups, so I wrote a Groovy script to call GSL.  Here is my very simple script, BackupGoogleSites.groovy:

import java.text.SimpleDateFormat

 * Back up the various Google Sites for FEFC
 * User: Jeff Olson (
 * Date: Dec 18, 2009
def sites = [

String backupDir = /C:\Backup\FFC Website Backup\Google Sites/
def username = 'your_username_here'
def password = 'your_password_here'
def host = ''
def domain = ''

SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd")
def today = df.format(new Date())

sites.each { site ->
  def location = "$backupDir/$today/$site" as String
  println "\n\nBacking up $site for $today to $location\n"

  def args = ['-h', host, '-d', domain, '-w', site, '-u', username, '-p', password, '-f', location]

  // hack because ABF site fails when getting all revisions for some reason
  if (site != 'abf') {
    args << '-r'

  Main.main(args as String[])

To use this, just fill in your list of sites, the backup directory, username & password, host, and domain (if using Google Apps for your domain). The script will create a new subdirectory for each day and put each site into a subdirectory under that.

The "hack" for the 'abf' site is due to a so-far unexplained NullPointerException I get when trying to export all revisions that site, so I disabled the -r option for that one.

To run this Groovy script, I created a short batch file (yes, I'm running on Windows XP):

groovy -cp lib\google-sites-liberation-1.0.3.jar src\BackupGoogleSites.groovy

Oh, if you try this and your system complains it can't find 'groovy', you'll need to install the latest version of Groovy.


  1. How nice of you to create this script.

  2. Hvad søren er du dansker, eller har dansk rødder.

  3. Klaus, neither, actually! I am a fourth-generation Norwegian & Swedish-American (and unfortunately, I don't know either of those languages). And I cheated on the Danish greeting to you by using Google Translate! :)


Note: Only a member of this blog may post a comment.