Exporting Confluence Wiki to Static HTML

As part of our general backup/DR strategy, we thought it would be nice to have a static copy our our wiki living on another machine. The wiki contains a lot of important info that would be inaccessible in the event of say, a DB crash, info that just might be helpful in resolving said crash.

Anyway, Bob Swift was kind enough to write Confluence CLI, the command line interface to Confluence. However, it’s still pretty much limited to functions already defined in Confluence, e.g. Can only export one space at a time, etc. The following quickly hacked script gets the list of space names, loops through and exports them, then unzips them to their new apache home:

#!/bin/sh
# REQUIRES: Confluence CLI

## edit these
TARGET_DIR="/usr/local/www/wiki"
OUT_DIR="/usr/local/ccli/out"
CCLI_DIR="/usr/local/ccli/confluence-cli-2.0.0"
JAVA_HOME="/usr/local/java"
PATH=$PATH:/usr/local/bin
##
export JAVA_HOME
export PATH

TFILE="asdf.$$.txt"
$CCLI_DIR/confluence.sh --action getSpaceList > $TFILE
THINGY=`awk '{if (NR > 2) {print $1}}' $TFILE`


for THG in $THINGY; do
THG=$(echo ${THG%\,})

($CCLI_DIR/confluence.sh -v --action exportSpace --space "$THG" --exportType HTML --file "$OUT_DIR/$THG.zip")
unzip -o $OUT_DIR/$THG.zip -d $TARGET_DIR
done

rm $TFILE