Removing outdated files

Discussion in 'Python' started by Jan Danielsson, Jan 23, 2007.

  1. 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 ----
    Jan Danielsson, Jan 23, 2007
    #1
    1. Advertising

  2. At Tuesday 23/1/2007 02:17, Jan Danielsson wrote:

    > 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
    Gabriel Genellina, Jan 23, 2007
    #2
    1. Advertising

  3. Gabriel Genellina wrote:
    >> 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()


    .thanks()

    --
    Kind regards,
    Jan Danielsson
    Jan Danielsson, Jan 23, 2007
    #3
  4. 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/
    Laurent Pointal, Jan 23, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harlan Osier

    HTML is outdated now !

    Harlan Osier, Jul 13, 2004, in forum: HTML
    Replies:
    13
    Views:
    781
    Webcastmaker
    Jul 14, 2004
  2. Raf256

    why IE 7 will be outdated

    Raf256, Dec 23, 2005, in forum: HTML
    Replies:
    2
    Views:
    929
  3. Jim Bancroft

    Use XSL to remove "outdated" nodes?

    Jim Bancroft, Jul 2, 2003, in forum: XML
    Replies:
    6
    Views:
    1,041
    Jim Bancroft
    Jul 2, 2003
  4. Markus Dreyer

    Accelerated C++ book outdated?

    Markus Dreyer, Jan 21, 2004, in forum: C++
    Replies:
    35
    Views:
    2,141
    Attila Feher
    Jan 28, 2004
  5. Mark Rae
    Replies:
    2
    Views:
    36,968
    Mark Rae
    Jul 11, 2006
Loading...

Share This Page