#!/usr/bin/ksh -x
# Backup script.
# Uses tape 6 slot autoloader and the HP util MTX
#
# [email protected]
# 15/9/1998
# 
# Modification Log
# ================
#
# Summary Of Changes
# ==================
# To implement the 4 tape generation backup regime as recommended by XXX in 'Operations Guide For XXX'
# Each generation requires 20 tapes ( 18 re-usable, 2 archive per week )
###########################################################################################################
# Backup Sched.
# Monday    - Backup /catia to tape1 & /export to tape2 & /catia to tape3 ( Off Site )
# Tuesday   - Backup /catia to tape4 & /export to tape5 & /catia to tape6 ( Off Site ), EJECT ALL TAPES
# LOAD NEW TAPES
# Wednesday - Backup /catia to tape1 & /export to tape2 & /catia to tape3 ( Off Site )
# Thursday  - Backup /catia to tape4 & /export to tape5 & /catia to tape6 ( Off Site ), EJECT ALL TAPES
# LOAD NEW TAPES
# Friday    - Backup /catia to tape1 & /export to tape2 & /catia to tape3 ( Off Site ) & /export to tape4 ( Off Site ), EJECT TAPES
# LOAD NEW TAPES
# Saturday  - Backup /, /usr, /opt to tape1
# Saturday  - Backup /, /usr, /opt to tape2 ( Off Site )
# Saturday  - Backup /catia to tape3 (Archive - Never to be used again )
# Saturday  - Backup /catia to tape4 (Archive - Off Site - Never to be used again ), EJECT ALL TAPES
# LOAD NEW TAPES
LANG=en_UK
export LANG
DEVICE=/dev/rmt/1un
SYSADMIN=root
OPS=ops
TODAY=`/usr/bin/date | /usr/bin/awk '{print $1}'`


#
# initape function - Put the device into a known state.
#
initape() {
        /usr/sbin/mtx -d $DEVICE -I

        /usr/sbin/mtx -d $DEVICE -u 1
        if ((  $? != 0 ))
        then
                print "$0: $DEVICE not ready, please check tapes are loaded" 1>&2
                echo "$0: ERROR INIT TAPEDRIVE " | /usr/ucb/mail -s "ERROR - BACKUP" $SYSADMIN
                exit 1
        fi
}
#
# backup function - actual unix dump command
# switches 0 = full dump from EPOC, f = dumpfile, u = update /etc/dumpdates
backup() {
        /usr/lib/fs/ufs/ufsdump 0fu $DEVICE $1
}

#
# loadtape function - load tape from magazine slot (variable passed by function)
#
loadtape() {
        /usr/sbin/mtx -d $DEVICE -l $1
        if ((  $? != 0 ))
        then
                print "$0: $DEVICE not ready, please check tapes are loaded" 1>&2
                echo "$0: ERROR LOADING - device $DEVICE tape $1 " | /usr/ucb/mail -s "ERROR - BACKUP" $SYSADMIN
                exit 1
        fi
}

#
# unloadtape function - unload tape and put back in magazine slot (variable passed by function)
#
unloadtape() {
        /usr/sbin/mtx -d $DEVICE -u $1
        if ((  $? != 0 ))
        then
                print "$0: $DEVICE not ready, please check tapes are loaded" 1>&2
                echo "$0: ERROR UNLOAD - device $DEVICE tape $1 " | /usr/ucb/mail -s "ERROR - BACKUP" $SYSADMIN
                exit 1
        fi
}



#
# email function - EMAIL the SYSADMIN to replace tapes.
#
email() {
        echo "$0: Change backup tapes " | /usr/ucb/mail -s "Change backup tapes for the next Tapes in this Generation" $SYSADMIN
        echo "$0: Change backup tapes " | /usr/ucb/mail -s "Change backup tapes for the next Tapes in this Generation" $OPS
}

#
# emailnewgen function - EMAIL the SYSADMIN to replace tapes and move to the next generation of tapes.
#
emailnewgen() {
        echo "$0: Change backup tapes " | /usr/ucb/mail -s "Change backup tapes for the next Generation of Tapes" $SYSADMIN
        echo "$0: Change backup tapes " | /usr/ucb/mail -s "Change backup tapes for the next Generation of Tapes" $OPS
}

#
# eject_mag function - eject magazine
#               NOTE -  all tape must be loaded on the magazine
#
eject_mag() {
        /usr/sbin/mtx -d $DEVICE -E
        if ((  $? != 0 ))
        then
                print "$0: $DEVICE not ready, Error ejecting magazine" 1>&2
                echo "$0: ERROR EJECTING  MAGAZINE- device $DEVICE " | /usr/ucb/mail -s "ERROR - BACKUP" $SYSADMIN
                exit 1
        fi
}

#
#  START OF MAIN PROGRAM
#

initape

case "$TODAY" in
'Monday')
        loadtape 1
        backup /catia
        unloadtape 1

        loadtape 2
        backup /export
        unloadtape 2

        loadtape 3
        backup /catia
        unloadtape 3
        ;;
'Tuesday')
        loadtape 4
        backup /catia
        unloadtape 4

        loadtape 5
        backup /export
        unloadtape 5

        loadtape 6
        backup /catia
        unloadtape 6

        email
        eject_mag
        ;;
'Wednesday')
        loadtape 1
        backup /catia
        unloadtape 1

        loadtape 2
        backup /export
        unloadtape 2

        loadtape 3
        backup /catia
        unloadtape 3
        ;;
'Thursday')
        loadtape 4
        backup /catia
        unloadtape 4

        loadtape 5
        backup /export
        unloadtape 5

        loadtape 6
        backup /catia
        unloadtape 6

        email
        eject_mag
        ;;
'Friday')
        loadtape 1
        backup /catia
        unloadtape 1

        loadtape 2
        backup /export
        unloadtape 2

        loadtape 3
        backup /catia
        unloadtape 3

        loadtape 4
        backup /export
        unloadtape 4

        email
        eject_mag
        ;;
'Saturday')
        loadtape 1
        backup /
        backup /usr
        backup /opt
        unloadtape 1

        loadtape 2
        backup /
        backup /usr
        backup /opt
        unloadtape 2

        loadtape 3
        backup /catia
        unloadtape 3

        loadtape 4
        backup /catia
        unloadtape 4

        emailnewgen
        eject_mag
        ;;
esac
Hosted by www.Geocities.ws

1