Tidy RPM Cache script

1160 GPL v3    


Deleting Obsolete RPM Files from the cache





Tidy RPM Cache script (previously Delete Obsolete RPMS) is a script that can used to deleting obsolete RPM files from a directory.

The Python script included on this page deletes obsolete RPM package files from the package manager's cache. RPM is a software management system used on many Linux distributions including Fedora. This script may be useful if you wish to minimise the disk space requirement of locally stored update packages.

Usage Synopsis

rm_obsolete_rpms.py {-d|--dir=dir}
 {-v|--verbose} {-q|--quiet}
 {-u|--usage} {-h|--help} {--version}

This script deletes obsolete files by comparing the version information of all RPM package files which provide the same software package. You can specify any number of paths of directories to search and you can also exclude specific packages from being tested for obsolescence.

To run this script simply specify the path of a directory containing RPM package files using the --dir option. For example, to delete obsolete RPMs from the directory '/tmp/packages', execute the following command:

tidy-rpm-cache.py --dir=/tmp/packages

The script will display a list of RPM packages it has deemed as obsolete and ask for confirmation before deleting them from the filesystem. To disable the confirmation message, add the --force option.

You can also configure the script to keep a specific number of obsolete versions of a package. For example, if you wish to keep one obsolete version of each package in case the newest version causes problems, you can achieve this using the following command:

tidy-rpm-cache.py --dir=/tmp/packages --num-obsolete=1

Note that the --num-obsolete option specifies the number of versions to keep excluding the newest version of the package. In this case all but the newest and the second newest versions would be deleted.

To prevent the deletion of specific packages you can supply a regular expression which will be tested against all RPM package filenames. If the expression matches, then that RPM will be excluded from the obsolescence test. For example, to exclude all kernel packages, execute the following command:

tidy-rpm-cache.py --dir=/tmp/packages --exclude='^kernel.*'

Note: always enclose the regular expressions in single quotes to prevent them being interpreted as a glob expression.

To see more information about what the script is doing and what packages it is examining, add the --verbose option. To disable all output except warning and error messages, add the --quiet option.

For more information on these and other options, please read the help information provided with the script. You can access this by adding the --help option. For example:

tidy-rpm-cache.py --help

Minimising the Size of a YUM Cache Directory

The reason for writing this script was to provide a feature missing in the current implementation of YUM. YUM is an RPM-based software management system which provides an option to keep downloaded package files in a cache directory for later use. It does not however provide a feature to delete package files which have become obsolete because a newer version of the same package has been downloaded. The following command could be executed manually or from a cron script to clean the default cache directory on Fedora Linux systems:

tidy-rpm-cache.py --dir=/var/cache/yum --force

Test System

Fedora 9
python 2.5.1-25
Last updated on October 19th, 2009

#delete obsolete RPM #system administration #software distribution #clean #delete #obsolete #RPM

Tidy RPM Cache script - Delete Obsolete RPMs script example

0 User reviews so far.