Monday, December 24, 2007

backup-clamav.sh - backup ClamAV data files prior to upgrade

#!/bin/sh
#
# backup-clamav.sh - backup ClamAV data files
#
# History:
# 2007/12/23 rwsiv1@gmail.com
# Created this file based on the ClamAV documentation (http://wiki.clamav.net/Main/UpgradeInstructions).
#
# Notes:
# This file can also be downloaded from: http://docs.google.com/Doc?id=dgwx5z52_90ftmz92gg
#

BACKUPDIR="/tmp/clamav"
TIMESTAMP=`date '+%Y%m%d-%H%M%S'`
ETCDIR="/usr/local/etc/"
BACKUPETCFILE="${BACKUPDIR}/backup-etc-${TIMESTAMP}.tgz"
SIGDIR="/usr/local/share/clamav/"
BACKUPSIGFILE="${BACKUPDIR}/backup-sig-${TIMESTAMP}.tgz"

#
# Functions
#
# failed() - print an error message and exit.
# args: message [errno]
#
failed () {
EXITCODE="1"

if [ -n "$1" ]; then
echo "$0 - $1"
if [ "$2" -gt 0 ]; then
EXITCODE="$2"
fi
fi
exit ${EXITCODE}
}

#
# Make sure that the backup directory exists
#
[ -d ${BACKUPDIR} ] || mkdir ${BACKUPDIR} || failed "unable to access or create ${BACKUPDIR}"

#
# Backup the directories
#
# etc files
#
cd ${ETCDIR} || failed "unable to cd to ${ETCDIR}"
tar czvpf ${BACKUPETCFILE} /usr/local/etc/clam*.conf /usr/local/etc/freshclam.conf
#
# signature files
#
cd ${SIGDIR} || failed "unable to cd to ${SIGDIR}"
tar czvpf ${BACKUPSIGFILE} /usr/local/share/clamav/