level-0 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 or else some files will fail to be dumped.
  13. exit 1
  14. else
  15. false
  16. fi
  17. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  18. . ./backup-specs
  19. # Maybe sleep until around specified or default hour.
  20. #
  21. if [ "${1}" != "now" ]; then
  22. if [ "${1}x" != "x" ]; then
  23. spec="${1}"
  24. else
  25. spec="${BACKUP_HOUR}"
  26. fi
  27. pausetime=`date | awk '{hr=substr($4,1,2);\\
  28. mn=substr($4,4,2);\\
  29. if((hr+0)<(spec+0))\\
  30. print 3600*(spec-hr)-60*mn;\\
  31. else\\
  32. print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  33. clear
  34. cat ./dont_touch
  35. sleep ${pausetime}
  36. fi
  37. # start doing things
  38. here=`pwd`
  39. LOGFILE=log-`date | awk '{print $2 "-" $3 "-" $6}'`-full
  40. HOST=`hostname | sed 's/\..*//'`
  41. TAR_PART1="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
  42. # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
  43. if [ x != "x${DUMP_REMIND_SCRIPT}" ]; then
  44. TAR_PART1="${TAR_PART1} --info-script=${DUMP_REMIND_SCRIPT}"
  45. fi
  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. # This doesn't presently work, of course, because $? is set to the exit
  78. # status of the last thing in the pipeline of the previous command,
  79. # namely `tee'. We really want the exit status of the sh command
  80. # running tar, but getting this seems to be nontrivial. --friedman
  81. if [ $? -ne 0 ] ; then
  82. echo Backup of ${1} failed. | tee -a ${LOGFILE}
  83. # I'm assuming that the tar will have written an empty
  84. # file to the tape, otherwise I should do a cat here.
  85. else
  86. if [ ${HOST} != ${host} ] ; then
  87. rsh ${host} "mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/${fsname}.level-0" 2>&1 | tee -a ${LOGFILE}
  88. else
  89. mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/${fsname}.level-0 2>&1 | tee -a ${LOGFILE}
  90. fi
  91. fi
  92. ${TAPE_STATUS} | tee -a ${LOGFILE}
  93. sleep 60
  94. shift
  95. done
  96. # Dump any individual files requested.
  97. if [ x != "x${BACKUP_FILES}" ] ; then
  98. date=`date`
  99. TAR_PART2="--listed=/etc/tar-backup/temp.level-0"
  100. TAR_PART3="--label='Full backup of miscellaneous files at ${date}'"
  101. mkdir /etc/tar-backup > /dev/null 2>&1
  102. rm -f /etc/tar-backup/temp.level-0
  103. echo Backing up miscellaneous files at ${date} | tee -a ${LOGFILE}
  104. # Using `sh -c exec' causes nested quoting and shell substitution
  105. # to be handled here in the same way rsh handles it.
  106. sh -c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} \
  107. ${BACKUP_FILES}" 2>&1 | tee -a ${LOGFILE}
  108. # This doesn't presently work, of course, because $? is set to the exit
  109. # status of the last thing in the pipeline of the previous command,
  110. # namely `tee'. We really want the exit status of the sh command
  111. # running tar, but getting this seems to be nontrivial. --friedman
  112. if [ $? -ne 0 ] ; then
  113. echo Backup of miscellaneous files failed. | tee -a ${LOGFILE}
  114. # I'm assuming that the tar will have written an empty
  115. # file to the tape, otherwise I should do a cat here.
  116. else
  117. mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0 2>&1 | tee -a ${LOGFILE}
  118. fi
  119. ${TAPE_STATUS} | tee -a ${LOGFILE}
  120. else
  121. echo No miscellaneous files specified | tee -a ${LOGFILE}
  122. false
  123. fi
  124. mt -f ${TAPE_FILE} rewind
  125. mt -f ${TAPE_FILE} offl
  126. echo Sending the dump log to ${ADMINISTRATOR}
  127. cat ${LOGFILE} | sed -f logfile.sed > ${LOGFILE}.tmp
  128. /usr/ucb/mail -s "Results of backup on `date`" ${ADMINISTRATOR} < ${LOGFILE}.tmp
  129. rm -f ${LOGFILE}.tmp