Skip to main content

Remove unneeded historical files

Project description

You may have backups.

Every day, your precious stuff is saved in a safe place.

But you may have too much of that…

This script will select for you what files to drop, based on a retention policy such that as files get older you can keep less of them. The default policy will keep all the files in the last two weeks, a file every week for the last three months, a file every month for the last year, a file every year forever.

The script takes in input the existing files on command line and by default will print on stdout the files to delete. You can use a chain of commands such as:

ls | xargs weeder | xargs rm

to run in a cron job every day to keep your backup directories light.

Our glorious help

Running weeder -h you might be told:

usage: weeder [-h] [-p AGE:DIST [AGE:DIST ...]] [-f REGEX] [-r YYYY-MM-DD]
              [--print-keepers | --print-goners] [-q | -v]
              [FILE [FILE ...]]

positional arguments:
  FILE                  the files to weed

optional arguments:
  -h, --help            show this help message and exit
  -p AGE:DIST [AGE:DIST ...], --policy AGE:DIST [AGE:DIST ...]
                        state that, of every file older than AGE days, we want
                        to keep at least one every DIST days
                        [default: 14:7 84:28 364:364]
  -f REGEX, --format REGEX
                        the pattern to extract a date from a file name
                        [default: (\d{4})-(\d{2})-(\d{2})]
  -r YYYY-MM-DD, --refdate YYYY-MM-DD
                        reference date to establish retention [default: today]
  --print-keepers       print the files to keep
  --print-goners        print the files to delete [default]
  -q, --quiet           talk less
  -v, --verbose         talk more

but who knows, really.

Running tests

You can run:

python3 setup.py test

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weeder-0.1.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file weeder-0.1.tar.gz.

File metadata

  • Download URL: weeder-0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for weeder-0.1.tar.gz
Algorithm Hash digest
SHA256 a9eac17275982b9eb8aae2c731204105562d148cb60b2533d64e9893de1d4c27
MD5 70a2388105126c73a51cfa607f2c917d
BLAKE2b-256 48f42876b1270b083b7ccad97be9c22ae0a81e8fcf1b25ca260db5b4de3c96b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page