Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Dec 1999 13:28:50 -0500 (EST)
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        cs@cheasy.de
Cc:        FreeBSD-Questions@FreeBSD.ORG
Subject:   Re: How to delete backups N days old?
Message-ID:  <199912051828.NAA48924@cc942873-a.ewndsr1.nj.home.com>
In-Reply-To: <14410.40791.863940.609567@mero-08a.merowingia.uni-kl.de> from Christoph Sold at "Dec 5, 1999 06:22:31 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
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




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