Skip to main content

No replies
Joined: 2004-07-13
Points: 0

In today's community meeting, I mentioned a shell script that takes the contents of a WFS snapshot and creates a tgz file with all the WFS, associated artwork and audio.

This script is for Linux:

<br />
#!/bin/bash </p>
<p># a script that copies the content of a WFS snapshot and all associated artwork<br />
# into a tar file.<br />
#<br />
# usage: input_dir (output_dir)<br />
#   input_dir: the wfs snapshot to save a copy of<br />
#   output_dir: the optional directory to write output to. If no directory is specified, the<br />
#               current directory will be used</p>
<p># copy all content referred to with wlcontent:// URLs<br />
copy_content () {<br />
    for i in `find $origdir -exec grep "wlcontent://" {} \; | sed -e 's|.*wlcontent://users@[0-9.]*\:[0-9]*/\(.*\)<.*|\1|' | sed -e 's|.*wlcontent://users/\(.*\)<.*|\1|'`; do<br />
        # find directory name<br />
        dir=`echo $i | sed -e 's|\(.*\)/.*|\1|'`<br />
        mkdir -p $tmpdir/run/content/users/$dir</p>
<p>        echo "Copying content from $wldir/run/content/users/$i to $tmpdir/run/content/users/$dir"<br />
        cp $wldir/run/content/users/$i $tmpdir/run/content/users/$i<br />
    done<br />
<p># copy all files associated with a deployed model<br />
copy_models () {<br />
    for i in `find $origdir -exec grep deployedModelURL {} \; | cut -d ':' -f 3 | sed -e 's|[0-9]*/\(.*\)\.kmz/.*|/\1.kmz|'`; do<br />
        echo "Copying model from $wldir/run/content/users/$i to $tmpdir/run/content/users"</p>
<p>        mkdir -p $tmpdir/run/content/users/$i<br />
        cp -R $wldir/run/content/users/$i/* $tmpdir/run/content/users/$i<br />
    done<br />
<p># first argument: directory to take a snapshot of<br />
<p># second argument: directory to write to (optional)<br />
if [ $2 ]; then<br />
    outdir=$2<br />
else<br />
    outdir=`pwd`<br />
<p># find the Wonderland directory this wfs is a child of<br />
wldir=`echo $1 | sed -e 's|\(.*\)/wfs/.*|\1|'`<br />
echo "Wonderland directory $wldir"</p>
<p># create the temporary directory to copy to<br />
tmpdir=/tmp/wlsave<br />
rm -rf $tmpdir</p>
<p># create subdirectories we will need<br />
mkdir -p $tmpdir/wfs/snapshots<br />
mkdir -p $tmpdir/run/content/users</p>
<p># copy WFS files -- this assumes a WFS snapshot<br />
echo "Copying WFS from $1 to $tmpdir/wfs/snapshots"<br />
cp -R $1 $tmpdir/wfs/snapshots</p>
<p># copy all content from the content repository<br />
<p># special-case copying of files related to deployed models<br />
<p># determine the output directory and file name<br />
outfile=`echo $1 | sed -e 's|.*/\(.*\)|\1|'`-`date +%m%d%Y`.tgz</p>
<p># create the output file by tarring the temporary directory<br />
echo "Writing to $outfile"<br />
cd $tmpdir<br />
tar czf $outdir/$outfile *<br />