level-0 4.3 KB

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