Automated Stand Alone Backups
Marc Ph. A. J. St.-Gil
mstgil at sol
Sat May 4 00:07:19 AEST 1991
As I have received multiple requests for details on how I have implemented
an almost completely unattended backup system for our 1.7GB server system,
I have decided to post this document to comp.unix.admin. Perhaps it should
be worked into a/the FAQ for this group?
First off, let me describe our environment. THe system being backed up is
a Solbourne 5E/902 Enterprise server with 2 IPI drives totaling about 1.7GB
of disk storage and 1 8mm 2.3 GB cassette drive for tape backup. This system
is running Solbourne OS/MP v.4.0D which is equivalent to SunOS 4.0.3. We are
not currently exporting any filesystems nor are we mounting same. Therefore,
I have not had to deal with the headache of cross network backups. The
following set of files and scripts is how I have set things up so that all
the operators have to do is swap a tape once a day. Our operators are part-
time student employees who are quite competent, but we want them to spend a
majority of their time working on less brainless tasks than switching tapes
for backups all day.
My proceedure consists of three parts. Part 1 is a set of cron entries to
make things happen at the proper time. Part 2 is a modification to Sol's
/etc/rc script. And part 3 is a set of scripts designed to actually do the
work.
Part 1 - the relevant cron entries
# cron table for root
#
# do an incremental backup Sun-Fri at 02:00
0 2 * * 0-5 /var/backups/daily
#
# tell system to shut down at 02:00 for stand alone backups on Sat. at 00:01
1 0 * * 6 /usr/etc/shutdown -r 02:00 " for stand alone backups" >/dev/null 2>&1
#
# create the stand alone backup control file on Sat. at 01:50
50 1 * * 6 /usr/bin/touch /var/backups/do_standalone
#
# remind the operator to put in a new backup tape Sat-Thurs at 17:00
0 17 * * 0-4,6 /var/backups/daily.msg >/dev/console
# and at 08:00 on Friday's
0 8 * * 5 /var/backups/sa.msg >/dev/console
#
Part 2 - The modified area of our /etc/rc script
Lines added are indicated by a leading "> ".
#
# See if things look like they are still mounted read-only.
# If so, perform all the remounting and set up work now.
#
touch /
if [ $? -ne 0 ]; then
(echo "Remounting file systems") >/dev/console
sh /etc/rc.single
fi
> if [ -r /var/backups/do_standalone ]; then
> #remove the flag file 1st to prevent possible looping on error
> rm -f /var/backups/do_standalone
> #do the backup synchronously
> sh /var/backups/standalone
> #check the backup asynchronously
> sh /var/backups/sa.check &
> fi
if [ -r /fastboot ]; then
rm -f /fastboot
elif [ $1x = autobootx ]; then
(echo Automatic reboot in progress...) >/dev/console
else
(echo Multiuser startup in progress...) >/dev/console
fi
date >/dev/console
Part 3 - the backup scripts
These are included as a shell archive, they should be sufficiently commented
internally. :)
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# daily
# daily.msg
# sa.bump
# sa.check
# sa.msg
# sa.week
# standalone
# This archive created: Fri May 3 09:02:42 1991
export PATH; PATH=/bin:$PATH
if test -f 'daily'
then
echo shar: will not over-write existing file "'daily'"
else
cat << \SHAR_EOF > 'daily'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: daily
#
# Purpose: Perform a level 5 backup while running
#
# Known Bugs: none
#
# Inputs: none
#
# Dependencies: Expects a writeable tape to be in the drive
#
# Outputs: Backup Tape, log file /var/backups/daily.out.<Day>
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Tue Feb 26 19:19:23 CST 1991
#
# Modification History:
# changed tape drive and added vars for speed and ease of modification
# Fri Apr 19 11:59:31 CDT 1991
#
# contents of /etc/fstab when last modified
# /dev/xd0a / 4.2 rw 1 1
# /dev/xd0d /var 4.2 rw 1 2
# /dev/xd0g /usr 4.2 rw 1 3
# /dev/xd1a /etc/security/audit/sol 4.2 rw 1 1
# /dev/xd1b /etc/security/audit/sol.1 4.2 rw 1 1
# /dev/xd1d /home 4.2 rw,quota 1 3
# /dev/xd0e /tmp 4.2 rw 1 1
# /dev/xd0f /var/tmp 4.2 rw 1 2
TAPE=/dev/rst0
NTAPE=/dev/nrst0
DUMP=/usr/etc/dump
DUMP_OPTS="S5ufM $NTAPE P6-120"
RESTORE=/usr/etc/restore
RESTORE_OPTS="tfMs $TAPE P6-120"
REWIND="/usr/bin/mt -f $TAPE rew"
# figure out what 'day' it is
day=`date +%a`
echo "Doing backups for $day" >/var/backups/daily.out.$day
echo >>/var/backups/daily.out.$day
echo >>/var/backups/daily.out.$day
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
# dump file systems in order most likely to need restoration
# /
$DUMP $DUMP_OPTS /dev/rxd0a >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /usr
$DUMP $DUMP_OPTS /dev/rxd0g >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /home
$DUMP $DUMP_OPTS /dev/rxd1d >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /etc/security/audit/sol
$DUMP $DUMP_OPTS /dev/rxd1a >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /etc/security/audit/sol.1
$DUMP $DUMP_OPTS /dev/rxd1b >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /var
$DUMP $DUMP_OPTS /dev/rxd0d >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /tmp
$DUMP $DUMP_OPTS /dev/rxd0e >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
# /var/tmp
$DUMP $DUMP_OPTS /dev/rxd0f >>/var/backups/daily.out.$day 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/daily.out.$day
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
# now check our work
echo "Now check our work" >>/var/backups/daily.out.$day
echo >>/var/backups/daily.out.$day
# /
$RESTORE $RESTORE_OPTS 1 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "1st backup ok" >>/var/backups/daily.out.$day
# /usr
$RESTORE $RESTORE_OPTS 2 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "2nd backup ok" >>/var/backups/daily.out.$day
# /home
$RESTORE $RESTORE_OPTS 3 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "3rd backup ok" >>/var/backups/daily.out.$day
# /etc/security/audit/sol
$RESTORE $RESTORE_OPTS 4 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "4th backup ok" >>/var/backups/daily.out.$day
# /etc/security/audit/sol.1
$RESTORE $RESTORE_OPTS 5 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "5th backup ok" >>/var/backups/daily.out.$day
# /var
$RESTORE $RESTORE_OPTS 6 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "6th backup ok" >>/var/backups/daily.out.$day
# /tmp
$RESTORE $RESTORE_OPTS 7 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "7th backup ok" >>/var/backups/daily.out.$day
# /var/tmp
$RESTORE $RESTORE_OPTS 8 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "8th backup ok" >>/var/backups/daily.out.$day
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
echo "all backups ok - tape rewound" >>/var/backups/daily.out.$day
SHAR_EOF
chmod +x 'daily'
fi # end of overwriting check
if test -f 'daily.msg'
then
echo shar: will not over-write existing file "'daily.msg'"
else
cat << \SHAR_EOF > 'daily.msg'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: daily.msg
#
# Purpose: print a message about which backup tape to insert
#
# Known Bugs: none
#
# Inputs: none
#
# Dependencies: none
#
# Outputs: see purpose
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Tue Apr 30 14:05:54 CDT 1991
#
# Modification History:
#
echo "Please insert tape for `date +%a`."
SHAR_EOF
chmod +x 'daily.msg'
fi # end of overwriting check
if test -f 'sa.bump'
then
echo shar: will not over-write existing file "'sa.bump'"
else
cat << \SHAR_EOF > 'sa.bump'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: sa.bump
#
# Purpose: Bump the sa.week file around one for syncing up schedules
#
# Known Bugs: none
#
# Inputs: /var/backups/sa.week
#
# Dependencies: /var/backups/sa.week
#
# Outputs: stdout, /var/backups/sa.week
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Sat Apr 27 11:32:32 CDT 1991
#
# Modification History:
#
# figure out what 'week' it is
week=`cat /var/backups/sa.week`
# tell user
echo "Current week set to $week"
# set up for next week
week=`expr $week + 1`;
if [ $week -eq 5 ]; then week=1; fi
echo $week > /var/backups/sa.week
# tell user
echo "Week now set to $week"
SHAR_EOF
chmod +x 'sa.bump'
fi # end of overwriting check
if test -f 'sa.check'
then
echo shar: will not over-write existing file "'sa.check'"
else
cat << \SHAR_EOF > 'sa.check'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: sa.check
#
# Purpose: Check the level 0 backup while coming up from re-boot
#
# Known Bugs: none
#
# Inputs: /dev/st0, /var/backups/sa.week
#
# Dependencies: /dev/st0, /var/backups/sa.week
#
# Outputs: /var/backups/sa.out.<week#>, /var/backups/sa.week
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Sat Apr 27 11:23:59 CDT 1991
#
# Modification History:
#
# contents of /etc/fstab when last modified
# /dev/xd0a / 4.2 rw 1 1
# /dev/xd0d /var 4.2 rw 1 2
# /dev/xd0g /usr 4.2 rw 1 3
# /dev/xd1a /etc/security/audit/sol 4.2 rw 1 1
# /dev/xd1b /etc/security/audit/sol.1 4.2 rw 1 1
# /dev/xd1d /home 4.2 rw,quota 1 3
# /dev/xd0e /tmp 4.2 rw 1 1
# /dev/xd0f /var/tmp 4.2 rw 1 2
TAPE=/dev/rst0
NTAPE=/dev/nrst0
RESTORE=/usr/etc/restore
RESTORE_OPTS="tfMs $TAPE P6-120"
REWIND="/usr/bin/mt -f $TAPE rew"
# figure out what 'week' it is
week=`cat /var/backups/sa.week`
# start backup
echo >>/var/backups/sa.out.$week
echo "Checking backups for week $week" >>/var/backups/sa.out.$week
echo >>/var/backups/sa.out.$week
echo >>/var/backups/sa.out.$week
# dump file systems in order most likely to need restoration
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
# /
$RESTORE $RESTORE_OPTS 1 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "1st backup appears ok" >>/var/backups/sa.out.$week
# /usr
$RESTORE $RESTORE_OPTS 2 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "2nd backup appears ok" >>/var/backups/sa.out.$week
# /home
$RESTORE $RESTORE_OPTS 3 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "3rd backup appears ok" >>/var/backups/sa.out.$week
# /etc/security/audit/sol
$RESTORE $RESTORE_OPTS 4 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "4th backup appears ok" >>/var/backups/sa.out.$week
# /etc/security/audit/sol.1
$RESTORE $RESTORE_OPTS 5 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "5th backup appears ok" >>/var/backups/sa.out.$week
# /var
$RESTORE $RESTORE_OPTS 6 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "6th backup appears ok" >>/var/backups/sa.out.$week
# /tmp
$RESTORE $RESTORE_OPTS 7 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "7th backup appears ok" >>/var/backups/sa.out.$week
# /var/tmp
$RESTORE $RESTORE_OPTS 8 >/dev/null
if [ $? -ne 0 ]; then exit -1; fi
echo "8th backup appears ok" >>/var/backups/sa.out.$week
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
echo "all backups appear ok - tape rewound" >>/var/backups/sa.out.$week
# set up for next week
week=`expr $week + 1`;
if [ $week -eq 5 ]; then week=1; fi
echo $week > /var/backups/sa.week
SHAR_EOF
chmod +x 'sa.check'
fi # end of overwriting check
if test -f 'sa.msg'
then
echo shar: will not over-write existing file "'sa.msg'"
else
cat << \SHAR_EOF > 'sa.msg'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: sa.msg
#
# Purpose: print a message about which weekly backup tape to insert
#
# Known Bugs: none
#
# Inputs: none
#
# Dependencies: none
#
# Outputs: see purpose
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Tue Apr 30 14:05:54 CDT 1991
#
# Modification History:
#
week=`cat /var/backups/sa.week`
echo "Please insert tape for week $week."
SHAR_EOF
chmod +x 'sa.msg'
fi # end of overwriting check
if test -f 'sa.week'
then
echo shar: will not over-write existing file "'sa.week'"
else
cat << \SHAR_EOF > 'sa.week'
3
SHAR_EOF
fi # end of overwriting check
if test -f 'standalone'
then
echo shar: will not over-write existing file "'standalone'"
else
cat << \SHAR_EOF > 'standalone'
#!/bin/sh
# set -x
# Script Header
#
# Name/Usage: standalone
#
# Purpose: Perform a level 0 backup while coming up from re-boot
#
# Known Bugs: appears to hang re-boot if no tape in drive (fixed?)
#
# Inputs: Whole File System, /var/backups/sa.week
#
# Dependencies: Tape in /dev/st0, /var/backups/sa.week
#
# Outputs: Backup Tape in /dev/st0
#
# Side Effects: none
#
# Author: Marc Ph. A. J. St.-Gil
#
# Creation Date: Tue Feb 26 19:19:23 CST 1991
#
# Modification History:
# changed tape drive and added vars for speed and ease of modification
# Fri Apr 19 15:45:01 CDT 1991
# changed to a two part script - this part makes backups and exits,
# other part checks backup in background (sa.check) they are tightly
# coupled!
# Sat Apr 27 11:23:59 CDT 1991
#
# contents of /etc/fstab when last modified
# /dev/xd0a / 4.2 rw 1 1
# /dev/xd0d /var 4.2 rw 1 2
# /dev/xd0g /usr 4.2 rw 1 3
# /dev/xd1a /etc/security/audit/sol 4.2 rw 1 1
# /dev/xd1b /etc/security/audit/sol.1 4.2 rw 1 1
# /dev/xd1d /home 4.2 rw,quota 1 3
# /dev/xd0e /tmp 4.2 rw 1 1
# /dev/xd0f /var/tmp 4.2 rw 1 2
TAPE=/dev/rst0
NTAPE=/dev/nrst0
DUMP=/usr/etc/dump
DUMP_OPTS="0ufM $NTAPE P6-120"
REWIND="/usr/bin/mt -f $TAPE rew"
TAPECHECK="/usr/bin/mt -f $TAPE status"
$TAPECHECK
# figure out what 'week' it is
week=`cat /var/backups/sa.week`
# start backup
echo "Doing backups for week $week" >/var/backups/sa.out.$week
echo >>/var/backups/sa.out.$week
echo >>/var/backups/sa.out.$week
# dump file systems in order most likely to need restoration
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
# /
$DUMP $DUMP_OPTS /dev/rxd0a >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /usr
$DUMP $DUMP_OPTS /dev/rxd0g >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /home
$DUMP $DUMP_OPTS /dev/rxd1d >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /etc/security/audit/sol
$DUMP $DUMP_OPTS /dev/rxd1a >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /etc/security/audit/sol.1
$DUMP $DUMP_OPTS /dev/rxd1b >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /var
$DUMP $DUMP_OPTS /dev/rxd0d >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /tmp
$DUMP $DUMP_OPTS /dev/rxd0e >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
# /var/tmp
$DUMP $DUMP_OPTS /dev/rxd0f >>/var/backups/sa.out.$week 2>&1
if [ $? -ne 0 ]; then exit -1; fi
echo >>/var/backups/sa.out.$week
$REWIND
if [ $? -ne 0 ]; then exit -1; fi
echo "backups ran without errors - tape rewound" >>/var/backups/sa.out.$week
SHAR_EOF
chmod +x 'standalone'
fi # end of overwriting check
# End of shell archive
exit 0
Cheers!,
Marc
--
Marc St.-Gil, UNIX Systems Administrator mstgil@{sol,vaxa,vaxb}.acs.unt.edu
University of North Texas 817/565-2324 mstgil@{ponder,solo}.csci.unt.edu
Academic Computing Services DISCLAIMER: My employers had no idea I was
PO Box 13495, Denton TX, 76203 going to say that.
More information about the Comp.unix.admin
mailing list