SUMMAY: Automated Backup Scripts

From: boyd0009@mc.duke.edu
Date: Tue Jan 30 1996 - 10:24:42 CST


I recently posted a question about performing automated backups on a
Solaris 2.4 machine. I received several replies and the consensus
seemed to be to use a backup script and cron to do the job. This works
very well for a single machines. If you have several machines to
backup, you may want to look at the AMANDA software available at
ftp.cs.umd.edu:/pub/amanda.

Several people wrote back to me asking for copies of the backup
scripts I received. I contacted the authors of the scripts and asked
for permission to post them. Attached to this message is a uuencoded
reply I received from Jay Lessert. The reply includes Jay's README
file, his crontab entry, and the backup scripts he uses. If anyone has
trouble getting this let me know and I'll try to help.

Once again, I would like to thank the following people for their help
and for their willingness to share their scripts with the group:

Jay Lessert jayl@lattice.com
Steve Poulsen spoulsen@transcrypt.com
Glenn Satchell glenn@uniq.com.au

Here is the backup script I received from Steve Poulsen. It can do
both dumps and tars. There is a loop for each so if you don't want
to use the tar part, remove the loop or make the TARFILES set to
nothing. Steve said he used tar for a couple of NFS directories.

#!/bin/csh
# Backup script by Steve Poulsen
# Performs backup and ejects the tape
#
# 0: level 0 dump (full)
# u: update /etc/dumpdates
# c: cartridge (den=1000BPI bf=126 len 425ft)
# d: density in BPI (2.3gb 8mm is 54,000)
# s: size (2.3gb8mm is 6000 ft)
# f: dump file

# Set dump device. Important not to rewind the tape. Dump will still report
# rewinding. Set the temp log file this gets mailed to me. Set log file
# actually, the names are backwards because I added a feature. This file is
# long. Set the fail file. If this file is created something went wrong. cat
# it for more info. DUMPFILES contains a list of file systems to dump TARFILES
# contains a list of files to tar to the tape

set DUMPDEV=/dev/nrst0
set LOGFILE=/csi/add_ons/backup/log_dir/temp.log
set TEMPLOG=/csi/add_ons/backup/log_dir/dump.log
set FAILFILE=/csi/add_ons/backup/`date +%m-%d-%y`.fail
set DUMPFILES='/ /csi /usr /var'
set TARFILES='/var/tscrypt1 /usr/export/home/tscrypt1'

# Create this file to disable nightly dumps

if (-f /var/tmp/disable-dump) then
  exit 1
endif

# Tell users that we are logging off and provide some info if running directly.

echo 'LOGOFF NOW. Performing backup'|wall
echo Dump Device is $DUMPDEV
echo Logfile is $LOGFILE

# Make sure the log files are created. This is important if we use >>

touch $LOGFILE
touch $TEMPLOG

# Put some information in the log file.

echo >> $TEMPLOG
echo -n 'Backup for ' >> $LOGFILE
date +%m-%d-%y::%H:%M >> $LOGFILE
echo -n 'Performed by ' >> $LOGFILE
whoami >> $LOGFILE

# First rewind primes the device (usually returns error)
# Second rewind will rewind the tape and verify it is present.
mt -f $DUMPDEV rewind
mt -f $DUMPDEV rewind||exit 1

# Now dump the list of file systems and log the dump.

foreach SYSTEM ( $DUMPFILES )
  echo -n $SYSTEM" dump started - " >> $LOGFILE
  date +%H:%M >> $LOGFILE
  /etc/dump 0ubdsf 96 54000 5200 $DUMPDEV $SYSTEM || echo $SYSTEM" dump
  unsuccessful" >> $LOGFILE && touch $FAILFILE && echo $SYSTEM" dump
  unsuccessful" >> $FAILFILE echo -n $SYSTEM" dump finished - " >> $LOGFILE date
  +%H:%M >> $LOGFILE
end

# Now do the tar list. I use this for a couple of NFS mounted directories.

foreach SYSTEM ( $TARFILES )
  echo -n $SYSTEM" tar started - " >> $LOGFILE
  date +%H:%M >> $LOGFILE
  tar cvf $DUMPDEV $SYSTEM || echo $SYSTEM" tar unsuccessful" >> $LOGFILE &&
  touch $FAILFILE && echo $SYSTEM" tar unsuccessful" >> $FAILFILE echo -n
  $SYSTEM" tar finished - " >> $LOGFILE date +%H:%M >> $LOGFILE
end

# Show the end of backup log.

echo -n '-- end backup for ' >> $LOGFILE
date +%m-%d-%y::%H:%M >> $LOGFILE

# Now eject the tape

mt -f $DUMPDEV offline

# Now move the temporary log file to the end of our permanent log file.

cat $LOGFILE >> $TEMPLOG

# Setup ownerships to ensure that the operator can do backups next time
# This is because they might get changed to "root" during cron backups.

chgrp operator $TEMPLOG
chmod 664 $TEMPLOG

# Send the temporary log file to the operators (an alias) and remove it.

cat $LOGFILE|Mail -s Backup operators
rm $LOGFILE

Here is the backup script I received from Glen Satchell. Glen works
for a consulting firm and said he got tired of writing a new script
for each customer. He came up with this generic script that works on
SunOS 4.x and Solaris 2.x systems without changes. The script
automatically scans through /etc/fstab or /etc/vfstab and finds all the
local filesystems and then dumps them to tape. At the end of the script
the tape is ejected. Glen says the only mods required are to select the
correct options line depending on the type of tape drive you have. The
script is called from cron using an entry such as:

0 23 * * 1-5 ufsdumpall /dev/rmt/0n 2>&1 | mailx -s 'system backup' root

#!/bin/sh
#
# generic backup script for SunOS and Solaris
# Glenn Satchell, Uniq Professional Services
# 28 September 1995
#
PATH=/usr/bin:/usr/etc:/usr/sbin;
export PATH
OS=`uname -r`

case "$OS" in
4.1.*)
   TAPE=${1:-/dev/nrst0}
   # select one set of dump options
   dump_opts="0udsbf 54000 6000 126" # Exabyte 8200
   #dump_opts="0udsbf 54000 13000 126" # Exabyte 8500
   #dump_opts="0udsbf 54000 25000 126" # Exabyte 8505
   #dump_opts="0udsbf 10000 10000 96" # 4mm DAT
   #dump_opts="0ucdstf 1000 700 18" # QIC-150

   cat /etc/fstab |
   while read dev mount type opts dump pass; do
      case $dev in
      '#'*) ;;
      *)
         case $type in
         4.2) dump $dump_opts $TAPE $mount ;;
         esac
         ;;
      esac
   done
   ;;

5.*)
   TAPE=${1:-/dev/rmt/0n}
   # select one set of dump options
   dump_opts="0ubf 126" # Exabyte
   #dump_opts="0ubf 96" # 4mm DAT

   cat /etc/vfstab |
   while read dev fsck mount type pass boot opts; do
      case $dev in
      '#'*) ;;
      *)
         case $type in
         ufs) ufsdump $dump_opts $TAPE $mount ;;
         esac
         ;;
      esac
   done
   ;;

*) echo "Sorry don't know how to back up version $OS" ;;
esac
mt -f $TAPE rewoffl
exit





This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:10:52 CDT