#!/bin/sh # Written by: Brenda Bell # Version: 1.04 # Date: 23 Mar 2003 # URL: opensource.theotherbell.com # # This script is distributed as is without warrenty. # # It may be freely distributed with or without modification provided # that: # # 1. This header is included in the distribution # 2. The redistributor documents his modifications immediately # below this header by providing his/her name and a description # of the modifications # # Change log: # # 23 Mar 2003: Moved some logic to backup2disk.functions for easier # maintenance # # 16 Feb 2003: Changed to use logger # # 15 Feb 2003: Changed error handling to guarantee that umount # command gets executed; added log messages for mount # and umount; added tar's exit code to email notification # # 30 Jan 2003: Changed level0 backup to seed the level1 timestamp; # This allows accurate level2 backups without an # intervening level1; the change has no effect on # level1 backups # me=`dirname $0`/`basename $0` if [ -z "$BACKUP2DISKHOME" ] ; then BACKUP2DISKHOME=`dirname $0` fi # include default settings and functions . ${BACKUP2DISKHOME}/backup2disk.conf . ${BACKUP2DISKHOME}/backup2disk.functions # process command line arguments for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval "$ac_prev=\$ac_option" ac_prev= continue fi case "$ac_option" in -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) ac_optarg= ;; esac case "$ac_option" in # options with arguments --archivedir) ac_prev=archivedir;; --archivedir=*) archivedir="$ac_optarg";; --backupdatadir) ac_prev=backupdatadir;; --backupdatadir=*) backupdatadir="$ac_optarg";; --excludefile) ac_prev=excludefile;; --excludefile=*) excludefile="$ac_optarg";; --level) ac_prev=level;; --level=*) level="$ac_optarg";; --mount) ac_prev=mount;; --mount=*) mount="$ac_optarg";; --notification) ac_prev=notification;; --notification=*) notification="$ac_optarg";; --sendto) ac_prev=sendto;; --sendto=*) sendto="$ac_optarg";; --sourcedir) ac_prev=sourcedir;; --sourcedir=*) sourcedir="$ac_optarg";; --umount) ac_prev=umount;; --umount=*) umount="$ac_optarg";; # options which are set or unset --crossfilesystems) crossfilesystems=yes;; --dereferencelinks) dereferencelinks=yes;; --disablecompression) disablecompression=yes;; --disableverify) disableverify=yes;; # help --help) cat << EOF Usage: $0.sh [options] Options: [choices in brackets] (defaults in parenthesis) Configuration: --archivedir=dir (${archivedir:-"not set"}) --backupdatadir=dir (${backupdatadir:-"not set"}) --crossfilesystems [yes|no] (${crossfilesystems:-"not set"}) --dereferencelinks [yes|no] (${dereferencelinks:-"not set"}) --disablecompression [yes|no] (${disablecompression:-"not set"}) --disableverify [yes|no] (${disableverify:-"not set"}) --excludefile=[none|file|default] (${excludefile:-"not set"}) --level=[0|1|2] (${level:-"not set"}) --mount=command (${mount:-"not set"}) --notification=[none|summary|list|verboselist] (${notification:-"not set"}) --sendto=email (${sendto:-"not set"}) --sourcedir=dir (${sourcedir:-"not set"}) --umount=command (${umount:-"not set"}) EOF exit 0 ;; esac done backup2disk_checkargs if [ $? -ne 0 ] ; then backup2disk_notify "Error found in backup configuration; check syslog for details" exit 1; fi echo "Commencing backup at `date`..." backup2disk_log "tar --create $label $afterdate $excludefrom $gzip $file $onefilesystem $verbose $sourcefiles" eval tar --create $label $afterdate $excludefrom $gzip $file $onefilesystem $verbose $sourcefiles RC=$? backup2disk_log "Backup exited with exit code $RC at `date`" if [ ! -f $archivefile ] ; then backup2disk_log "Fatal error: $archivefile not found" backup2disk_notify "Fatal error: $archivefile not found; check syslog for details" if [ "$umount" != "" ] ; then $umount fi exit 1 fi echo "Updating datestamps..." if [ "$level" -eq 0 ] ; then echo $now > $datestamp0 echo $now > $datestamp1 elif [ "$level" -eq 1 ] ; then echo $now > $datestamp1 fi if [ "$disableverify" != "yes" ] ; then echo "Verifying backup..." eval tar --list $file $gzip fi backup2disk_notify "Host: $HOSTNAME Files: $sourcedir Archive: $archivefile Started: $now Exit code: $RC" # unmount filesystem if [ "$umount" != "" ] ; then $umount fi