home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume15 / whichtape < prev    next >
Text File  |  1988-05-30  |  7KB  |  286 lines

  1. Subject:  v15i023:  Tools to help find files on backup tapes
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: Clyde Hoover <ut-sally!ut-emx!clyde>
  6. Posting-number: Volume 15, Issue 23
  7. Archive-name: whichtape
  8.  
  9. [  For BSD-based backup and restore.  --r$  ]
  10.  
  11. Storetape and whichtape are tools I cobbled together a couple of years
  12. ago to facilitiate backup restores.   Rather than have to mount a bunch
  13. of incremental tapes to find out which one a particular file was on,
  14. these shell scripts impliment a simple data base which contains the table
  15. of contents of each backup tape.
  16.  
  17. #    This is a shell archive.
  18. #    Remove everything above and including the cut line.
  19. #    Then run the rest of the file through sh.
  20. -----cut here-----cut here-----cut here-----cut here-----
  21. #!/bin/sh
  22. # shar:    Shell Archiver
  23. #    Run the following text with /bin/sh to create:
  24. #    README
  25. #    storetape.8
  26. #    storetape.sh
  27. #    whichtape.8
  28. #    whichtape.sh
  29. cat << \SHAR_EOF > README
  30. Storetape & whichtape README
  31.  
  32. Storetape and whichtape are tools I cobbled together a couple of years
  33. ago to facilitiate backup restores.   Rather than have to mount a bunch
  34. of incremental tapes to find out which one a particular file was on,
  35. these shell scripts impliment a simple data base which contains the table
  36. of contents of each backup tape.
  37.  
  38. The data base is created by storetape and access by whichtape.
  39. The data files are compressed to save disk space and since they should
  40. not be accessed very often, so the compression/decompression time to
  41. disk space tradeoff is reasonable.
  42.  
  43. For incremental dumps, a 'restore t' was done on each backup tape right
  44. after the dump was done.  This table of contents is fed to storetape.
  45. This also verifies that the tape just written can be read, at least up
  46. to the directory information.
  47.  
  48. For level 0 dumps which span several tape reels, this method is impractical.
  49. Instead 'ncheck -i' is used to generate a list of file names.
  50. Any program or method which generates a list of names in a file tree
  51. would provide proper input for storetape.
  52.  
  53. These scripts leave their database in the current directory.
  54. Customization of that is left to the installer.
  55.  
  56.     Clyde Hoover
  57.     Computation Center
  58.     The University of Texas at Austin
  59.     Austin, Texas 78712
  60.     (512) 471-3241
  61.     clyde@emx.utexas.edu
  62.     uunet!ut-sally!ut-emx!clyde
  63. SHAR_EOF
  64. cat << \SHAR_EOF > storetape.8
  65. .\" @(#)storetape.8    1.1 10/13/86 (cc.utexas.edu)
  66. .TH STORETAPE 8
  67. .SH NAME
  68. storetape \- remember contents of backup tape
  69. .SH SYNOPSIS
  70. .B storetape
  71. \fB-d\fP filesystem \fB-t\fP tape-name \fB-l\fP dump-level [ \fB-f\fP file ]
  72. .SH DESCRIPTION
  73. .I Storetape
  74. takes as input a list of files from either
  75. .IR restore (8)
  76. or
  77. .IR ncheck (8)
  78. and enters it in a tape backup data base.
  79. This data base is accessed by
  80. .IR whichtape (8).
  81. .PP
  82. The options are:
  83. .TP 15 10
  84. -d filesystem
  85. Indicates the file system that this is the list of.
  86. .TP 15 10
  87. -t tape-name
  88. Is the name of the backup tape.
  89. .TP 15 10
  90. -l dump-level
  91. Is the dump level of the tape.
  92. .TP 15 10
  93. -f file
  94. Is the input file.
  95. If none is specified, then the standard input is used.
  96. .PP
  97. The information from the 
  98. .B -d
  99. and
  100. .B -l
  101. arguments are used to construct the name of the data base files.
  102. There is one set of data base files per file system per dump level.
  103. .SH FILES
  104. FilesystemLevel.C - tape data base control file
  105. .br
  106. FilesystemLevel.D - tape data base data file
  107. .SH "SEE ALSO"
  108. whichtape(8), ncheck(8), restore(8)
  109. SHAR_EOF
  110. cat << \SHAR_EOF > storetape.sh
  111. #! /bin/sh
  112. #
  113. #    storetape - store backup tape list in backups data base
  114. #
  115. #    Usage: storetape -t tape_name -l dump_level -d file_system
  116. #        [-f input_file]
  117. #    If input_file is not given, then standard input is read.
  118. #    Input must be a list of file names.
  119. #
  120. Usage="Usage: $0 [-f file] -t tape_name -l dump_flags -d file_system"
  121. if [ $# -lt 6 ]; then
  122.     echo $Usage
  123.     exit 1
  124. fi
  125.  
  126. Compressor=compress        # CONFIG
  127. FileSystem=""
  128. TapeName=""
  129. DumpFlags=""
  130. InputFile=""
  131.  
  132. #
  133. #    Parse arguments
  134. #
  135. argx=""
  136. for a do
  137.     case $a in
  138.     -d* || -t* || -l* || -f*)
  139.         argx=$a
  140.         ;;
  141.     -*)
  142.         echo Unknown argument $a
  143.         exit 1
  144.         ;;
  145.     *)
  146.         case "$argx" in
  147.         -d)     FileSystem=$a ;;
  148.         -t)    TapeName=$a ;;
  149.         -l)    DumpFlags=$a ;;
  150.         -f)    InputFile=$a ;;
  151.         *)    echo $Usage; exit 1 ;;
  152.         esac
  153.         argx=""
  154.     esac
  155. done
  156.  
  157. #
  158. # Generate backup data base filename
  159. #
  160. fslabel=`echo $FileSystem | tr -d /`            # Remove slashes
  161. dbname=$fslabel.$DumpFlags                # Generate name
  162.  
  163. #
  164. # Generate control file 
  165. #
  166. cat > $dbname.C <<!
  167. $dbname
  168. $FileSystem
  169. $TapeName
  170. $DumpFlags
  171. `date`
  172. !
  173. #
  174. # Compact input data into data base
  175. #
  176. (if [ -n "$InputFile" ]; then
  177.     cat $InputFile 
  178. else
  179.     cat
  180. fi) | $Compressor -c  > $dbname.D 2>/dev/null
  181. chmod 0644 $dbname.?
  182. exit 0
  183. #
  184. # End
  185. #
  186. SHAR_EOF
  187. cat << \SHAR_EOF > whichtape.8
  188. .\" @(#)whichtape.8    1.1 10/13/86 (cc.utexas.edu)
  189. .TH WHICHTAPE 8
  190. .SH NAME
  191. whichtape \- locate file(s) on backup tapes
  192. .SH SYNOPSIS
  193. .B /etc/whichtape
  194. file-name ... [ file-name ]
  195. .SH DESCRIPTION
  196. .I Whichtape
  197. scans the backup tape directory created by
  198. .I storetape
  199. and finds which backup tape(s)
  200. .I file-name
  201. are on.
  202. Filenames are relative paths, so
  203. .I /u0/cc/foobar
  204. are stored as
  205. .IR ./cc/foobar .
  206. .I File-name
  207. can be any match pattern acceptable to
  208. .IR egrep (1).
  209. Metacharacters must be quoted.
  210. .SH FILES
  211. FilesystemLevel.C - tape data base control file
  212. .br
  213. FilesystemLevel.D - tape data base data file
  214. .SH "SEE ALSO"
  215. storetape(8), egrep(1)
  216. SHAR_EOF
  217. cat << \SHAR_EOF > whichtape.sh
  218. #! /bin/sh
  219. #
  220. #    whichtape - locate file(s) in backup data base
  221. #
  222. #    Usage: whichtape path-name
  223. #
  224. if [ $# -lt 1 ]; then
  225.     echo "Usage: $0 path-name ... path-name"
  226.     exit 1
  227. fi
  228. Uncompress=zcat            # CONFIG
  229. sed=/tmp/lookdb$$        # Sed script file
  230.  
  231. trap "rm -f $sed.?; exit 1" 2 3
  232.  
  233. #
  234. #    Sed script to crack the control files
  235. #
  236. cat >$sed.A <<"!"
  237. 1s/.*/stem=&/
  238. 2s/.*/filesys=&/
  239. 3s/.*/tapename="&"/
  240. 4s/.*/dumplevel="&"/
  241. 5s/.*/tdate="&"/
  242. !
  243.  
  244. #
  245. #    Step through control files
  246. #
  247. for bf in *.C; do
  248.     stem=""
  249.     eval `sed -f $sed.A $bf`    # Get data from control file
  250.     if [ "$stem" = "" ]; then
  251.         echo Format error in control file $bf !!
  252.         continue
  253.     fi
  254.     cat > $sed.B <<!        # Sed script to post-process grep output
  255. s@^@($tapename)    @
  256. s@\$@    $tdate@
  257. !
  258.     #
  259.     # Step through file arguments
  260.     #
  261.     for file do
  262.         trap "break" 2        # Intr to next file
  263.         if [ ! -r $stem.D ]; then
  264.             echo Data file $stem.D missing!
  265.         else
  266.             $Uncompress $stem.D | egrep $file | sed -f $sed.B
  267.         fi
  268.     done
  269.     trap "rm -f $sed.?; exit 1" 2 3        # Restore global intr behavior
  270. done
  271. # Cleanup
  272. rm -f $sed.?
  273. exit 0
  274. #
  275. # End
  276. #
  277. SHAR_EOF
  278. #    End of shell archive
  279. exit 0
  280. -- 
  281. Shouter-To-Dead-Parrots @ Univ. of Texas Computation Center; Austin, Texas  
  282.     clyde@ngp.utexas.edu; ...!ut-sally!ut-ngp!clyde
  283. "It's a sort of a threat, you see.  I've never been very good at them
  284. myself, but I've told they can be very effective."
  285.  
  286.