Best way to clean up Yum repository?

We have a custom Yum repo that our developers upload builds to.

The problem is that after some time it becomes cluttered with old versions.

Removing the old versions manually is quite annoying, so before we try to automate it ourselves, I wonder if there any script that would clean old RPM's based on version (preferred) or time of upload.

Best would be if we could specify to simple save X last versions, and erase anything else. Then we could cron it and just let it run daily.

Thanks for any idea.


Solution 1:

The "simple" way is to just dump everything in a directory and run:

rm $(repomanage --keep=2 --old /path/to/repo)
createrepo /path/to/repo

...the more complicated way is to setup koji/etc. to do your builds and create the repos.

Solution 2:

Check out the "repomanage" utility from the yum-utils RPM. It does exactly what you're looking for.

[root ~]# repomanage --help
usage:
  repomanage: manage a directory of rpm packages. returns lists of newest
            or oldest packages in a directory for easy piping to xargs
            or similar programs.
  repomanage [--old] [--new] path.


  options:
    -h, --help            show this help message and exit
    -o, --old             print the older packages
    -n, --new             print the newest packages
    -s, --space           space separated output, not newline
    -k KEEP, --keep=KEEP  newest N packages to keep - defaults to 1
    -c, --nocheck         do not check package payload signatures/digests
[root ~]#