From owner-freebsd-questions@FreeBSD.ORG Wed Nov 21 13:57:18 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A796716A468 for ; Wed, 21 Nov 2007 13:57:18 +0000 (UTC) (envelope-from roberthuff@rcn.com) Received: from smtp02.lnh.mail.rcn.net (smtp02.lnh.mail.rcn.net [207.172.157.102]) by mx1.freebsd.org (Postfix) with ESMTP id 172DF13C515 for ; Wed, 21 Nov 2007 13:57:17 +0000 (UTC) (envelope-from roberthuff@rcn.com) Received: from mr08.lnh.mail.rcn.net ([207.172.157.28]) by smtp02.lnh.mail.rcn.net with ESMTP; 21 Nov 2007 08:57:16 -0500 Received: from smtp01.lnh.mail.rcn.net (smtp01.lnh.mail.rcn.net [207.172.4.11]) by mr08.lnh.mail.rcn.net (MOS 3.8.5-GA) with ESMTP id JJB86182; Wed, 21 Nov 2007 08:57:16 -0500 (EST) Received: from 209-6-22-188.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com (HELO jerusalem.litteratus.org.litteratus.org) ([209.6.22.188]) by smtp01.lnh.mail.rcn.net with ESMTP; 21 Nov 2007 08:56:07 -0500 From: Robert Huff MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18244.14646.98900.820824@jerusalem.litteratus.org> Date: Wed, 21 Nov 2007 08:57:10 -0500 To: "=?ISO-8859-1?Q?Andreas_Wider=F8e_Andersen?=" In-Reply-To: <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com> References: <23ed14b80711210539w4bed1enc180f8e32ec76881@mail.gmail.com> X-Mailer: VM 7.17 under 21.5 (beta28) "fuki" XEmacs Lucid X-Junkmail-Whitelist: YES (by domain whitelist at mr08.lnh.mail.rcn.net) Cc: freebsd-questions Subject: Need help with backup shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Nov 2007 13:57:18 -0000 =?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