Archive-and-delete.sh

From WeBWorK
Jump to: navigation, search
!/bin/bash
#
# Hal Sadofsky, September 4, 2010
#
# This script archives and deletes a bunch of courses from WeBWorK.
#
# It calls a perl script to do the actual archiving.  It probably needs to be
# run as root, or as some very privileged user in the local WeBWorK
# directories.
#
# After making the archive (a .tar.gz file) the script deletes the course, and
# copies the archive to ARCHIVE_DIR.
#
# Usage is 
#
# sh archive-and-delete.sh coursename
#
# where coursename can be an indidual coursename, or something with wildcards
# that will match more than one coursename.
#
# Be careful!!  The command
#
# sh archive-and-delete.sh *
#
# will archive and delete all courses!
#
# 
export WEBWORK_ROOT=/opt/webwork/webwork2
export COURSE_DIR=/opt/webwork/courses
export SCRIPT_DIR=/home/wwork/archive-courses
export ARCHIVE_DIR=/opt/webwork/old/
directory=`pwd`
filesuffix='.tar.gz' 

cd $COURSE_DIR

for file in $1
if [ -d "$file" ]
then
  echo "Removing temp files from $file."
  rm $file/logs/*
  rm -rf $file/html/tmp/*
  echo "Making archive of $file."
  perl $SCRIPT_DIR/make-course-archive.pl $file
  archivename="${file}$filesuffix"
  echo $archivename
  if [ -f "$archivename" ]
  then
      echo "Archive of $file successful, deleting course."
      perl $WEBWORK_ROOT/bin/delcourse $file
      echo "Moving to archive directory."
      mv $archivename $ARCHIVE_DIR
  else
      echo "Archive of $file unsuccessful."
  fi
fi
done

cd $directory
follow us