level-1 4.6 KB

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