#!/bin/sh # backup v1.0.7 (c) 3.7.2002 by Andreas Ley (u) 26.1.2007 # Backup Celerra Filesystems on TSM Server #mail="andy@rz.uni-karlsruhe.de urle@rz.uni-karlsruhe.de" mail="andy@rz.uni-karlsruhe.de" days=1 logs=/var/log/backup locks=/var/lock/backup usage() { echo "Usage: `basename $0` [-d days] [-s site] [-v] [-V] [filesystem]" >&2 echo "-d run backups for filesystems not backed up since n days" >&2 echo "-s force backup site (ka/hd)" >&2 echo "-v verbose mode" >&2 echo "-V tsm verbose mode" >&2 exit 1 } set -- `getopt DhxvVd:s: $*` || usage trace=false verbose=false while :; do case $1 in -h) sed '1d;s/^# *//;/^$/q' $0; usage;; -x) set -x; trace=true; shift;; -v) verbose=true; shift;; -V) options="-verbose"; shift;; -d) days="$2"; shift 2;; -s) force_site="$2"; shift 2;; --) shift; break;; esac done # HP-UX and Linux syntax test $# -eq 0 && set `mount | sed -n 's/^[^ ]*:[^ ]* on //;s/^\(\/export\/[^ ]*\) .*/\1/p' | sort` seconds=`expr ${days} \* 86400` PATH=/bin:/usr/bin:/usr/machine/bin; export PATH DSM_DIR=/opt/tivoli/tsm/client/ba/bin; export DSM_DIR DSM_CONFIG=/usr/local/tsm/dsm.opt; export DSM_CONFIG DSM_LOG=${logs}; export DSM_LOG LC_CTYPE=en_US; export LC_CTYPE umask 077 # Process all filesystems for fs do # The filesystem name usable as a filename base=`echo ${fs} | sed 's/^\///;s/\//_/g;'` # File used as timestamp as well as lock against multiple instances lock=${locks}/${base} # Check wether this filesystem should be backed up test -f ${lock} && test `/usr/machine/bin/stat -N -m ${lock}` -lt ${seconds} && continue # Define backup site if test -n "${force_site}"; then site="${force_site}" else site="ka" test -s ${lock} -a ! -f "${fs}/.etc/backup.${site}" && grep "${site}" ${lock} >/dev/null && site="hd" fi # Create log and lock directories in case someone just removed them mkdir -p ${logs}/${site} ${locks} # Log dsmc output log=${logs}/${site}/${base}.log # Dsmc error output err=${logs}/${site}/${base}.err # Try to obtain lock; if successful, keep 7 versions of old logs and run incremental backup ${verbose} && echo "[`date '+%d.%m.%Y %H:%M:%S'`] Try backup ${site}: ${fs}" #${verbose} && echo ${DSM_DIR}/dsmc query filespace -server=${site} #${verbose} && eval ${DSM_DIR}/dsmc query filespace -server=${site} lockcmd -n ${lock} "test -s ${log} && cycle ${log}; exec ${DSM_DIR}/dsmc incremental -server=${site} ${options} ${fs} >${log} 2>&1" status=$? if test ${status} -eq 255; then # Some other backup instance is currently working on this ${verbose} && echo "[`date '+%d.%m.%Y %H:%M:%S'`] Locked: ${fs}" else # We successfully obtained the lock so don't try again until # next schedule echo "${site}" >${lock} # Now check wether the backup was successful, too: # Remove all known legal messages from the log egrep -v -f /usr/local/etc/tsm.error.ignore ${log} >${err} # Unknown output in logfile or unknown error code, send mail # Error codes 4 (some file not processes) and 8 (warning # message) produce error output that we handle separatly if test -s ${err} -o \( ${status} -ne 0 -a ${status} -ne 4 -a ${status} -ne 8 \); then ${verbose} && echo "[`date '+%d.%m.%Y %H:%M:%S'`] Backup ${site} complete with errors: ${fs}" (echo "Subject: TSM-Backup `hostname`:${fs} on ${site}" echo if test ${status} -ne 0; then echo "Backup command exited with status ${status}" echo fi if test -s ${err}; then echo "Unknown TSM messages for ${fs} on ${site}, probably due to errors:" echo uniq ${err} echo fi echo "Complete TSM output:" echo cat ${log}) | /usr/lib/sendmail -i ${mail} else ${verbose} && echo "[`date '+%d.%m.%Y %H:%M:%S'`] Backup ${site} complete: ${fs}" rm -f ${err} fi fi done exit 0