Chapter 13. Deleting Orphaned Packages

Red Hat Update Infrastructure does not delete orphaned packages. Orphaned packages are package files no longer referenced by any repositories but remain on the file system and consume disk space. Package files can become orphaned packages as a result of the configuration settings or repository deletion. If unsure about the deletion of these packages consider enlarging disk space instead of removing the packages.
This chapter explains how to delete orphaned packages on Red Hat Update Appliance and CDS servers to reclaim disk space. This can either be done by modifying the configuration settings or running the pulp-purge-packages script.

Important

These procedures delete packages from Red Hat Update Infrastructure. A complete back up should be performed before using the following procedures. See Chapter 14, Backup and Restore for Red Hat Update Infrastructure for more information.

Procedure 13.1. Deleting Orphaned Packages by modifying configuration settings

  • On the Red Hat Update Appliance Server, open /etc/pulp/pulp.conf in your preferred text editor. Set remove_old_versions to true to have Red Hat Update Infrastructure delete references to old packages versions beyond the versions specified in num_old_pkgs_keep.
    # True/False to flag if we should remove older rpms
    remove_old_versions: true
    # Integer to specify how many old packages to keep.
    num_old_pkgs_keep: 2
    

Procedure 13.2. Deleting Orphaned Packages from a CDS

  1. Open /etc/pulp/cds/cds.conf in your preferred text editor.
  2. Set cds_remove_old_versions to true.

    Note

    Setting remove_old_versions to true on the Red Hat Update Appliance server and cds_remove_old_versions to false on the CDS will result in errors as the CDS will attempt to synchronize packages that no longer exist on the Red Hat Update Appliance server.
    To correct this set both to true to remove all old packages beyond the version specified by num_old_pkgs_keep or set remove_old_packages to false on the Red Hat Update Appliance server to retain all old packages and make the required changes for the CDS.
  3. Set num_old_pkgs_keep to the required number of packages to keep.

    Note

    Make sure that num_old_pkgs_keep on the CDS is set to the same or lower than on the Red Hat Update Appliance server if remove_old_versions is true on the Red Hat Update Appliance server to ensure that the CDS is not trying to synchronize packages that do not exist on the Red Hat Update Appliance server.
  4. Save and exit the file.
    # True/False to flag if we should remove older rpms
    cds_remove_old_versions: true
    # Integer to specify how many old packages to keep.
    num_old_pkgs_keep: 2
    
    This will remove old package versions beyond the versions specified in num_old_pkgs_keep on the CDS the next time it is synchronized.

Procedure 13.3. Deleting Orphaned Packages using the pulp-purge-packages script

Packages can become orphaned when the associated repositories are deleted. To delete orphaned packages:
  1. Stop the httpd service.
    # service httpd stop
    
  2. View packages available for deletion.
    # pulp-purge-packages --dry-run
    
  3. Run the pulp-purge-packages script to delete orphaned packages and reclaim disk space.

    Warning

    This script will delete all packages not associated with any repositories. Including packages that were uploaded with the 'pulp-admin content upload' command.
    # pulp-purge-packages
    

    Note

    The pulp-purge-packages script logs to /var/log/pulp-purge-packages.
  4. Start the httpd service.
    # service httpd start
    

Note

The pulp-purge-packages script automatically detects the packages and repositories for package deletion, so the script can be run interchangeably on both the Red Hat Update Appliance and CDS servers. View all options and commands by using the --help command:
Options:
  -h, --help            show this help message and exit
  -p PACKAGES_DIR, --packages-dir=PACKAGES_DIR
                        packages directory to purge of orphaned packages (will
                        be detected if not specified)
  -r REPOS_DIR, --repos-dir=REPOS_DIR
                        repository directory to search for referenced packages
                        (will be detected if not specified)
  -d, --dry-run         dry run only, do not actually purge any packages

Example 13.1. Example Script Output

[root@rhui2 ~]# pulp-purge-packages --dry-run
2013-03-22 15:28:20,405 - Starting run of ./pulp-purge-packages

WARNING: httpd must be stopped before this script can be run.

WARNING: This script will delete all packages not associated with any repositories.  Including packages that were uploaded with the 'pulp-admin content upload' command.

Continue? Y/N: y

2013-03-22 15:28:21,550 - Detecting packages and repository directories.
2013-03-22 15:28:21,551 - Using /var/lib/pulp/repos as repository directory.
2013-03-22 15:28:21,551 - Using /var/lib/pulp/packages as packages directory to purge.
2013-03-22 15:28:21,551 - Dry run specificed, No actual deletes will occur.
2013-03-22 15:28:21,552 - Getting all referenced packages, this may take a few minutes...
<logging of found packages to delete>