In order to inspect a database of another system, the rpm and yum databases will need to be extracted into an alternate root (similar to a chroot structure). Then, yum & rpm commands can be used on a stable system with flags such as –installroot= and –root=. Not all commands will work in the alternate root, as the root does not contain all files that were on the original system.
How to backup rpm & yum databases
Run the following commands to collect the required database and repository details:
# package-cleanup --dupes > /tmp/package_cleanup.dupes # package-cleanup --problems > /tmp/package_cleanup.problems # tar -cvjf /tmp/rpmdb.$(hostname -s).tar.bz2 /tmp/package_cleanup.dupes /tmp/package_cleanup.problems /var/log/messages* /var/log/yum.log /var/lib/rpm /var/lib/yum
The file /tmp/rpmdb.[hostname].tar.bz2 will contain the backup of rpm/yum databases which can then be provided to support team or moved to any other system for inspection.
1. A stable system must be of the same major release version of CentOS/RHEL. yum and rpm package versions may also need to be similar versions to the original system. rpm and yum database versions are not backward compatible for every version in a major release.
2. Unpack the yum & rpm databases from another system to an alternate root. For example:
# mkdir /root/rpmdb-root # cd /root/rpmdb-root # tar -xvf /tmp/rpmdb.[hostname].[date].tar.bz2
The directory ‘/root/rpmdb-root‘ will act as the alternate root.
# ls /root/rpmdb-root etc tmp var
Inspecting the rpm database
Use the –root= flag to point rpm to the alternate root. Example of querying the database:
# rpm --root=/root/rpmdb-root -qa
This method can be used for other rpm commands such as -qf, -ql, –qf [query-tags], etc.
Inspecting the yum database
Use the –installroot= flag to point yum to the alternate root. Example of checking history against the database:
# yum --installroot=/root/rpmdb-root history # yum --installroot=/root/rpmdb-root history info [ID]
This method can be used for some other yum commands such as:
# yum --installroot=/root/rpmdb-root history packages-info [package] # yum --installroot=/root/rpmdb-root check-update
Note: some commands have caveats such as:
- Install and update commands will require the stable system to be registered to identical RHN/RHSM repos as the original system.
- If the release cannot be determined by yum, using –releasever= may be required.
- Install & update commands may fail, due to files not existing in the alternate root directory, and using –setopt=tsflags=noscripts may help.
Some package-cleanup can be used with –installroot= on CentOS/RHEL 6 and up. For Example:
# package-cleanup --installroot=/root/rpmdb-root --dupes # package-cleanup --installroot=/root/rpmdb-root --problems