I haven't tested this out yet, but I'm planning on integrating my clamscan run with my backup run. My backup tool produces a list of files modified in order to perform an incremental backup, so why recompute the same file list twice?
I use dirvish to create my backups, which uses rsync underneath. In the end, I get a log.bz2
giving me a report of all files backed-up including the list of files that got backed-up.
This genclamfilelist.sh
script will extract the file list from the log.bz2
of the latest backup and print it out:
#!/bin/sh
AWK=/usr/bin/awk
BUNZIP2=/bin/bunzip2
HEAD=/usr/bin/head
HOSTNAME=/bin/hostname
LS=/bin/ls
SED=/bin/sed
SNAPSHOT_HOME=/path/to/dirvish/snapshots
for vaultHome in ${SNAPSHOT_HOME}/*; do
# vault naming convention: <hostname>-<sharename>
vaultName="`echo ${vaultHome} | ${SED} -e 's/^.*\/\([^\/]\+\)$/\1/'`"
vaultHost="`echo ${vaultName} | ${SED} -e 's/\([^\-]\+\)\-.*$/\1/'`"
# only proceed if vault being considered is for the same host
if [ "${vaultHost}" = "`${HOSTNAME}`" ]; then
logfile="`${LS} -1t ${vaultHome}/20??????-???? \
| ${HEAD} -1 \
| ${SED} -e 's/^\(.*\)\:$/\1/'`/log.bz2"
if [ -f ${logfile} ]; then
${BUNZIP2} -c ${logfile} | ${AWK} '
/^$/ {
if (start) {
start=0
}
}
{
if (start) {
print $0
}
}
/^receiving\ file\ list\ \.\.\.\ done$/ {
start=1
}' | ${SED} -e "s/^\(.*\)$/\/\1/"
fi
# else skip - no log file found, probably backup didn't run or failed
fi
# else skip - another vault
done
exit 0
This /etc/cron.d/clamav
cron script will use the file list:
# /etc/cron.d/clamav: crontab fragment for clamav
CLAMAV_FILELIST=/tmp/clamav_filelist_`/bin/hostname`.txt
# run every night
0 19 * * * root /usr/bin/test -f ${CLAMAV_FILELIST} && /usr/bin/clamscan --any-desired-options --file-list=${CLAMAV_FILELIST} && /bin/rm ${CLAMAV_FILELIST}
Since I use dirvish, I modified its /etc/dirvish/dirvish-cronjob
to call the first script to generate the file list for use by the last script:
# ...
/usr/sbin/dirvish-expire --quiet && /usr/sbin/dirvish-runall --quiet rc=$?
# v--- BEGIN ADDING NEW LINES
touch /tmp/clamav_filelist_`hostname`.txt
chmod 400 /tmp/clamav_filelist_`hostname`.txt
/usr/local/bin/genclamfilelist.sh >> /tmp/clamav_filelist_`hostname`.txt
# ^--- END ADDING NEW LINES
umount /mnt/backup0 || rc=$?
# ...