Wikis - Page

Automated Orphaned Packages Deletion from ZLM Package Repository

0 Likes

Contents:









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-package-deletion.sh Orphan-packages-batch-delete-count
Example:
sh orphan-package-deletion.sh 100





#!/bin/bash
sleep_interval=10
function usage()
{
echo USAGE:
echo "$0 <Orphan-packages-batch-delete-count> "
exit 1
}

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

orphan_id_log="/tmp/orphan-pkgids.log"
orphan_deleted_log="/tmp/orphan-deleted.log"
packages_to_del=$1
total_count=0

while true ;
do
count=0
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 ;
fi

while [ $total_count -gt $count ] ;
do

pkgid_list=""
count=`expr $count $packages_to_del`

for i in `cat /tmp/orphan-packages.log | head -n $count | tail -n $packages_to_del`;
do
pkgid_list="$pkgid_list $i"
#trim left and right spaces
pkgid_list="${pkgid_list#"${pkgid_list%%[![:space:]]*}"}"
pkgid_list="${pkgid_list%"${pkgid_list##*[![:space:]]}"}"
done

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
fi
array=($pkgid_list)
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;
done
done
fi



Labels:

How To-Best Practice
Comment List
Related
Recommended