#!/bin/bash # @(#) $Id$ BAR="==============================================================================" MyScript="`basename $0`" MyHost="`hostname -s`" MyStart="`date`" # ---------------------------------------------------------------------------- VOLNBR="${1:-"0000"}" DOW="`date +%a`" # Sun, Mon, ... BTYPE=full BCK="$MyHost-$BTYPE-$DOW-v$VOLNBR.cpio" LOG="$MyHost-$BTYPE-$DOW-v$VOLNBR.log" TOC="$MyHost-$BTYPE-$DOW-v$VOLNBR.toc" WRKDIR="/tmp" DSTDIR="/media/MX200702082108" ARCDIR="/usr/local/data/bcklogs" BSIZE=32768 IDFILE="backid.txt" # really /backid.txt $HOME/bin/create-backid-file # ---------------------------------------------------------------------------- # directories to be backed up; command option specifies not to cross filesystems # work is done after a "cd /", so the "./" prefix is relative to "/" ### just for testing... ### DIRS="$IDFILE ./boot" DIRS="./$IDFILE ./boot ./ ./home ./data ./usr/local ./usr ./opt ./var" # omitted: /tmp /media # ---------------------------------------------------------------------------- echo "" echo "$BAR" echo "Script: $MyScript" echo "Started: $MyStart" echo "$BAR" echo "" echo "Contents of /$IDFILE:" cat /$IDFILE echo "" echo "Mounted file systems:" df -h # ---------------------------------------------------------------------------- echo "" echo "`date` : creating backup" echo " targets: $DIRS" # stdout is empty (always?) when using the -O option of cpio # all content comes from stderr being redirected to stdout cd / && find $DIRS -xdev -depth -print0 | cpio -o -va0 -H crc -C $BSIZE -O $DSTDIR/$BCK >$WRKDIR/$LOG 2>&1 # ---------------------------------------------------------------------------- echo "" echo "`date` : testing and listing backup" # block count is written to stderr, but can't just send stderr to stdout # because the count appears to be emitted at random within stdout stream cpio -i -vt -H crc --only-verify-crc -C $BSIZE -I $DSTDIR/$BCK >$WRKDIR/$TOC 2>$WRKDIR/$TOC.err cat $WRKDIR/$TOC.err >>$WRKDIR/$TOC rm -f $WRKDIR/$TOC.err echo "" echo "`date` : testing/listing done" # ---------------------------------------------------------------------------- echo "" echo "line counts from logs" wc -l $WRKDIR/$LOG $WRKDIR/$TOC | head -2 echo "" echo "block counts (size=$BSIZE) from logs" tail -n 1 $WRKDIR/$LOG $WRKDIR/$TOC echo "" fdcnt=`wc -l $WRKDIR/$TOC | sed 's/^ *//' | cut -d' ' -f1` blkcnt=`tail -n 1 $WRKDIR/$TOC | cut -d' ' -f1` gbcnt=`echo "scale=2; $blkcnt * $BSIZE / 1024 / 1024 / 1024" | bc` echo "$blkcnt blocks @ $BSIZE/block = $gbcnt GB" # ---------------------------------------------------------------------------- echo "" echo "`date` : compressing logs" gzip $WRKDIR/$LOG $WRKDIR/$TOC echo "" echo "`date` : moving logs to $ARCDIR" [ ! -d $ARCDIR ] && mkdir $ARCDIR mv -f $WRKDIR/$LOG.gz $WRKDIR/$TOC.gz $ARCDIR/ chmod u=rw,go= $ARCDIR/$LOG.gz $ARCDIR/$TOC.gz echo "`date` : copying logs to $DSTDIR" cp $ARCDIR/$LOG.gz $ARCDIR/$TOC.gz $DSTDIR/ # ---------------------------------------------------------------------------- MyFinish="`date`" echo "" echo "$BAR" echo "Script: $MyScript" echo "Started: $MyStart" echo "Finished: $MyFinish" echo "Usage: $gbcnt GB; $fdcnt files/dirs" echo "$BAR" # ---------------------------------------------------------------------------- # end # ----------------------------------------------------------------------------