Subject: Re: Removing dated files
To: Jan Danielsson <jan.m.danielsson@gmail.com>
From: matthew sporleder <msporleder@gmail.com>
List: netbsd-users
Date: 01/22/2007 09:57:05
On 1/22/07, Jan Danielsson <jan.m.danielsson@gmail.com> wrote:
> Hello all,
>
> I have a bunch of backup archives which are dated:
>
> .
> .
> .
> documents.2006-12-24.tar.bz2.gpg
> documents.2006-12-25.tar.bz2.gpg
> documents.2006-12-26.tar.bz2.gpg
> documents.2006-12-27.tar.bz2.gpg
> .
> .
> .
> systemfiles.2006-11-24.tar.bz2.gpg
> systemfiles.2006-11-25.tar.bz2.gpg
> systemfiles.2006-11-26.tar.bz2.gpg
> systemfiles.2006-11-27.tar.bz2.gpg
> .
> .
> .
>
> I would like to remove some (most!) of these files according to a
> pattern:
>
> - Keep all backup files which are two weeks (or less) old
> - If backups are more than two weeks old, then keep only the latest one
> that week.
> - If backups are more than two months old, then keep only the latest one
> that month.
> - If backups are more than two years old, then keep only the latest one
> that year.
>
> This feels like something that probably has been done a gazillion
> times before. Am I reinventing the wheel if I write a script which
> performs this kind of maintenance? All I have to do is use a regexp to
> parse the "base name" and dates, build a tree of it all, and then
> traverse the trees, clobbering anything that looks "old" and "redundant"
> (according to the rules). It seems like quite a simple thing to write,
> but not simple enough for me to go ahead and write without asking first.
I believe 'find' is such a tool. You'll have to make multiple passes
against many different archive directories, or else you'll end up
keeping only the fifteen most recent files. (at least, that's the way
the solution presented itself to me)
_Matt