home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / linux / 10503 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  12.2 KB

  1. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  2. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: Backups
  5. Message-ID: <1992Sep11.210107.15662@klaava.Helsinki.FI>
  6. Date: 11 Sep 92 21:01:07 GMT
  7. References: <1992Sep11.202337.10427@cs.tulane.edu>
  8. Organization: University of Helsinki
  9. Lines: 375
  10.  
  11. butler@cs.tulane.edu (Larry Butler) writes:
  12. >How do I make a backup of a file system on to floppies?
  13.  
  14. I use GNU tar myself.  The sources from GNU come with two shell scripts
  15. that can be used to make backups, level-0 for a full dump, and level-1
  16. for files changed since the last full dump.
  17.  
  18. Unfortunately, these scripts don't works right out of the box, since
  19. they use commands not commonly available on Linux (mt, mail, perhaps
  20. others).  I had to hack at them for a while until they worked.  I
  21. recently offered to mail them to interested parties, and did to all two
  22. of them, but I guess I'll post too, since there may be more people who
  23. might use them.
  24.  
  25. However, please be warned that these scripts have been hacked and that
  26. they are _ugly_.  There is no need to tell it to me.  Of course, if you
  27. happen to find a bug, I'd be glad to hear about it (I have about 18
  28. months' work depending on this backup strategy, but do _not_ take this
  29. as a statement of quality: I gamble almost without provocation).
  30.  
  31. To use them, you need to customize backup-specs, which defines the
  32. filesystems or directories that will be backed up.
  33.  
  34. --
  35. Lars.Wirzenius@helsinki.fi
  36.  
  37.  
  38. ---8<---cut here for level-0 ---8<---
  39. #!/bin/sh
  40. #
  41. # Run this script as root on the machine that has the tape drive, to make a
  42. # full dump.
  43. #
  44. # If you give `now' as an argument, the dump is done immediately.
  45. # Otherwise, it waits until 1am, or until the hour given as argument.
  46. # Specify the hour as a number from 0 to 23.
  47. #
  48. # You must edit the file `backup-specs' to set the parameters for your site.
  49.  
  50. if [ ! -w / ]; then
  51.    echo The backup must be run as root,
  52.    echo or else some files will fail to be dumped.
  53.    exit 1
  54. else
  55.    false
  56. fi
  57.  
  58. # This is undesirable -- rms.
  59. # rsh albert /usr/local/adm/motd-backup-start
  60.  
  61. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  62. . ./backup-specs
  63.  
  64. # Maybe sleep until around specified or default hour.
  65. #
  66. if [ "$1" != "now" ]; then
  67.    if [ "$1"x != x ]; then
  68.       spec=$1
  69.    else
  70.       spec=$BACKUP_HOUR
  71.    fi
  72.    pausetime=`date | awk '{hr=substr($4,1,2);\\
  73.       mn=substr($4,4,2);\\
  74.       if((hr+0)<spec)\\
  75.          print 3600*(spec-hr)-60*mn;\\
  76.       else\\
  77.          print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  78.    clear
  79.    cat ./dont_touch
  80.    sleep $pausetime
  81. fi
  82.  
  83. # start doing things
  84.  
  85. here=`pwd`
  86. LOGFILE=log`date '+%m%d'`full
  87. HOST=`hostname | sed 's/\..*//'`
  88. TAR_PART1="/bin/tar -c +multi-volume +block=$BLOCKING +sparse +exclude-from -"
  89. #TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING "
  90.  
  91. # Make sure the log file did not already exist.  Create it.
  92.  
  93. if [ -f $LOGFILE ] ; then
  94.    echo Log file $LOGFILE already exists.
  95.    exit 1
  96. else
  97.    touch $LOGFILE
  98. fi
  99.  
  100. #mt -f $TAPE_FILE rewind
  101.  
  102. set $BACKUP_DIRS
  103. while [ $# -ne 0 ] ; do
  104.    host=`echo $1 | sed 's/:.*$//'`
  105.    fs=`echo $1 | sed 's/^.*://'`
  106.    date=`date`
  107.    fsname=`echo $1 | sed 's/\//:/g'`
  108.  
  109.    TAR_PART2="+listed=/etc/tar-backup/temp.lev0 "
  110.    TAR_PART3="+label='Full backup of $fs on $host at $date' -C $fs ."
  111.  
  112.    echo Backing up $1 at $date | tee -a $LOGFILE
  113.  
  114.    # Actually back things up.
  115.  
  116.    if [ $HOST != $host ] ; then
  117.       rsh $host "mkdir /etc/tar-backup 2>/dev/null; \
  118.     rm -f /etc/tar-backup/temp.lev0; \
  119.           $TAR_PART1 -f $HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3" \
  120.      2>&1 | tee -a $LOGFILE
  121.    else
  122.       mkdir /etc/tar-backup 2>/dev/null
  123.       rm -f /etc/tar-backup/temp.lev0
  124. # Using `sh -c exec' causes nested quoting and shell substitution
  125. # to be handled here in the same way rsh handles it.
  126.       echo -n "Insert first volume for $1 and press Enter"; read dummy
  127.       echo "$EXCLUDE_FILES" | tr ' ' '\12' | \
  128.         sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3" 2>&1 | \
  129.         tee -a $LOGFILE
  130.    fi
  131.    if [ $? -ne 0 ] ; then
  132.       echo Backup of $1 failed. | tee -a $LOGFILE
  133.       # I'm assuming that the tar will have written an empty
  134.       # file to the tape, otherwise I should do a cat here.
  135.    else
  136.       if [ $HOST != $host ] ; then
  137.     rsh $host mv -f /etc/tar-backup/temp.lev0 /etc/tar-backup/$fsname.lev0 2>&1 | tee -a $LOGFILE
  138.       else
  139.         mv -f /etc/tar-backup/temp.lev0 /etc/tar-backup/$fsname.lev0 2>&1 | tee -a $LOGFILE
  140.       fi
  141.    fi
  142.    $TAPE_STATUS | tee -a $LOGFILE
  143. #   sleep 60
  144.    shift
  145. done
  146.  
  147. # Dump any individual files requested.
  148.  
  149. if [ x != "x$BACKUP_FILES" ] ; then
  150.    date=`date`
  151.  
  152.    TAR_PART2="+listed=/etc/tar-backup/temp.lev0"
  153.    TAR_PART3="+label='Full backup of miscellaneous files at $date'"
  154.  
  155.    mkdir /etc/tar-backup 2>/dev/null
  156.    rm -f /etc/tar-backup/temp.lev0
  157.  
  158.    echo Backing up miscellaneous files at $date | tee -a $LOGFILE
  159. # Using `sh -c exec' causes nested quoting and shell substitution
  160. # to be handled here in the same way rsh handles it.
  161.    echo -n "Insert first volume for $1 and press Enter"; read dummy
  162.    echo "$EXCLUDE_FILES" | tr ' ' '\12' | \
  163.      sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3 \
  164.      $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  165.    if [ $? -ne 0 ] ; then
  166.      echo Backup of miscellaneous files failed. | tee -a $LOGFILE
  167.      # I'm assuming that the tar will have written an empty
  168.      # file to the tape, otherwise I should do a cat here.
  169.    else
  170.      mv -f /etc/tar-backup/temp.lev0 /etc/tar-backup/misc.lev0 2>&1 | tee -a $LOGFILE
  171.    fi
  172.    $TAPE_STATUS | tee -a $LOGFILE
  173. else
  174.    echo No miscellaneous files specified | tee -a $LOGFILE
  175.    false
  176. fi
  177.  
  178. #mt -f $TAPE_FILE rewind
  179. #mt -f $TAPE_FILE offl
  180.  
  181. echo Sending the dump log to $ADMINISTRATOR
  182. #cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  183. #mail -s "Results of backup on `date`" $ADMINISTRATOR < $LOGFILE.tmp
  184. (echo ''; echo "Subject: Results of backup on `date`"; echo '';
  185. cat $LOGFILE) >> /usr/spool/mail/root
  186.  
  187. # This is undesirable -- rms.
  188. #rsh albert /usr/local/adm/motd-backup-done &
  189.  
  190. ---8<---cut here for level-1 ---8<---
  191. #!/bin/sh
  192. #
  193. # Run this script as root on the machine that has the tape drive, to make a
  194. # level-1 dump containing all files changed since the last full dump.
  195. #
  196. # If you give `now' as an argument, the dump is done immediately.
  197. # Otherwise, it waits until 1am.
  198. #
  199. # You must edit the file `backup-specs' to set the parameters for your site.
  200.  
  201. if [ ! -w / ]; then
  202.    echo The backup must be run as root,
  203.    echo or else some files will fail to be dumped.
  204.    exit 1
  205. else
  206.    false
  207. fi
  208.  
  209. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  210. . ./backup-specs
  211.  
  212. # Maybe sleep until around specified or default hour.
  213. #
  214. if [ "$1" != "now" ]; then
  215.    if [ "$1"x != x ]; then
  216.       spec=$1
  217.    else
  218.       spec=$BACKUP_HOUR
  219.    fi
  220.    pausetime=`date | awk '{hr=substr($4,1,2);\\
  221.       mn=substr($4,4,2);\\
  222.       if((hr+0)<spec)\\
  223.          print 3600*(spec-hr)-60*mn;\\
  224.       else\\
  225.          print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  226.    clear
  227.    cat ./dont_touch
  228.    sleep $pausetime
  229. fi
  230.  
  231. # start doing things
  232.  
  233. here=`pwd`
  234. LOGFILE=log`date '+%m%d'`lev1
  235. HOST=`hostname | sed 's/\..*//'`
  236. TAR_PART1="/bin/tar -c +multi-volume +block=$BLOCKING +sparse +exclude-from -"
  237. #TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING "
  238.  
  239. # Make sure the log file did not already exist.  Create it.
  240.  
  241. if [ -f $LOGFILE ] ; then
  242.    echo Log file $LOGFILE already exists.
  243.    exit 1
  244. else
  245.    touch $LOGFILE
  246. fi
  247.  
  248. #mt -f $TAPE_FILE rewind
  249.  
  250. set $BACKUP_DIRS
  251. while [ $# -ne 0 ] ; do
  252.    host=`echo $1 | sed 's/:.*$//'`
  253.    fs=`echo $1 | sed 's/^.*://'`
  254.    date=`date`
  255.    fsname=`echo $1 | sed 's/\//:/g'`
  256.  
  257. # This filename must be absolute; it is opened on the machine that runs tar.
  258.    TAR_PART2="+listed=/etc/tar-backup/temp.lev1"
  259.    TAR_PART3="+label='level 1 backup of $fs on $host at $date' -C $fs ."
  260.  
  261.    echo Backing up $1 at $date | tee -a $LOGFILE
  262.    echo Last full dump on this filesystem: | tee -a $LOGFILE
  263.  
  264.    if [ $HOST != $host ] ; then
  265.      rsh $host "ls -l /etc/tar-backup/$fsname.lev0; \
  266.     cp /etc/tar-backup/$fsname.lev0 /etc/tar-backup/temp.lev1" \
  267.     2>&1 | tee -a $LOGFILE
  268.    else
  269.      ls -l /etc/tar-backup/$fsname.lev0 2>&1 | tee -a $LOGFILE
  270.      cp /etc/tar-backup/$fsname.lev0 /etc/tar-backup/temp.lev1 2>&1 | tee -a $LOGFILE
  271.    fi
  272.  
  273.    # Actually back things up.
  274.  
  275.    if [ $HOST != $host ] ; then
  276.       rsh $host $TAR_PART1 -f $HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3 2>&1 | tee -a $LOGFILE
  277.    else
  278. # Using `sh -c exec' causes nested quoting and shell substitution
  279. # to be handled here in the same way rsh handles it.
  280.       echo -n "Insert first volume for $1 and press Enter"; read dummy
  281.       echo "$EXCLUDE_FILES" | tr ' ' '\12' | \
  282.         sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3" 2>&1 | \
  283.         tee -a $LOGFILE
  284.    fi
  285.    if [ $? -ne 0 ] ; then
  286.       echo Backup of $1 failed. | tee -a $LOGFILE
  287.       # I'm assuming that the tar will have written an empty
  288.       # file to the tape, otherwise I should do a cat here.
  289.    else
  290.       if [ $HOST != $host ] ; then
  291.     rsh $host mv -f /etc/tar-backup/temp.lev1 /etc/tar-backup/$fsname.lev1 2>&1 | tee -a $LOGFILE
  292.       else
  293.         mv -f /etc/tar-backup/temp.lev1 /etc/tar-backup/$fsname.lev1 2>&1 | tee -a $LOGFILE
  294.       fi
  295.    fi
  296.    $TAPE_STATUS  | tee -a $LOGFILE
  297. #   sleep 60
  298.    shift
  299. done
  300.  
  301. # Dump any individual files requested.
  302.  
  303. if [ x != "x$BACKUP_FILES" ] ; then
  304.    date=`date`
  305.    TAR_PART2="+listed=/etc/tar-backup/temp.lev1"
  306.    TAR_PART3="+label='Incremental backup of miscellaneous files at $date'"
  307.  
  308.    echo Backing up miscellaneous files at $date | tee -a $LOGFILE
  309.    echo Last full dump of these files: | tee -a $LOGFILE  
  310.    ls -l /etc/tar-backup/misc.lev0 2>&1 | tee -a $LOGFILE
  311.  
  312.    rm -f /etc/tar-backup/temp.lev1 2>&1 | tee -a $LOGFILE
  313.    cp /etc/tar-backup/misc.lev0 /etc/tar-backup/temp.lev1 2>&1 | tee -a $LOGFILE
  314.  
  315.    echo Backing up miscellaneous files at $date | tee -a $LOGFILE
  316. # Using `sh -c exec' causes nested quoting and shell substitution
  317. # to be handled here in the same way rsh handles it.
  318.    echo -n "Insert first volume for $1 and press Enter"; read dummy
  319.    echo "$EXCLUDE_FILES" | tr ' ' '\12' | \
  320.      sh -c "exec $TAR_PART1 -f $TAPE_FILE $TAR_PART2 $TAR_PART3 \
  321.       $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  322.    if [ $? -ne 0 ] ; then
  323.      echo Backup of miscellaneous files failed. | tee -a $LOGFILE
  324.      # I'm assuming that the tar will have written an empty
  325.      # file to the tape, otherwise I should do a cat here.
  326.    else
  327.      mv -f /etc/tar-backup/temp.lev1 /etc/tar-backup/misc.lev1 2>&1 | tee -a $LOGFILE
  328.    fi
  329.    $TAPE_STATUS | tee -a $LOGFILE
  330. else
  331.    echo No miscellaneous files specified | tee -a $LOGFILE
  332.    false
  333. fi
  334.  
  335. #mt -f $TAPE_FILE rewind
  336. #mt -f $TAPE_FILE offl
  337.  
  338. echo Sending the dump log to $ADMINISTRATOR
  339. #cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  340. #/usr/ucb/mail -s "Results of backup on `date`" $ADMINISTRATOR < $LOGFILE.tmp
  341. (echo ''; echo "Subject: Results of backup on `date`"; echo '';
  342. cat $LOGFILE) >> /usr/spool/mail/root
  343.  
  344. ---8<--- cut here for backup-specs
  345. # site-specific parameters for file system backup.
  346.  
  347. # User name of administrator of backups.
  348. ADMINISTRATOR=root
  349.  
  350. # Hour at which backups are normally done.
  351. # This should be a number from 0 to 23.
  352. BACKUP_HOUR=1
  353.  
  354. # Device to use for dumping.  It should be on the host
  355. # on which the dump scripts are run.
  356. TAPE_FILE=/dev/fd0
  357.  
  358. # Command to obtain status of tape drive, including error count.
  359. # On some tape drives there may not be such a command;
  360. # then simply use `TAPE_STATUS=false'.
  361. TAPE_STATUS=false
  362.  
  363. # Blocking factor to use for writing the dump.
  364. BLOCKING=20
  365.  
  366. # List of file systems to be dumped.
  367. # Actually, any directory may be used,
  368. # but if it has subdirectories on other file systems,
  369. # they are not included.
  370.  
  371. # The host name specifies which host to run tar on.
  372. # It should normally be the host that actually has the file system.
  373. # If GNU tar is not installed on that machine,
  374. # then you can specify some other host which can access
  375. # the file system through NFS.
  376. # Although these are arranged one per line, that is not mandatory.
  377. # It does not work to use # for comments within the string.
  378. BACKUP_DIRS="haven:/"
  379.  
  380. # List of individual files to be dumped.
  381. # These should be accesible from the machine on which the dump is run.
  382. BACKUP_FILES=""
  383.  
  384. # List of files to be excluded from backups
  385. EXCLUDE_FILES="swapfile tmp bin lib usr/bin usr/lib usr/tmp msdos/bin mnt"
  386.