Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
If there's not a script, there should be. We wrote one for our own use at our company, but I will see about releasing this into the wild if possible. –  Andrew M. Nov 4 '11 at 21:14
    
Great - I will appreciate if it can be open-sourced. Posting on github would be a great odea. –  SyRenity Nov 6 '11 at 10:02

4 Answers 4

up vote 7 down vote accepted

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.

share|improve this answer
    
Cool - that exactly what I needed. –  SyRenity Sep 26 '12 at 17:57
    
great stuff, wasn't aware of this one –  dyasny Oct 27 at 19:56

I would leverage the versioning or labeling system you use to identify builds. You could also identify packages by date with a script running on the server hosting the repository.

share|improve this answer
    
You mean by checking the version in file names? This is my line of thought as well, but would be nice to have an automated script for this. –  SyRenity Nov 6 '11 at 10:03
1  
Also remember that the filename is not necessarily indicative of the version. I.e., I can rename an RPM to anything I want; yum will use the metadata of the RPM instead. –  Andrew M. Nov 6 '11 at 15:26

If the uploads happen everyday, why not consider deleting the old files which are older beyond say certain number of days(in terms of their access/modification times)? Find and just delete them. If you could have your developers upload builds such that they put the name of the current month into the filename when uploading, it would make sense from the filename directly that the file was uploaded in so called month'year and it makes sense to delete just by the basis of looking at the filename. It would make easy for your script automation to just consider removing those files or just keep those files which match previous month and current month. Just a thought.

share|improve this answer

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 ~]#
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.