Removing outdated files
jan.m.danielsson at gmail.com
Tue Jan 23 06:17:15 CET 2007
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.
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):
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:
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.
------------ 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 ----
More information about the Python-list