home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / hp / 13176 < prev    next >
Encoding:
Text File  |  1992-11-19  |  23.7 KB  |  1,076 lines

  1. Newsgroups: comp.sys.hp
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!dhhalden.no!fenris.dhhalden.no!eskilb
  3. From: eskilb@dhhalden.no (Eskil Brun)
  4. Subject: Free backup scripts...
  5. Message-ID: <eskilb.722251094@fenris.dhhalden.no>
  6. Summary: Suite of shell scripts to run backup
  7. Keywords: backup script
  8. Organization: Ostfold College
  9. Date: Fri, 20 Nov 1992 09:18:14 GMT
  10. Lines: 1064
  11.  
  12. Hi. I've seen many postings about how to run backups.
  13.  
  14. I've included the scripts we use here to run backup. I wrote these to
  15. use cpio, dd and remote shell. With a little hacking, these scripts
  16. should run on anything that supports no-rewind, berkeley-close tape
  17. devices. You should be able to use any kind of archive program that
  18. can write to stdout. You would have to modify both the backup.sh and
  19. restore.sh scripts to do this. Remote shell access for root is
  20. required in ~root/.rhosts.
  21.  
  22. We use 4 DDS dat drives connected to HP9000/720 and run compression on
  23. the 720 computers. On the local disks of the computer with the tape
  24. backup rate is ~14+ Megabytes per minute. The average rate is ~10
  25. MB/M. Your mileage will vary according to the speed of your tape
  26. drives, your computers and your disks. I found that compressing data
  27. on a HP9000/720 computer before writing to tape is actually faster
  28. than writing directly to tape. (-:
  29.  
  30. These scripts are NOT supported by me and I release them on an "as-is"
  31. basis.  If you find them useful or have improvements, I'll be glad to
  32. hear from you. If you do not understand the shell scripts or if you do
  33. not like the way they are written, that's your problem.
  34.  
  35. I've also included a little perl script to make summaries of the type
  36. below.
  37.  
  38. I take no responsibility for whatever happens if you use these
  39. scripts.
  40.  
  41. If you are resonably well versed in /bin/sh, you should have no
  42. problem adopting these scripts to your needs.
  43.  
  44. Happy hacking...
  45. :-)
  46.  
  47. P.s: Shell scripts are included in the shar archive is included below
  48.      after the summary from the perl script.
  49.  
  50. +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  51.  Eskil Brun                     InterNet: eskil.brun@hrp.no
  52.  Systems Administrator          DingaLingNet: +47 9 183100
  53.  OECD Halden Reactor Project    FaxNet: +47 9 183103
  54.  Norway                         SnailMailNet: P.O. Box 173, N-1751 Halden
  55. +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  56.  
  57. Here is a summary of last night's backup:
  58.  
  59. --- chew here ---
  60.  
  61. Summary of /users/root/backup/backup-log on klaus chuck sleipner volt
  62.  
  63.  
  64. MbBU  = Megabytes backed up.
  65. MBWT  = Megabytes written to tape.
  66. Comp% = % size of data after compression. 
  67. Time  = Time used for backup.
  68. KB/S  = Kilobytes Per Second.
  69. MB/M  = Megabytes Per Minute.
  70.  
  71.  
  72. ======================================================================
  73.                       SUMMARY OF BACKUP FROM klaus
  74. ----------------------------------------------------------------------
  75. Hostname      MbBU   MbWT Comp%   Time KB/S   MB/M     Date
  76.  
  77. snapp          256    102   40%   0:27  162   9.50     Fri Nov 20
  78. klara          202     91   45%   0:23  150   8.77     Fri Nov 20
  79. guffen         188     79   42%   0:21  153   8.94     Fri Nov 20
  80. anton          121     62   51%   0:14  147   8.62     Fri Nov 20
  81. skrue           19     11   55%   0:06   55   3.24     Fri Nov 20
  82. pluto           24     12   52%   0:04  101   5.89     Fri Nov 20
  83. storeulv       151     63   42%   0:28   92   5.40     Fri Nov 20
  84. lilleulv       153     80   52%   0:16  164   9.59     Fri Nov 20
  85. klaus           38     19   51%   0:04  161   9.43     Fri Nov 20
  86. doffen          40     20   50%   0:04  171  10.01     Fri Nov 20
  87. dole            44     22   51%   0:05  149   8.73     Fri Nov 20
  88. bingen         436    226   52%   0:35  213  12.46     Fri Nov 20
  89. ----------------------------------------------------------------------
  90. TOTAL/AVG     1671    787   47%   3:07  153   8.94
  91. ======================================================================
  92.  
  93.  
  94. ======================================================================
  95.                       SUMMARY OF BACKUP FROM chuck
  96. ----------------------------------------------------------------------
  97. Hostname      MbBU   MbWT Comp%   Time KB/S   MB/M     Date
  98.  
  99. chuck          307    113   37%   0:26  201  11.80     Fri Nov 20
  100. steve          701    296   42%   2:06   95   5.56     Fri Nov 20
  101. ----------------------------------------------------------------------
  102. TOTAL/AVG     1008    409   41%   2:32  113   6.63
  103. ======================================================================
  104.  
  105.  
  106. ======================================================================
  107.                     SUMMARY OF BACKUP FROM sleipner
  108. ----------------------------------------------------------------------
  109. Hostname      MbBU   MbWT Comp%   Time KB/S   MB/M     Date
  110.  
  111. sleipner       681    193   28%   0:39  298  17.46     Fri Nov 20
  112. draugen        125     57   46%   0:29   73   4.30     Fri Nov 20
  113. oseberg        153     39   26%   0:13  201  11.79     Fri Nov 20
  114. brage          498    114   23%   0:44  193  11.32     Fri Nov 20
  115. ----------------------------------------------------------------------
  116. TOTAL/AVG     1457    403   28%   2:05  199  11.65
  117. ======================================================================
  118.  
  119.  
  120. ======================================================================
  121.                       SUMMARY OF BACKUP FROM volt
  122. ----------------------------------------------------------------------
  123. Hostname      MbBU   MbWT Comp%   Time KB/S   MB/M     Date
  124.  
  125. volt          1551    850   55%   1:48  245  14.36     Fri Nov 20
  126. chris          291     87   30%   0:33  151   8.82     Fri Nov 20
  127. thomas         619    251   41%   0:53  199  11.69     Fri Nov 20
  128. uran            91     36   40%   0:07  222  12.98     Fri Nov 20
  129. ----------------------------------------------------------------------
  130. TOTAL/AVG     2553   1224   48%   3:21  217  12.70
  131. ======================================================================
  132.  
  133. ======================================================================
  134.                       TOTAL/AVG OF ALL BACKUPS
  135.   MbBU   MbWT Comp%   Time KB/S   MB/M
  136.  
  137.   6688   2824   42%  11:05  172  10.06
  138. ======================================================================
  139.  
  140. --- chew here ---
  141.  
  142.  
  143. # This is a shell archive.  Remove anything before this line,
  144. # then unpack it by saving it in a file and typing "sh file".
  145. #
  146. # Wrapped by Eskil Brun <eskilb@chuck> on Fri Nov 20 10:05:38 1992
  147. #
  148. # This archive contains:
  149. #    backup    
  150. #
  151.  
  152. LANG=""; export LANG
  153. PATH=/bin:/usr/bin:$PATH; export PATH
  154.  
  155. echo mkdir - backup
  156. mkdir backup
  157.  
  158. echo x - backup/backup.sh
  159. cat >backup/backup.sh <<'@EOF'
  160. #/bin/sh
  161. # Backup script...
  162.  
  163. # Dirs to backup
  164. dirs="
  165.     ./etc
  166.     ./usr/spool/lp
  167.     ./prj
  168.     ./users
  169.     ./u[0-9]*
  170.     ./disks
  171.     ./usr/contrib"
  172.  
  173. echo Backing up $dirs >&2
  174.  
  175. #Find files and archive them.
  176. cd /
  177. find `echo $dirs` -fsonly hfs -print |cpio -Bo
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. @EOF
  187.  
  188. chmod 755 backup/backup.sh
  189.  
  190. echo x - backup/catindex.sh
  191. cat >backup/catindex.sh <<'@EOF'
  192. #!/bin/sh
  193.  
  194.  
  195. #######################################################################
  196. # IFE DDS Tape backup...
  197. #     getindex script
  198. #
  199. # Author: Eskil Brun
  200. #
  201. #    wind to end of tape and backspace to read index file
  202. #    cat it to STDOUT
  203. #
  204. #######################################################################
  205.  
  206.  
  207. ##################################################
  208. # Make sure Search Path is correct.
  209. PATH="/bin:/usr/bin:/etc"
  210. export PATH
  211.  
  212.  
  213.  
  214.  
  215. ##################################################
  216. # Assumptions...
  217.  
  218. TAPE=/dev/bdds                # Must be raw, Berkeley, no rewind style DDS.
  219.  
  220.  
  221. ##################################################
  222. # Functions.....
  223.  
  224.  
  225. ####################
  226. # eod winds to the end of tape
  227.  
  228. eod()
  229. {
  230.     if [ `uname` = 'HP-UX' ]
  231.     then
  232.         OSVER=` uname -r |sed -e "s/[.A-Za-z]//g" -e "s/^0//" -e "s/00*$//"`
  233.         
  234.         case $OSVER in
  235.             7*)
  236.                 true        # Reset $?
  237.                 while [ $? = 0 ]
  238.                 do
  239.                     mt -t $TAPE fsf 1 >/dev/null 2>&1
  240.                 done
  241.                 ;;
  242.             
  243.             8*)
  244.                 mt -t $TAPE eod
  245.                 ;;
  246.  
  247.             *)
  248.                 echo $0 : Error\! eod\(\) must be rewritten for `uname` `uname -r`.
  249.                 exit 0
  250.                 ;;
  251.         esac
  252.  
  253.     else
  254.     
  255.         echo $0 : Error\! eod\(\) must be rewritten for `uname` `uname -r`.
  256.         exit 0
  257.     fi
  258. }
  259.  
  260. ####################
  261. # Clean up function...
  262.  
  263. do_cleanup()
  264. {
  265.     echo Cleaning Lady is here... Hum-tidum...
  266. }
  267.  
  268.  
  269. ####################
  270. # Stop on error function...
  271. stop_on_error()
  272. {
  273.     if [ $? != 0 ]
  274.     then
  275.         echo Woops. An error occured while $*
  276.         do_cleanup
  277.         exit 2
  278.     fi
  279. }
  280.  
  281.  
  282.  
  283. cat_index_file()
  284. {
  285.     # Rewind Tape
  286.     mt -t $TAPE rew    >/dev/null 2>&1
  287.  
  288.     eod
  289.     
  290.     # Now, Position tape at index file
  291.     mt -t $TAPE bsf 3    || stop_on_error Backspacing 3 filemarks to INDEX-file.
  292.     mt -t $TAPE fsf 1    || stop_on_error Forward Spacing to INDEX-file
  293.     cat $TAPE        || stop_on_error Writing INDEX file STDOUT from tape.
  294. }
  295.  
  296.  
  297.  
  298. ##################################################
  299. # Main part 
  300.  
  301.  
  302. cat_index_file
  303. @EOF
  304.  
  305. chmod 775 backup/catindex.sh
  306.  
  307. echo x - backup/master.sh
  308. cat >backup/master.sh <<'@EOF'
  309. #!/bin/sh
  310.  
  311.  
  312. #######################################################################
  313. # IFE DDS Tape backup...
  314. #     Master script
  315. #
  316. # Author: Eskil Brun
  317. #
  318. #     The $BACKUPMASTER starts a remote shell script on the
  319. #    $NODE, running backup. The script run on the $NODE is assumed
  320. #    to write backup data to STDOUT and messages to STDERR
  321. #
  322. #    The $BACKUPMASTER writes an INDEX at the end of the tape
  323. #    to know which hosts have backups in which position.
  324. #
  325. #######################################################################
  326.  
  327.  
  328. ##################################################
  329. # Make sure Search Path is correct.
  330. PATH="/bin:/usr/bin:/etc"
  331. export PATH
  332.  
  333. trap "echo Caught a TERM\(15\) signal. I\'m dying.; exit 1" 15
  334.  
  335.  
  336. ##################################################
  337. # Assumptions...
  338.  
  339. TAPE=/dev/bdds                    # Must be raw, Berkeley, no rewind style DDS.
  340. CHUNKSIZE=60k                    # Tape Block size for dd(1)
  341. INDEXFILE=/users/root/backup/tape-index        # INDEX file name.
  342. LOGFILE=/users/root/backup/backup-log        # Backup log output file.
  343. SCRIPTSDIR=/users/root/backup            # Where we keep backup scripts...
  344. COMPRESS="no"                    # Whether we should compress data
  345.  
  346. ##################################################
  347. # List of computers to take backup...
  348.  
  349. # Master backup computers...
  350. MASTERS="chuck sleipner volt"
  351.  
  352. # Computers to take backup on chuck's tape
  353. chuck_NODES="chuck steve"
  354. chuck_COMPRESS="yes"
  355.  
  356. # Computers to take backup on sleipner's tape
  357. sleipner_NODES="sleipner draugen oseberg brage"
  358. sleipner_COMPRESS="yes"
  359.  
  360. # Computers to take backup on volt's tape
  361. volt_NODES="volt chris thomas uran"
  362. volt_COMPRESS="yes"
  363.  
  364. ##################################################
  365. # Functions.....
  366.  
  367.  
  368. ####################
  369. # Clean up function...
  370.  
  371. do_cleanup()
  372. {
  373.     echo Doing Cleanup \(Nothing, Really\).
  374.     echo Right now, I think it\'s smart to quit\!
  375.     kill -TERM $$
  376. }
  377.  
  378.  
  379. ####################
  380. # Stop on error function...
  381. stop_on_error()
  382. {
  383.     if [ $? != 0 ]
  384.     then
  385.         echo Woops. An error occured while $*
  386.         do_cleanup
  387.     fi
  388. }
  389.  
  390.  
  391. ####################
  392. # rewind tape function
  393.  
  394. rewind_tape()
  395. {
  396.     echo Rewinding Tape...
  397.     mt -t $TAPE rew     || stop_on_error Rewinding Tape.
  398. }
  399.  
  400.  
  401. output_to_tape()
  402. {
  403.     echo Writing DATA to tape >&2
  404.     # write compressed / uncompressed ??
  405.     if [ $COMPRESS = yes ]
  406.     then
  407.         compress | dd ibs=10k obs=$CHUNKSIZE of=$TAPE || stop_on_error Writing compressed DATA to tape
  408.         echo Wrote compressed DATA to tape
  409.     else
  410.         dd ibs=10k obs=$CHUNKSIZE of=$TAPE || stop_on_error Writing uncompressed DATA to tape
  411.         echo Wrote uncompressed DATA to tape
  412.     fi
  413. }
  414.  
  415.  
  416. ####################
  417. # eject tape function
  418.  
  419. eject_tape()
  420. {
  421.     echo Ejecting Tape
  422.     mt -t $TAPE offl || stop_on_error Rewinding and Ejecting Tape.
  423. }
  424.  
  425.  
  426.  
  427. ####################
  428. # bsdping emulates the bsd version of ping
  429. # usage: bsdping "host"
  430. # if "host" does not exist, bsdping return true!!
  431. # This is not really a serious bug for this script's use
  432.  
  433. bsdping()
  434. {
  435.     if [ `uname` = 'HP-UX' ]
  436.     then
  437.         OSVER=` uname -r |sed -e "s/[.A-Za-z]//g" -e "s/^0//" -e "s/00*$//"`
  438.  
  439.         case $OSVER in
  440.             7*)
  441.  
  442.                 if [ $# -eq 0 ] ;then
  443.                     return 2
  444.                 else
  445.                     RES=`ping $1 -n1 |grep -c '0 packets received'`
  446.                 return $RES
  447.                 fi
  448.                 ;;
  449.  
  450.             8*)
  451.                 if [ $# -eq 0 ] ;then
  452.                     return 2
  453.                 else
  454.                     RES=`ping $1 64 1 |grep -c '0 packets received'`
  455.                     return $RES
  456.                 fi
  457.                 ;;
  458.  
  459.             *)
  460.                 echo $0 : Error\! bsdping\(\) must be rewritten for `uname` `uname -r`.
  461.                 exit 0
  462.                 ;;
  463.         esac
  464.  
  465.     else
  466.  
  467.         echo $0 : Error\! bsdping\(\) must be rewritten for `uname` `uname -r`.
  468.         exit 0
  469.     fi
  470. }
  471.  
  472. # Test bsdping
  473. bsdping localhost
  474.  
  475.  
  476.  
  477. ##################################################
  478. # Main part
  479.  
  480.  
  481. # age LOGFILE. Be silent about it.
  482. mv $LOGFILE.4 $LOGFILE.5 >/dev/null 2>&1
  483. mv $LOGFILE.3 $LOGFILE.4 >/dev/null 2>&1
  484. mv $LOGFILE.2 $LOGFILE.3 >/dev/null 2>&1
  485. mv $LOGFILE.1 $LOGFILE.2 >/dev/null 2>&1
  486. mv $LOGFILE   $LOGFILE.1 >/dev/null 2>&1
  487.  
  488.  
  489. # Redirect stdout and stderr to logfile
  490. exec >$LOGFILE 2>&1
  491.  
  492.  
  493. trap HUP
  494.  
  495.  
  496.  
  497. # Check if We are a master computer...
  498.  
  499. MYNAME=`hostname |sed -e "s/\\..*//"`            # get hostname without domain
  500. for MASTER in $MASTERS
  501. do
  502.     [ $MYNAME = $MASTER ] && BACKUPMASTER=$MYNAME
  503. done
  504.  
  505. # If not, Nothing to do.
  506.  
  507. if [ "$BACKUPMASTER" = "" ]
  508. then
  509.     echo This Computer is not a BACKUPMASTER
  510.     echo Nothing to do...
  511.     exit 0
  512. fi
  513.  
  514. # Otherwise, Do backup...
  515.  
  516.  
  517. echo Master Backup Script started at `date`
  518.  
  519.  
  520. # assure bsdping can be used with this script...
  521. echo Checking bsdping\(\)
  522. bsdping localhost
  523.  
  524. echo Removing INDEX file.
  525. rm -f $INDEXFILE
  526.  
  527. echo Creating New INDEX file.
  528. cat /dev/null >$INDEXFILE
  529.  
  530. echo Getting node names to run backup from.
  531.  
  532. BACKUP_NODES=`eval echo '$'${BACKUPMASTER}_NODES`
  533.  
  534. if [ "$BACKUP_NODES" = "" ]
  535. then
  536.     echo No nodes to take backup from.
  537.     echo Nothing to do.
  538.     exit 0
  539. else
  540.     echo $BACKUPMASTER takes backup of $BACKUP_NODES
  541. fi
  542.  
  543.  
  544. COMPRESS=`eval echo '$'${BACKUPMASTER}_COMPRESS`
  545.  
  546.  
  547. if [ $COMPRESS = yes ]
  548. then
  549.     echo $BACKUPMASTER will compress data before writing to tape
  550.     COMP="COMPRESSED"
  551. else
  552.     echo $BACKUPMASTER will not compress data before writing to tape
  553.     COMP="UNCOMPRESSED"
  554. fi
  555.  
  556.  
  557. # Initialize backup tape
  558. rewind_tape
  559.  
  560.  
  561. # Initialise POSITION Variable
  562. POSITION=2
  563.  
  564.  
  565. # Timestamp Tape
  566. echo Timestamping tape.
  567. echo 0:Backup_Timestamp >>$INDEXFILE
  568. echo "Backup Timestamp: "`date` >$TAPE
  569.  
  570. # Mark tape COMPRESSED/UNCOMRESSED
  571. echo Marking Tape
  572. echo 1:Compression_Mark >>$INDEXFILE
  573. echo $COMP >$TAPE
  574.  
  575.  
  576. for NODE in $BACKUP_NODES
  577. do
  578.     echo ------------------------------------------------------------
  579.  
  580.     if bsdping $NODE
  581.     then
  582.         if [ $BACKUPMASTER = $NODE ]
  583.         then
  584.             echo Running shell for Computer $NODE Backup at `date`
  585.             $SCRIPTSDIR/backup.sh |output_to_tape
  586.         else
  587.             echo Running remote shell for Computer $NODE Backup at `date`
  588.             remsh $NODE -n $SCRIPTSDIR/backup.sh |output_to_tape
  589.         fi
  590.         echo Updating INDEX file with \"$POSITION\:$NODE\"
  591.         echo $POSITION\:$NODE >>$INDEXFILE
  592.         POSITION=`expr $POSITION + 1`
  593.         echo Done writing Backup for Computer $NODE at `date`
  594.     else
  595.         date
  596.         echo Computer $NODE is unreachable. No backup attempted.
  597.     fi
  598. done
  599. echo ------------------------------------------------------------
  600.  
  601. echo Writing Logfile to tape... \(no more log on tape after this\).
  602. cat $LOGFILE >$TAPE
  603. echo $POSITION\:Backup_logfile >>$INDEXFILE
  604. POSITION=`expr $POSITION + 1`
  605.  
  606.  
  607. echo Writing Index file to tape.
  608. echo $POSITION\:Backup_index >>$INDEXFILE
  609. cat $INDEXFILE >$TAPE
  610.  
  611. echo Removing Index file.
  612. rm -f $INDEXFILE || stop_on_error Removing Index file
  613.  
  614.  
  615. rewind_tape || stop_on_error Rewinding Tape
  616.  
  617. eject_tape || stop_on_error Ejecting Tape
  618.  
  619. echo Master Backup Script stopped at `date`
  620.  
  621. @EOF
  622.  
  623. chmod 755 backup/master.sh
  624.  
  625. echo x - backup/restore.sh
  626. cat >backup/restore.sh <<'@EOF'
  627. #!/bin/sh
  628.  
  629.  
  630.  
  631. ##################################################
  632. # Make sure Search Path is correct.
  633. PATH="/bin:/usr/bin:/etc"
  634. export PATH
  635.  
  636.  
  637. ##################################################
  638. # Trap errors...
  639. trap "echo Caught a TERM\(15\) signal. I\'m dying.; exit 1" 15
  640.  
  641.  
  642.  
  643. ##################################################
  644. # Assumptions...
  645. TAPE=/dev/bdds
  646. CHUNKSIZE=60k
  647. INDEXFILE=/tmp/restore.sh.index.$$
  648. COMPRESS="no"
  649.  
  650. ##################################################
  651. # Functions.....
  652.  
  653.  
  654. ####################
  655. # Clean up function...
  656.  
  657. do_cleanup()
  658. {
  659.     echo Removing Temporary files...
  660.     #rm -f /tmp/restore.sh.*.$$ 
  661. }
  662.  
  663.  
  664. ####################
  665. # Stop on error function...
  666. stop_on_error()
  667. {
  668.     echo Woops. An error occured while $*
  669.     echo Sending my self a TERM signal.
  670.     kill -TERM $$
  671. }
  672.  
  673. ####################
  674. # eod winds to the end of tape
  675.  
  676. eod()
  677. {
  678.     if [ `uname` = 'HP-UX' ]
  679.     then
  680.         OSVER=` uname -r |sed -e "s/[.A-Za-z]//g" -e "s/^0//" -e "s/00*$//"`
  681.         
  682.         case $OSVER in
  683.             7*)
  684.                 true        # Reset $?
  685.                 while [ $? = 0 ]
  686.                 do
  687.                     mt -t $TAPE fsf 1 >/dev/null 2>&1
  688.                 done
  689.                 ;;
  690.             
  691.             8*)
  692.                 mt -t $TAPE eod
  693.                 ;;
  694.  
  695.             *)
  696.                 echo $0 : Error\! eod\(\) must be rewritten for `uname` `uname -r`.
  697.                 exit 0
  698.                 ;;
  699.         esac
  700.  
  701.     else
  702.     
  703.         echo $0 : Error\! eod\(\) must be rewritten for `uname` `uname -r`.
  704.         exit 0
  705.     fi
  706. }
  707.  
  708.  
  709. cat_index_file()
  710. {
  711.  
  712.     # Wind to end of tape.
  713.     
  714.     eod
  715.     
  716.     # Now, Position tape at index file
  717.     mt -t $TAPE bsf 3    || stop_on_error Backspacing 3 filemarks to INDEX-file.
  718.     mt -t $TAPE fsf 1    || stop_on_error Forward Spacing to INDEX-file
  719.     cat $TAPE        || stop_on_error Writing INDEX file STDOUT from tape.
  720. }
  721.  
  722.  
  723.  
  724. # Main part of script...
  725.  
  726. ##################################################
  727. # check parameters...
  728.  
  729. if [ $# -lt 2 ]
  730. then
  731.     echo "usage: $0 <host> <file> [file] [file] ..."
  732.     exit 1
  733. fi
  734.  
  735.  
  736. # Trap interrupts etc...
  737. trap "do_cleanup" 0
  738. trap "do_cleanup; kill -TERM $$" 2 3 
  739.  
  740.  
  741. # Get hostname without domain (if any)
  742. HOST="`echo $1 |sed -e \"s/\..*//\"`"
  743. shift
  744.  
  745. # Make sure shell does not glob filename arguments...
  746.  
  747. FILES=\'$*\'
  748. FILES="`echo $FILES |sed -e \"s/[     ][     ]*/' '/g\"`"
  749.  
  750. # Remove / in front of filenames...
  751. FILES="`echo $FILES |sed -e \"s,'/,',g\"`"
  752.  
  753.  
  754. echo FILES=$FILES
  755.  
  756. # Check if host is available... (strip domain when hostname returned from host)
  757. if [ "`remsh $HOST hostname |sed -e \"s/\..*//\"`" != "$HOST" ]
  758. then
  759.     echo Cannot contact $HOST via network.
  760.     echo Restore cannot complete.
  761.     stop_on_error Trying to reach computer $HOST via network.
  762. fi
  763.  
  764.  
  765. # Rewind Tape.
  766.  
  767. mt -t $TAPE rew || stop_on_error rewinding tape.
  768.  
  769.  
  770. # Get timestamp from tape
  771. echo Getting Timestamp from tape.
  772. TIMESTAMP="`cat $TAPE`" || stop_on_error Reading timestamp from tape.
  773.  
  774. echo TIMESTAMP=$TIMESTAMP
  775.  
  776. # Get compression mark from tape
  777. echo Getting Compression Mark from tape.
  778. COMPRESS="`cat $TAPE`" || stop_on_error Reading compression mark from tape.
  779.  
  780. echo COMPRESS=$COMPRESS
  781.  
  782. # Get index from tape.
  783. echo Getting Index from tape.
  784. cat_index_file >$INDEXFILE || stop_on_error Reading compression mark from tape.
  785.  
  786. echo ------------ index ---------
  787. cat $INDEXFILE
  788. echo ----------------------------
  789.  
  790. # Search index for $HOST
  791. echo Searching index for $HOST
  792. if [ "`egrep '^[0-9][0-9]*:'$HOST'$' $INDEXFILE |cut -d: -f2`" != $HOST ]
  793. then
  794.     echo Computer $HOST has no filess on this backup tape.
  795.     stop_on_error Searching indexfile for computer $HOST
  796. fi
  797.  
  798.  
  799. # Position to correct fileset
  800. echo Getting Position for correct fileset.
  801. POSITION="`egrep '^[0-9][0-9]*:'$HOST'$' $INDEXFILE |cut -d: -f1`"
  802. [ -z "$POSITION" ] && stop_on_error Could not determine position of $HOST in index.
  803. echo ${HOST}\'s backup is located on fileset $POSITION
  804.  
  805. # rewind Tape 
  806. echo Rewinding Tape.
  807. mt -t $TAPE rew || stop_on_error Rewinding Tape
  808.  
  809. echo Winding to Fileset no $POSITION
  810. mt -t $TAPE fsf $POSITION || stop_on_error Positioning tape to fileset $POSITION
  811.  
  812.  
  813.  
  814. # Restore file(s)
  815.  
  816. echo Restoring Files...
  817.  
  818.  
  819. #
  820. # I had to include the 'cat | cpio' instead of plain cpio.
  821. # when using plain cpio, cpio would go out of sync.
  822. # i think this has to do with how remsh handles the pipe to cpio
  823. # Eskil...
  824.  
  825.  
  826. if [ "$COMPRESS" = "COMPRESSED" ]
  827. then
  828.     dd if=$TAPE ibs=$CHUNKSIZE obs=10k |uncompress |remsh $HOST "cd /;" 'cat | cpio' -RBivdumx $FILES
  829.     # for debugging
  830.     # dd if=$TAPE ibs=$CHUNKSIZE obs=10k |uncompress |remsh $HOST "cd /;" 'cat | cpio' -RBivt $FILES
  831.  
  832.  
  833. elif [ "$COMPRESS" = "UNCOMPRESSED" ]
  834. then
  835.  
  836.     dd if=$TAPE ibs=$CHUNKSIZE obs=10k |remsh $HOST "cd /;" 'cat |cpio' -RBivdumx $FILES
  837.     # for debugging
  838.     # dd if=$TAPE ibs=$CHUNKSIZE obs=10k |remsh $HOST "cd /;" 'cat |cpio' -RBivt $FILES
  839. else
  840.     echo Could not resolve wheter tape is compressed or not.
  841.     echo No files restored...
  842.     do_cleanup
  843. fi
  844.  
  845.  
  846.  
  847.  
  848. @EOF
  849.  
  850. chmod 755 backup/restore.sh
  851.  
  852. echo x - backup/backup-stats.pl
  853. sed 's/^@//' >backup/backup-stats.pl <<'@EOF'
  854. #!/usr/local/gnu/bin/perl 
  855.  
  856.  
  857. @@BACKUPMASTERS=(klaus,chuck,sleipner,volt);
  858.  
  859.  
  860. $BACKUPFILE="/users/root/backup/backup-log";
  861.  
  862. if ( $ARGV[0] =~ /^[0-9]$/ )
  863. {
  864.    $BACKUPFILE="$BACKUPFILE\.$ARGV[0]";
  865.    
  866. }
  867.  
  868. print "Summary of $BACKUPFILE on @BACKUPMASTERS\n\n";
  869.  
  870. format HEADER =
  871.  
  872. ======================================================================
  873. @@||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  874. $HEADER
  875. ----------------------------------------------------------------------
  876. Hostname      MbBU   MbWT Comp%   Time KB/S   MB/M     Date
  877.  
  878. @.
  879.  
  880. format LINE =
  881. @@<<<<<<<<<< @##### @##### @###% @>>>>> @### @##.##     @<<<<<<<<<<<
  882. $HOST,      $MB,   $MBOUT,$COMPRESSION, $TIME, $KBPS, $MBPM, $DATE
  883. @.
  884.  
  885. format TOTAL =
  886. ----------------------------------------------------------------------
  887. TOTAL/AVG   @##### @##### @###% @>>>>> @### @##.## 
  888.             $TOTALMB, $TOTALMBOUT, $TOTALCOMPRESSION,$TOTALTIME,$TOTALKBPS, $TOTALMBPM
  889. ======================================================================
  890.  
  891. @.
  892.  
  893. format SUM =
  894. ======================================================================
  895.                       TOTAL/AVG OF ALL BACKUPS
  896.   MbBU   MbWT Comp%   Time KB/S   MB/M
  897.  
  898. @@##### @##### @###% @>>>>> @### @##.##
  899. $SUMMB, $SUMMBOUT, $SUMCOMPRESSION, $SUMTIME, $SUMKBPS, $SUMMBPM
  900. ======================================================================
  901. @.
  902.  
  903.  
  904.  
  905. sub tominutes
  906. {
  907.     local($ARG) = @_;
  908.     local($HOURS,$MINUTES) = split(':',$ARG);
  909.     return ( $HOURS * 60 ) + $MINUTES;
  910. }
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917. # Main.
  918.  
  919. print "\
  920. MbBU  = Megabytes backed up.\
  921. MBWT  = Megabytes written to tape.\
  922. Comp% = % size of data after compression. \
  923. Time  = Time used for backup.\
  924. KB/S  = Kilobytes Per Second.\
  925. MB/M  = Megabytes Per Minute.\
  926. \
  927. ";
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937. foreach $MASTER (@BACKUPMASTERS) 
  938. {
  939.     open(MASTERFILE,"remsh $MASTER /bin/cat $BACKUPFILE|");
  940.  
  941.     $~ = HEADER;
  942.     $HEADER ="SUMMARY OF BACKUP FROM $MASTER";
  943.     write;
  944.     
  945.     $TOTALKB = $TOTALKBOUT = $TOTALMINUTES = $TOTALCOMPRESSION = $TOTALKBPS = $TOTALMBPM = 0;
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.     while (<MASTERFILE>)
  968.     {
  969.          
  970.         /^Backing up (.*)$/ && ($DIRS=$1);
  971.         /^([0-9]+) blocks$/ && ($BLOCKS=$1);
  972.         if (/^Running .*((Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s[0-9]+)\s([0-9]+:[0-9]+:)/)
  973.             {
  974.             $DATE=$1;
  975.             $STARTTIME=&tominutes($4);
  976.         }
  977.         
  978.         /^([0-9+]+) (records|blocks) out$/ && ($BLOCKSOUT=$1);
  979.         /^Updating INDEX file with "[0-9]+:([0-9a-zA-Z]+)"$/ && ($HOST=$1);
  980.         if (/^Done .*([0-9]+:[0-9]+:)/)
  981.         {
  982.             $ENDTIME=&tominutes($1);
  983.             $MINUTES=$ENDTIME-$STARTTIME;
  984.             $TOTALMINUTES += $MINUTES;
  985.             $SUMMINUTES += $MINUTES;
  986.             $TIME=sprintf("%d:%2.2d",($MINUTES / 60),($MINUTES % 60));
  987.             eval("\$BLOCKS=$BLOCKS");
  988.             eval("\$BLOCKSOUT=$BLOCKSOUT");
  989.             $KB=$BLOCKS/2;
  990.             $KBOUT=$BLOCKSOUT*60;
  991.             $TOTALKB += $KB;
  992.             $TOTALKBOUT += $KBOUT;
  993.             $SUMKB += $KB;
  994.             if ($MINUTES > 0)
  995.                 {
  996.                 $KBPS=($KB / ($MINUTES * 60));
  997.                 $MBPM=(($KB/1024) / $MINUTES);
  998.             }
  999.             else
  1000.             {
  1001.                 $KBPS = 0;
  1002.                 $MBPM = 0;
  1003.             }
  1004.             
  1005.  
  1006.             $MB=$KB/1024;
  1007.             
  1008.             $MBOUT=$KBOUT/1024;
  1009.         
  1010.             if ($KB > 0)
  1011.             {
  1012.                 $COMPRESSION=($KBOUT/$KB)*100;
  1013.             }
  1014.             else
  1015.             {
  1016.                 $COMPRESSION=0;
  1017.             }
  1018.             
  1019.             $~ = LINE;
  1020.             write;
  1021.             $BLOCKS=0;
  1022.             $BLOCKSOUT=0;
  1023.             $DIRS="";
  1024.             $HOST="";
  1025.         }    
  1026.     }
  1027.     
  1028.     $TOTALTIME=sprintf("%d:%2.2d",($TOTALMINUTES / 60),($TOTALMINUTES % 60));
  1029.     $TOTALMB=$TOTALKB/1024;
  1030.     $TOTALMBOUT=$TOTALKBOUT/1024;
  1031.     if ($TOTALKB > 0)
  1032.     {
  1033.         $TOTALCOMPRESSION=($TOTALKBOUT/$TOTALKB)*100;
  1034.     }
  1035.  
  1036.     if ($TOTALMINUTES > 0)
  1037.     {
  1038.         $TOTALKBPS = ($TOTALKB / ( $TOTALMINUTES * 60));
  1039.         $TOTALMBPM = (($TOTALKB / 1024) / $TOTALMINUTES);
  1040.     }
  1041.     
  1042.     close(BACKUPFILE);
  1043.     $~ = TOTAL; write;
  1044.  
  1045.     $SUMMB += $TOTALMB;
  1046.     $SUMMBOUT += $TOTALMBOUT;
  1047. }
  1048.  
  1049.  
  1050.  
  1051.  
  1052. if ($SUMMB > 0)
  1053. {
  1054.     $SUMCOMPRESSION = ($SUMMBOUT/$SUMMB)*100;
  1055. }
  1056.  
  1057. if ($SUMMINUTES > 0)
  1058. {
  1059.     $SUMKBPS = ($SUMKB / ( $SUMMINUTES * 60));
  1060.     $SUMMBPM = (($SUMKB / 1024) / $SUMMINUTES);
  1061. }
  1062.  
  1063.  
  1064. $SUMTIME=sprintf("%d:%2.2d",($SUMMINUTES / 60),($SUMMINUTES % 60));
  1065.  
  1066.  
  1067. $~ = SUM;
  1068. write;
  1069. @EOF
  1070.  
  1071. chmod 775 backup/backup-stats.pl
  1072.  
  1073. chmod 777 backup
  1074.  
  1075. exit 0
  1076.