From owner-freebsd-questions Sun Dec 5 10:24:44 1999 Delivered-To: freebsd-questions@freebsd.org Received: from cc942873-a.ewndsr1.nj.home.com (cc942873-a.ewndsr1.nj.home.com [24.2.89.207]) by hub.freebsd.org (Postfix) with ESMTP id EDAFD14BD0 for ; Sun, 5 Dec 1999 10:24:39 -0800 (PST) (envelope-from cjc@cc942873-a.ewndsr1.nj.home.com) Received: (from cjc@localhost) by cc942873-a.ewndsr1.nj.home.com (8.9.3/8.9.3) id NAA48924; Sun, 5 Dec 1999 13:28:50 -0500 (EST) (envelope-from cjc) From: "Crist J. Clark" Message-Id: <199912051828.NAA48924@cc942873-a.ewndsr1.nj.home.com> Subject: Re: How to delete backups N days old? In-Reply-To: <14410.40791.863940.609567@mero-08a.merowingia.uni-kl.de> from Christoph Sold at "Dec 5, 1999 06:22:31 pm" To: cs@cheasy.de Date: Sun, 5 Dec 1999 13:28:50 -0500 (EST) Cc: FreeBSD-Questions@FreeBSD.ORG Reply-To: cjclark@home.com X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Christoph Sold wrote, [Charset iso-8859-1 unsupported, filtering to ASCII...] > I do regular backups of a subtree into some tarballs on another > volume. The tarballs are named including the date > (e.g. bup-19991205.tar.bz2). Those files accumulate over a period of > several days, then get written out to tape. After that, I want to > delete backup tarballs older than, say, one week. > > Looking for an option in find, I went up blank. (Yes, you may specify > files older than another given file, but that_s not what is needed > here. I want to create a script automating the process, leaving a > couple of newer tarballs online.) > > Any ideas really appreciated #!/bin/sh # # Usage: bkupclean [days] # # Clean up backup older than 'days' or default to a week (7 days). # BACKUPDIR is the location of the backups and needs to be set. cd $BACKUPDIR if [ $1 ]; then if [ $1 -lt 1 ]; then echo "$0: Bad number of days. Must be greater than 0." >&2 exit 1 else DAYS=$1 fi else DAYS=7 fi ERASEFROM=`date -v-"$DAYS"d +%Y%m%d` ERASEFROM=bup-"$ERASEFROM".tar.bz2 for BUP in bup*; do if expr $BUP '<=' $ERASEFROM; then rm $BUP fi done exit 0 -- Crist J. Clark cjclark@home.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message