level-1 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/sh
  2. #
  3. # Run this script as root on the machine that has the tape drive, to make a
  4. # level-1 dump containing all files changed since the last full dump.
  5. #
  6. # If you give `now' as an argument, the dump is done immediately.
  7. # Otherwise, it waits until 1am.
  8. #
  9. # You must edit the file `backup-specs' to set the parameters for your site.
  10. # Insure `mail' is in PATH.
  11. PATH="/usr/ucb:${PATH}"
  12. export PATH
  13. if [ ! -w / ]; then
  14. echo "The backup must be run as root or else some files will fail to be dumped."
  15. exit 1
  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 '
  28. {
  29. hr = substr($4, 1, 2);
  30. mn = substr($4, 4, 2);
  31. if((hr + 0) < (spec + 0))
  32. print 3600 * (spec - hr) - 60 * mn;
  33. else
  34. print 3600 * (spec + (24 - hr)) - 60 * mn;
  35. }' spec=\"${spec}\"`"
  36. clear
  37. # Put your favorite message here. We just want a screenful of obnoxious
  38. # caps warning people from messing with the dedicated terminal.
  39. awk 'BEGIN {
  40. for (i = 0; i < 30; i++)
  41. print " D O N O T T O U C H T H I S T E R M I N A L !!!!!"
  42. }' /dev/null
  43. sleep "${pausetime}"
  44. fi
  45. # start doing things
  46. # Put startdate in the subject line of mailed report, since if it happens
  47. # to run longer than 24 hours (as may be the case if someone forgets to put
  48. # in the next volume of the tape in adequate time), the backup date won't
  49. # appear too misleading.
  50. startdate="`date`"
  51. here="`pwd`"
  52. # Logfile name should be in the form ``log-1993-03-18-full''
  53. # i.e. year-month-date. This format is useful for sorting by name.
  54. LOGFILE=log-`date | awk '
  55. BEGIN {
  56. d["Jan"] = "01"; d["Feb"] = "02"; d["Mar"] = "03";
  57. d["Apr"] = "04"; d["May"] = "05"; d["Jun"] = "06";
  58. d["Jul"] = "07"; d["Aug"] = "08"; d["Sep"] = "09";
  59. d["Oct"] = "10"; d["Nov"] = "11"; d["Dec"] = "12";
  60. }
  61. {
  62. if ($3 < 10)
  63. $3 = "0" $3;
  64. print $6 "-" d[$2] "-" $3;
  65. }'`-level-1
  66. HOST="`hostname | sed -e 's/\..*//'`"
  67. TAR_PART1="/usr/local/bin/tar -c --multi-volume --one-file-system --block=${BLOCKING} --sparse --volno-file=${VOLNO_FILE}"
  68. # Only use --info-script if DUMP_REMIND_SCRIPT was defined in backup-specs
  69. if [ "x${DUMP_REMIND_SCRIPT}" != "x" ]; then
  70. TAR_PART1="${TAR_PART1} --info-script=${DUMP_REMIND_SCRIPT}"
  71. fi
  72. # Make sure the log file did not already exist. Create it.
  73. if [ -f "${LOGFILE}" ] ; then
  74. echo "Log file ${LOGFILE} already exists."
  75. exit 1
  76. else
  77. touch "${LOGFILE}"
  78. fi
  79. # Caveat: Some version of `mt' require `-t', not `-f'.
  80. mt -f "${TAPE_FILE}" rewind
  81. rm -f "${VOLNO_FILE}"
  82. set - "${BACKUP_DIRS}"
  83. while [ $# -ne 0 ] ; do
  84. host="`echo \"${1}\" | sed -e 's/:.*$//'`"
  85. fs="`echo \"${1}\" | sed -e 's/^.*://'`"
  86. date="`date`"
  87. fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
  88. # This filename must be absolute; it is opened on the machine that runs tar.
  89. TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
  90. TAR_PART3="--label='level 1 backup of ${fs} on ${host} at ${date}' -C ${fs} ."
  91. echo "Backing up ${1} at ${date}" | tee -a "${LOGFILE}"
  92. echo "Last full dump on this filesystem:" | "tee -a ${LOGFILE}"
  93. if [ "z${host}" != "z${HOST}" ] ; then
  94. rsh "${host}" "ls -l /etc/tar-backup/${fsname}.level-0; \
  95. cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1" 2>&1 \
  96. | tee -a "${LOGFILE}"
  97. else
  98. ls -l /etc/tar-backup/${fsname}.level-0 2>&1 | tee -a ${LOGFILE}
  99. cp /etc/tar-backup/${fsname}.level-0 /etc/tar-backup/temp.level-1 2>&1 | tee -a ${LOGFILE}
  100. fi
  101. # Actually back things up.
  102. if [ "z${host}" != "z${HOST}" ] ; then
  103. rsh "${host}" ${TAR_PART1} -f ${HOST}:${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} 2>&1 \
  104. | tee -a "${LOGFILE}"
  105. else
  106. # Using `sh -c exec' causes nested quoting and shell substitution
  107. # to be handled here in the same way rsh handles it.
  108. sh -c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3}" 2>&1 | tee -a "${LOGFILE}"
  109. fi
  110. # This doesn't presently work, of course, because $? is set to the exit
  111. # status of the last thing in the pipeline of the previous command,
  112. # namely `tee'. We really want the exit status of the sh command
  113. # running tar, but getting this seems to be nontrivial. --friedman
  114. if [ $? -ne 0 ] ; then
  115. echo "Backup of ${1} failed." | tee -a "${LOGFILE}"
  116. # I'm assuming that the tar will have written an empty
  117. # file to the tape, otherwise I should do a cat here.
  118. else
  119. if [ ${HOST} != ${host} ] ; then
  120. rsh ${host} mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/${fsname}.level-1 2>&1 \
  121. | tee -a ${LOGFILE}
  122. else
  123. mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/${fsname}.level-1 2>&1 \
  124. | tee -a ${LOGFILE}
  125. fi
  126. fi
  127. ${TAPE_STATUS} | tee -a "${LOGFILE}"
  128. sleep 60
  129. shift
  130. done
  131. # Dump any individual files requested.
  132. if [ "x${BACKUP_FILES}" != "x" ] ; then
  133. date="`date`"
  134. TAR_PART2="--listed=/etc/tar-backup/temp.level-1"
  135. TAR_PART3="--label='Incremental backup of miscellaneous files at ${date}'"
  136. echo "Backing up miscellaneous files at ${date}" | tee -a "${LOGFILE}"
  137. echo "Last full dump of these files:" | tee -a "${LOGFILE}"
  138. ls -l /etc/tar-backup/misc.level-0 2>&1 | tee -a "${LOGFILE}"
  139. rm -f /etc/tar-backup/temp.level-1 2>&1 | tee -a "${LOGFILE}"
  140. cp /etc/tar-backup/misc.level-0 /etc/tar-backup/temp.level-1 2>&1 | tee -a "${LOGFILE}"
  141. # Using `sh -c exec' causes nested quoting and shell substitution
  142. # to be handled here in the same way rsh handles it.
  143. sh -c "exec ${TAR_PART1} -f ${TAPE_FILE} ${TAR_PART2} ${TAR_PART3} ${BACKUP_FILES}" 2>&1 \
  144. | tee -a "${LOGFILE}"
  145. # This doesn't presently work, of course, because $? is set to the exit
  146. # status of the last thing in the pipeline of the previous command,
  147. # namely `tee'. We really want the exit status of the sh command
  148. # running tar, but getting this seems to be nontrivial. --friedman
  149. if [ $? -ne 0 ] ; then
  150. echo "Backup of miscellaneous files failed." | tee -a "${LOGFILE}"
  151. # I'm assuming that the tar will have written an empty
  152. # file to the tape, otherwise I should do a cat here.
  153. else
  154. mv -f /etc/tar-backup/temp.level-1 /etc/tar-backup/misc.level-1 2>&1 | tee -a "${LOGFILE}"
  155. fi
  156. ${TAPE_STATUS} | tee -a "${LOGFILE}"
  157. else
  158. echo "No miscellaneous files specified" | tee -a "${LOGFILE}"
  159. fi
  160. # Caveat: some versions of `mt' use `-t' instead of `-f'.
  161. mt -f "${TAPE_FILE}" rewind
  162. mt -f "${TAPE_FILE}" offl
  163. echo "Sending the dump log to ${ADMINISTRATOR}"
  164. mail -s "Results of backup started ${startdate}" ${ADMINISTRATOR} < "${LOGFILE}"
  165. # eof