Cybersecurity
DevOps Cloud
IT Operations Cloud
Contents:
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 :
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 .
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