level-0 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 --atime-preserve"
  45. # Make sure the log file did not already exist. Create it.
  46. if [ -f $LOGFILE ] ; then
  47. echo Log file $LOGFILE already exists.
  48. exit 1
  49. else
  50. touch $LOGFILE
  51. fi
  52. mt -f $TAPE_FILE rewind
  53. rm $VOLNO_FILE
  54. set $BACKUP_DIRS
  55. while [ $# -ne 0 ] ; do
  56. host=`echo $1 | sed 's/:.*$//'`
  57. fs=`echo $1 | sed 's/^.*://'`
  58. date=`date`
  59. fsname=`echo $1 | sed 's/\//:/g'`
  60. TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
  61. TAR_PART3="--label='Full backup of $fs on $host at $date' -C $fs ."
  62. echo Backing up $1 at $date | tee -a $LOGFILE
  63. # Actually back things up.
  64. if [ $HOST != $host ] ; then
  65. # Removed 2>&1/dev/null cruft since that's incorrect sh syntax.
  66. rsh $host mkdir /etc/tar-backup > /dev/null 2>&1
  67. rsh $host rm -f /etc/tar-backup/temp.level-0
  68. rsh $host $TAR_PART1 -f $HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3 2>&1 | tee -a $LOGFILE
  69. else
  70. mkdir /etc/tar-backup > /dev/null 2>&1
  71. rm -f /etc/tar-backup/temp.level-0
  72. # Using `sh -c exec' causes nested quoting and shell substitution
  73. # to be handled here in the same way rsh handles it.
  74. sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3" 2>&1 | tee -a $LOGFILE
  75. fi
  76. if [ $? -ne 0 ] ; then
  77. echo Backup of $1 failed. | tee -a $LOGFILE
  78. # I'm assuming that the tar will have written an empty
  79. # file to the tape, otherwise I should do a cat here.
  80. else
  81. if [ $HOST != $host ] ; then
  82. rsh $host "mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0" 2>&1 | tee -a $LOGFILE
  83. else
  84. mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
  85. fi
  86. fi
  87. $TAPE_STATUS | tee -a $LOGFILE
  88. sleep 60
  89. shift
  90. done
  91. # Dump any individual files requested.
  92. if [ x != "x$BACKUP_FILES" ] ; then
  93. date=`date`
  94. TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
  95. TAR_PART3="--label='Full backup of miscellaneous files at $date'"
  96. mkdir /etc/tar-backup > /dev/null 2>&1
  97. rm -f /etc/tar-backup/temp.level-0
  98. echo Backing up miscellaneous files at $date | tee -a $LOGFILE
  99. # Using `sh -c exec' causes nested quoting and shell substitution
  100. # to be handled here in the same way rsh handles it.
  101. sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3 \
  102. $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  103. if [ $? -ne 0 ] ; then
  104. echo Backup of miscellaneous files failed. | tee -a $LOGFILE
  105. # I'm assuming that the tar will have written an empty
  106. # file to the tape, otherwise I should do a cat here.
  107. else
  108. mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0 2>&1 | tee -a $LOGFILE
  109. fi
  110. $TAPE_STATUS | tee -a $LOGFILE
  111. else
  112. echo No miscellaneous files specified | tee -a $LOGFILE
  113. false
  114. fi
  115. mt -f $TAPE_FILE rewind
  116. mt -f $TAPE_FILE offl
  117. echo Sending the dump log to $ADMINISTRATOR
  118. cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  119. /usr/ucb/mail -s "Results of backup on `date`" $ADMINISTRATOR < $LOGFILE.tmp
  120. # This is undesirable -- rms.
  121. #rsh albert /usr/local/adm/motd-backup-done &