Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Nov 2007 08:57:10 -0500
From:      Robert Huff <roberthuff@rcn.com>
To:        "=?ISO-8859-1?Q?Andreas_Wider=F8e_Andersen?=" <wodfer@gmail.com>
Cc:        freebsd-questions <freebsd-questions@freebsd.org>
Subject:   Need help with backup shell script
Message-ID:  <18244.14646.98900.820824@jerusalem.litteratus.org>
In-Reply-To: <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com>
References:  <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

=?ISO-8859-1?Q?Andreas_Wider=F8e_Andersen?= writes:

>  Does anyone use a script like this today that they can share? I'm
>  not a shell scripter myself so any help is highly appreciated.

	My current scripts are appended; constructive criticism is
welcome.
	And the key to "<= 30 days" would involve "find".



			Robert Huff

	****		full_backup	****

#!/bin/sh 

#set -x

#
#          Set variables
#

PATH=/bin:/sbin:/usr/sbin:/bin:/usr/bin

echo "Backup started." at `date`

DUMP_DATE=`date | awk '{printf "%d.%s.%d\n", $6, $2, $3}'`
DUMP_DAY=`date | awk '{print $1}'`
DUMP_LEVEL=0
DUMP_CACHE=32
DUMP_DEVICE=/backup
DUMPDATES_FILE=/etc/dumpdates
export DUMP_DATE DUMP_DAY DUMP_LEVEL DUMP_CACHE DUMPDATES_FILE


#        make the drive available

#mount /dev/da3a /backup
mount $DUMP_DEVICE
if [ $? -eq 0 ];
    then
        echo "/backup clean"
    else
        fsck -y $DUMP_DEVICE
        fsck $DUMP_DEVICE
        echo "/backup cleaned"
        mount $DUMP_DEVICE
fi
echo "Disk mounted"
cd $DUMP_DEVICE/$DUMP_DAY
echo "Using "`pwd`
chflags -R noschg .

/etc/backup/dump_root
/etc/backup/dump_var
/etc/backup/dump_usr

#     show disk usage

du -k $DUMP_DEVICE/$DUMP_DAY

#     Clean up and go home

cd /tmp
sleep 5
umount $DUMP_DEVICE
echo "Disk unmounted."

echo "Backup complete." at `date`


	****		dump_usr	****

#! /bin/sh 

#set -x

#          Set variables

PATH=/bin:/sbin:/usr/sbin:/bin:/usr/bin

#
#          backup /usr
#

if [ ! -d usr ];
    then mkdir usr
fi
cd usr
if [ $? -eq 0 ];
    then
        pwd
        LINES=`ls -al /backup/$DUMP_DAY/usr | wc -l`
	   if [ $LINES -ne 3 ];
		  then
		      rm -r * 
	   fi
	   echo "Usr"
	   dump $DUMP_LEVEL -D $DUMPDATES_FILE -C $DUMP_CACHE -Lau -f $DUMP_DATE.usr.dump /usr 
	   if [ $? -eq 0 ];
		  then
#
#    Compressing the weekly isn't worth the effort
#		  (takes too long relative to space reclaimed)
#		
		      if [ $DUMP_LEVEL -ne 0 ];
			  then
			  echo "Compressing with gzip..."
			  gzip $DUMP_DATE.usr.dump
#			  echo "Compressing ..."
#			  tar -czf $DUMP_DATE.usr.dump.tgz $DUMP_DATE.usr.dump && \
#			      rm $DUMP_DATE.usr.dump
			  echo "done"
		      fi
	   else
	       echo "Dump suceeded."
	   fi	 
	   cd ..
fi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?18244.14646.98900.820824>