home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gtak212.zip / 1.10 / level-0 < prev    next >
Text File  |  1992-09-02  |  4KB  |  144 lines

  1. #!/bin/sh
  2. #
  3. # Run this script as root on the machine that has the tape drive, to make a
  4. # full dump.
  5. #
  6. # If you give `now' as an argument, the dump is done immediately.
  7. # Otherwise, it waits until 1am, or until the hour given as argument.
  8. # Specify the hour as a number from 0 to 23.
  9. #
  10. # You must edit the file `backup-specs' to set the parameters for your site.
  11.  
  12. if [ ! -w / ]; then
  13.    echo The backup must be run as root,
  14.    echo or else some files will fail to be dumped.
  15.    exit 1
  16. else
  17.    false
  18. fi
  19.  
  20. # This is undesirable -- rms.
  21. # rsh albert /usr/local/adm/motd-backup-start
  22.  
  23. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  24. . ./backup-specs
  25.  
  26. # Maybe sleep until around specified or default hour.
  27. #
  28. if [ "$1" != "now" ]; then
  29.    if [ "$1"x != x ]; then
  30.       spec=$1
  31.    else
  32.       spec=$BACKUP_HOUR
  33.    fi
  34.    pausetime=`date | awk '{hr=substr($4,1,2);\\
  35.       mn=substr($4,4,2);\\
  36.       if((hr+0)<spec)\\
  37.          print 3600*(spec-hr)-60*mn;\\
  38.       else\\
  39.          print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  40.    clear
  41.    cat ./dont_touch
  42.    sleep $pausetime
  43. fi
  44.  
  45. # start doing things
  46.  
  47. here=`pwd`
  48. LOGFILE=log-`date | awk '{print $2 "-" $3 "-" $6}'`-full
  49. HOST=`hostname | sed 's/\..*//'`
  50. TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING +sparse"
  51. #TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING "
  52.  
  53. # Make sure the log file did not already exist.  Create it.
  54.  
  55. if [ -f $LOGFILE ] ; then
  56.    echo Log file $LOGFILE already exists.
  57.    exit 1
  58. else
  59.    touch $LOGFILE
  60. fi
  61.  
  62. mt -f $TAPE_FILE rewind
  63.  
  64. set $BACKUP_DIRS
  65. while [ $# -ne 0 ] ; do
  66.    host=`echo $1 | sed 's/:.*$//'`
  67.    fs=`echo $1 | sed 's/^.*://'`
  68.    date=`date`
  69.    fsname=`echo $1 | sed 's/\//:/g'`
  70.  
  71.    TAR_PART2="+listed=/etc/tar-backup/temp.level-0"
  72.    TAR_PART3="+label='Full backup of $fs on $host at $date' -C $fs ."
  73.  
  74.    echo Backing up $1 at $date | tee -a $LOGFILE
  75.  
  76.    # Actually back things up.
  77.  
  78.    if [ $HOST != $host ] ; then
  79.       rsh $host "mkdir /etc/tar-backup 2>&1/dev/null; \
  80.     rm -f /etc/tar-backup/temp.level-0; \
  81.           $TAR_PART1 -f $HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3" \
  82.      2>&1 | tee -a $LOGFILE
  83.    else
  84.       mkdir /etc/tar-backup 2>&1/dev/null
  85.       rm -f /etc/tar-backup/temp.level-0
  86. # Using `sh -c exec' causes nested quoting and shell substitution
  87. # to be handled here in the same way rsh handles it.
  88.       sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3" 2>&1 | tee -a $LOGFILE
  89.    fi
  90.    if [ $? -ne 0 ] ; then
  91.       echo Backup of $1 failed. | tee -a $LOGFILE
  92.       # I'm assuming that the tar will have written an empty
  93.       # file to the tape, otherwise I should do a cat here.
  94.    else
  95.       if [ $HOST != $host ] ; then
  96.     rsh $host mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
  97.       else
  98.         mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
  99.       fi
  100.    fi
  101.    $TAPE_STATUS | tee -a $LOGFILE
  102.    sleep 60
  103.    shift
  104. done
  105.  
  106. # Dump any individual files requested.
  107.  
  108. if [ x != "x$BACKUP_FILES" ] ; then
  109.    date=`date`
  110.  
  111.    TAR_PART2="+listed=/etc/tar-backup/temp.level-0"
  112.    TAR_PART3="+label='Full backup of miscellaneous files at $date'"
  113.  
  114.    mkdir /etc/tar-backup 2>&1/dev/null
  115.    rm -f /etc/tar-backup/temp.level-0
  116.  
  117.    echo Backing up miscellaneous files at $date | tee -a $LOGFILE
  118. # Using `sh -c exec' causes nested quoting and shell substitution
  119. # to be handled here in the same way rsh handles it.
  120.    sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3 \
  121.     $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  122.    if [ $? -ne 0 ] ; then
  123.      echo Backup of miscellaneous files failed. | tee -a $LOGFILE
  124.      # I'm assuming that the tar will have written an empty
  125.      # file to the tape, otherwise I should do a cat here.
  126.    else
  127.      mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0 2>&1 | tee -a $LOGFILE
  128.    fi
  129.    $TAPE_STATUS | tee -a $LOGFILE
  130. else
  131.    echo No miscellaneous files specified | tee -a $LOGFILE
  132.    false
  133. fi
  134.  
  135. mt -f $TAPE_FILE rewind
  136. mt -f $TAPE_FILE offl
  137.  
  138. echo Sending the dump log to $ADMINISTRATOR
  139. cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  140. /usr/ucb/mail -s "Results of backup on `date`" $ADMINISTRATOR < $LOGFILE.tmp
  141.  
  142. # This is undesirable -- rms.
  143. #rsh albert /usr/local/adm/motd-backup-done &
  144.