Automated Orphaned Packages Deletion from ZLM Package Repository

over 11 years ago


Package Repository and Orphan Packages

In ZLM, the packages (RPMs) are associated to bundles and these packages part of the bundles are known as managed-rpm . The bundle’s package information is stored into the ZLM Server’s database across several tables, and the uploaded packages content are located on the filesystem at a definite path package-repository (pkg-repo). This content system which stores softwares or update packages is called package-repository on ZLM Server. It is a directory named pkg-repo present at the default path /var/opt/novell/zenworks . Only single instance of a package based on N.E.V.R.A.T (name,epoch,version,release,arch,target) and checksum can be imported into ZLM package repository. The packages added or imported into same or different bundles with same N.E.V.R.A.T. are links to the bundles.

Importing the same packages from multiple sources or distributions into different bundles does not duplicate them under package repository but are just symbolic link/reference to the single instance of this package under /var/opt/novell/zenworks/pkg-repo/packages . On deleting the bundles or its versions from ZCC , its imported packages metadata in database and files are not automatically cleaned under pkg-repo path . If no other bundles references the imported package file , it is called an Orphan RPM Package. The packages orphaned by cleaning or deleting the bundle, are retained under the repository to avoid the overhead of re-importing and related computations. The orphaned package files thus created are retained at the same pkg-repo path where it gets imported.
The listing of orphan packages on ZLM server can be obtained in following ways :

    • ZCC : Go to Tools > PackageList and search for Orphan RPM Packages

  1. ZLMAN (CLI) : zlman lp --orphan

Over a period of time ZLM repository scales up and it becomes a recommended practice to cleanup package repository of these orphan packages to reclaim the disk storage space or avoid conflicts during importing . In ZCC , the permanent cleanup of the package repository is allowed by performing the cleaning tasks for upto 100 orphan packages, based on repeated search and successive deletion operation. On deleting the selected orphan packages, the single instance of imported package file is removed on the disk, reclaiming the space.

There is no direct mechanism to list and delete all the orphan packages at the CLI(zlman) via single operation for all the orphaned packages in the repository. The script allows administrator to perform batch deletion of all the orphan package files under repository by specifying the desired deletion count.

Configuration and Usage Instructions

This Script performs listing and batch deletion of all the orphaned packages, by using zlman lp --orphan and zlman dp commands on ZLM 7.2 Server or later. It is suggested to execute the script with Orphan-packages-batch-delete-count as 100 or less. All the orphan packages and the packages deleted are logged into /tmp/orphan-pkgids.log and /tmp/orphan-deleted.log files for reference.

Below are the configuration details .

  1. Set the /root/.zlmanrc file to username as administrator and its password, to the skip interactive prompt. .

  • (Optional) Change the value of sleep_interval defined in this script based on the count of packages to be delete each time.

  • (Optional) Increase JVM heap memory settings for the zlman script to higher value if needed.

Script Usage:

sh Orphan-packages-batch-delete-count
sh 100

function usage()
echo USAGE:
echo "$0 <Orphan-packages-batch-delete-count> "
exit 1

if [ $# -lt 1 ] || [ $# -gt 1 ]; then


while true ;
zlman lp --orphan | cut -d'|' -f1 -s | grep ^[0-9] > /tmp/orphan-packages.log
cat /tmp/orphan-packages.log >> $orphan_id_log ; echo ""
total_count=`wc -l /tmp/orphan-packages.log | cut -f1 -d " "`
echo " Total Orphan Packages found for deletion: $total_count. For details refer log file /tmp/orphan-pkgids.log "

if [ $total_count -eq 0 ]; then
echo " No more Orphan Packages present in package-repository for deletion "; echo "" ;
rm -f /tmp/orphan-packages.log
exit 1 ;

while [ $total_count -gt $count ] ;

count=`expr $count $packages_to_del`

for i in `cat /tmp/orphan-packages.log | head -n $count | tail -n $packages_to_del`;
pkgid_list="$pkgid_list $i"
#trim left and right spaces

echo "Package deleted with ID: [$pkgid_list]"

zlman dp $pkgid_list

if [ $? -ne 0 ] ; then
echo " Could not delete some orphaned packages as server might be waiting to process deletion requests now. Please wait sometime!"
echo " Delete left-over orphan packages by running the script again with lesser orphan count than before" ;
rm -f /tmp/orphan-packages.log
# exit 1
echo " Orphan Packages permanently deleted from package-repository : ${#array[@]} "
echo " Orphan Packages successfully deleted: (${#array[@]}) : $pkgid_list " >> $orphan_deleted_log
echo " ------------------------ `date`-------------------------- " >> $orphan_deleted_log
sleep $sleep_interval;


How To-Best Practice
Comment List
Related Discussions