Re: backup strategy (was Re: reconstruct the system)

From: Maurits van Rees (maurits_at_vanrees.org)
Date: 06/03/05

  • Next message: David Jardine: "Re: Discover device drivers built into a kernel image"
    Date: Fri, 3 Jun 2005 21:24:56 +0200
    To: debian-user@lists.debian.org
    
    
    

    On Fri, Jun 03, 2005 at 02:28:26PM -0400, Marty wrote:
    > If my backup scripts don't quite do it for you, here is an excellent
    > web page with a general discussion of rsync as a backup tool, with
    > more elaborate backup script, and links to other backup scripts:
    > http://www.mikerubel.org/computers/rsync_snapshots/

    rsnapshot is a Debian package that uses this approach. I use that for
    taking snapshots on my home machine and a remote server.

    I also do a nightly backup to cd. Here's my script. The comments
    _should_ make everything clear. On my system it takes about an hour.

    ############################################

    #! /bin/sh
    # Make a full backup divided into several tar bzipped files. Put these
    # into iso files that will fit on a CD-RW so you can have 7 CD-RWs and
    # do this backup every day (night) of the week. Standard practice: the
    # important stuff goes on the first CD so it gets written
    # automatically, unless you forget to put the CD in the drive. :)

    # Call this script with a name for the backup directory

    # First commandline option is added to the name of the backup.
    # If no option is given, the current date is used.
    if test "x${1}" == "x"; then
        NAME=`date -Idate`
    else
        NAME=$1
    fi

    # Edit these lines
    MAINBACKUP=/backup/tar
    TARDIR=$MAINBACKUP/$NAME
    ROOTFS=/
    READMEFILENAME=README

    # Dir and script for saving some info about your system, if you have
    # those:
    SYSINFODIR=/var/local/system-info
    SYSINFOSCRIPT=/usr/local/bin/system-info

    # Make sure the necessary directories exist
    mkdir -p $TARDIR
    mkdir -p $SYSINFODIR

    echo "Backup started:"
    date
    cd $ROOTFS
    echo "Backup from computer $(hostname) made with $0 script." > $TARDIR/$READMEFILENAME
    echo $NAME >> $TARDIR/$READMEFILENAME

    if test -x $SYSINFOSCRIPT; then
        cd "$SYSINFODIR"
        $SYSINFOSCRIPT
        cd -
    fi

    echo "Tarring various stuff ..."
    # Make sure to adjust the excludes to match your system.
    tar -cjf $TARDIR/div.tar.bz2 * --exclude backup --exclude extra --exclude firstdisk --exclude home --exclude sys --exclude music --exclude opt --exclude proc --exclude tmp --exclude usr --exclude var --exclude snapshot --exclude root/snapshot --exclude cdrom

    echo "Tarring home ..."
    tar -cjf $TARDIR/home.tar.bz2 home

    echo "Tarring var various ..."
    tar -cjf $TARDIR/var-rest.tar.bz2 var --exclude var/cache/apt --exclude /var/spool/bootcd

    echo "Tarring usr/local ..."
    tar -cjf $TARDIR/usr-local.tar.bz2 usr/local
    echo "Tarring usr/lib ..."
    tar -cjf $TARDIR/usr-lib.tar.bz2 usr/lib
    echo "Tarring usr/share ..."
    # /usr/share/doc is getting way too large and isn't all that important
    # in a backup.
    tar -cjf $TARDIR/usr-share.tar.bz2 usr/share --exclude usr/share/doc
    echo "Tarring usr various ..."
    tar -cjf $TARDIR/usr-rest.tar.bz2 usr --exclude usr/local --exclude usr/lib --exclude usr/share

    # Make an easy softlink to the latest backup
    cd $MAINBACKUP
    rm -f latest
    ln -s $TARDIR latest

    # Make md5sums
    echo "md5summing $TARDIR/*bz2 ..."
    cd $TARDIR
    for i in *bz2; do
        md5sum $i > $i.md5
    done

    # Put it on cd images. It's trial and error to find out which goes
    # where in order to make the images not too large.
    mkdir cd1 cd2 cd3
    mv div* home* usr-local* var-rest* cd1
    mv usr* cd2
    # Put some handy info on the cds
    for i in cd1 cd2 cd3; do
        cp $READMEFILENAME "$0" $i
    done
    rm $READMEFILENAME

    # Only necessary/handy when you keep a package archive:
    echo "Copying var/cache/apt ..."
    cp -r /var/cache/apt $TARDIR/cd3
    cd cd3
    for i in * */* */*/*; do
        if test -f $i; then
            md5sum $i >> apt.md5
        fi
    done
    cd ..

    # Make iso files for each cd. This is done by my mki script, which
    # basically just calls mkisofs
    mki *

    # The cd directories can be removed now as we have iso files
    rm -r cd*/

    echo "Backup ended:"
    date

    # Checking and blanking below are only useful if you use cd
    # rewritables.

    # Before overwriting the previous backup check if any md5sums on the
    # cd are still correct. If not you may have some bit rot on your
    # cd. Use it as a frisbee then. ckcdsums is a script that basically
    # mounts the cd, does 'md5sum -c *md5*', reports any errors and
    # unmounts it again.
    echo "Checking CD-RW..."
    ckcdsums
    echo "Fast blanking CD-Rom..."
    cdrecord -blank=fast

    # The burncheck script basically calls cdrecord to burn the iso,
    # ejects the cd and reloads it (possibly superfluous), then calls the
    # ckcdsums script mentioned above.
    echo "Burning 1st cd to CD-Rom..."
    burncheck cd1.iso
    echo "Burning ended:"
    date

    # Report how large the iso files are:
    ls -lh *

    # Check if there is enough space left for future backups on the
    # filesystem:
    /bin/df -h "$MAINBACKUP"

    ############################################

    For laughs: John Cleese at the renowned Institute for Backup Trauma:
    http://www.backuptrauma.com/

    -- 
    Maurits van Rees | http://maurits.vanrees.org/ [Dutch/Nederlands] 
    Public GnuPG key: keyserver.net ID 0x1735C5C2
    "Let your advance worrying become advance thinking and planning."
     - Winston Churchill
    
    

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    


  • Next message: David Jardine: "Re: Discover device drivers built into a kernel image"

    Relevant Pages

    • Re: /usr/informix/bin/onbar[84]: 22716 Memory fault
      ... write debug traces (setting BAR_DEBUG parameter in onconfig ... I'm getting the above error when running onbar from a script. ... echo EORROR_NUMBER before backup is equal to 0 ...
      (comp.databases.informix)
    • Feedback on backup script
      ... The one problem I have is that the script keeps stopping at lines 633,635 and or 637 with the error "Path Not Found" I have emailed the original author for help but haven't heard back yet. ... I was just wondering if the problem could be that the account running the script doesn't have correct permissions to a share/directory/file that it's trying to backup? ... ' always one less than the actual number of folders. ... ' Show the user free space info on all available disk drives ...
      (microsoft.public.scripting.vbscript)
    • Re: [SLE] Backup to CD/DVD -- recommended software?
      ... Here is the script I have used for CD-Rbackup of a specific ... Next is the CD-RW backup script. ... echo We are in the datasheets.CD-RW.backup script! ... failing to match md5sums or getting IO errors ...
      (SuSE)
    • Re: Maintain backup directory
      ... When I run the script (after setting target to the right ... the backup media runs out of ... Remove the word "echo" from Line #18 to enable the file deletion. ...
      (microsoft.public.scripting.wsh)
    • Re: Maintain backup directory
      ... When I run the script (after setting target to the right ... Consequently, the backup media runs ... Remove the word "echo" from Line #18 to enable the file deletion. ...
      (microsoft.public.scripting.wsh)