Migrating Group Wiki Pages
Fri Jul 18, 2008 · 295 words

It's surprisingly difficult to transfer entire wikis between groups since it's not just a matter of copying static HTML files as I thought previously. Here's a rough sketch of the process. It worked for me, but might not for everyone.

# wikimove from to
SRC=$1; DST=$2
cd /Library/Collaboration/Groups

# Take a backup
cp -r $SRC $SRC.bak; cp -r $DST $DST.bak

# Transfer the old search indices
sqlite3 $SRC/wiki/index.db .dump | sed 's/groups\/$SRC\//groups\/$DST\//' | sqlite3 $DST/wiki/index.db
chown teamsserver $DST/wiki/index.db;
chmod 0750 $DST/wiki/index.db
sed 's/groups\/$SRC\//groups\/$DST\//' $SRC/extrainfo >> $DST/extrainfo

# Transfer the actual documents and metadata
mv $SRC/wiki/*.page $DST/wiki/
cd $DST/wiki
for p in *.page ; do sed -i '' 's/groups\/$SRC\//groups\/$DST\//g' $p/page.html; done
for p in *.page ; do sed -i '' 's/groups\/$SRC\//groups\/$DST\//g' $p/page.plist; done

Don't forget to clean those .bak directories or else wikid will not start due to permissions errors. You'll still have references to your old group wiki inside the revisions.db files which you can get rid of with:

for p in *.page ; 
    do sqlite3 $p/revisions.db .dump | sed 's/groups\/$SRC\//groups\/$DST\//g' > /tmp/revisions.sql
    rm $p/revisions.db
    sqlite3 $p/revisions.db < /tmp/revisions.sql
done

srm /tmp/revisions.sql

Disaster recovery

If you accidentally hose a group wiki's page.plist and page.html files, it's possible to recover the latest versions of the pages, if you still have the revisions.db files intact. Here's how I did it:

cd group/wiki
for p in *.page ;
    do sqlite3 $p/revisions.db "select content from revisions order by revision desc limit 1" > /tmp/wikitmp.plist
  defaults read /tmp/wikitmp content > $p/page.html;
    defaults delete /tmp/wikitmp content;
    defaults write /tmp/wikitmp 'modifiedDate' -date $(defaults read /tmp/wikitmp modifiedDate | cut -d . -f 1)
    plutil -convert xml1 /tmp/wikitmp.plist -o $p/page.plist;
    done

srm /tmp/wikitmp.plist

This breaks things like accented characters (replaced by codes returned from defaults), but it sure beats rewriting every single page. :P


back · essays · credits ·