Removing outdated files

J

Jan Danielsson

Hello all,

I have a backup system which produces files using the following pattern:

<basename>.<date>.<extension>

For instance:

documents.2007-01-01.tar.bz2.gpg
documents.2007-01-02.tar.bz2.gpg
.
.
.
system_files.2007-01-01.tar.bz2.gpg
system_files.2007-01-02.tar.bz2.gpg
.
.
.
etc.

Obviously, I have little need for *all* those files. What I want to
do is to delete old files according to this 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 for each week.
- If backups are more than two months old, then keep only the latest
one for each month.
- If backups are more than two years old, then keep only the latest
one for each year.

I have generated a list of files, parsed the date from the entries,
and created date object from them. I have a list where I have grouped
the "basenames" together. I.e. (lists in a list):

documents
2007-01-01
2007-01-02
.
.
.
system_files
2007-01-01
2007-01-02
.
.
.

Now all I have to do is iterate through the date-lists for each of
the basenames, and apply the rules! Well..

How does one group by week, for instance? I'd like to create a new
set of lists which looks like this:

basename:documents
week:01
2007-01-01
2007-01-02
week:02
2007-01-07
2007-01-08

Date-grouping is dead easy in SQL, but I don't feel like resorting to
postgresql just for this. :)

I've been looking at the datetime.date class, but I can't see any
easy way to parse the week number from it. I could calculate this
information by brute force -- but I get a feeling that there are
functions in Python to extract week numbers from a date.

--
Kind regards,
Jan Danielsson
------------ And now a word from our sponsor ------------------
For a quality usenet news server, try DNEWS, easy to install,
fast, efficient and reliable. For home servers or carrier class
installations with millions of users it will allow you to grow!
---- See http://netwinsite.com/sponsor/sponsor_dnews.htm ----
 
G

Gabriel Genellina

I've been looking at the datetime.date class, but I can't see any
easy way to parse the week number from it. I could calculate this
information by brute force -- but I get a feeling that there are
functions in Python to extract week numbers from a date.

..isocalendar()


--
Gabriel Genellina
Softlab SRL






__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
L

Laurent Pointal

Jan Danielsson a écrit :
Hello all,

I have a backup system which produces files using the following pattern: ....

Obviously, I have little need for *all* those files. What I want to
do is to delete old files according to this 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 for each week.
- If backups are more than two months old, then keep only the latest
one for each month.
- If backups are more than two years old, then keep only the latest
one for each year.

You should take a look at snapy, AFAIR it does things like this to
manage snapshot backups (with cp [+rsync] [+ssh]).

http://www.flibuste.net/libre/snapy/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top