Rebuild Corrupted Yum Database

If you server crashes during a yum operation, your yum metadata can get corrupted causing issues, and you have to rebuild it.

Rebuilding rpmdb

rm -f /var/lib/rpm/__db*
rpm –rebuilddb

yum clean all
yum update

Errors you might see

rpmdb: Thread/process 7940/140325995558656 failed: Thread died in Berkeley DB library
error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db3 – (-30974)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed

=================

yum-downloadonly

Download RPM files with yum using yum-downloadonly.

First we must install the package.

#yum install yum-downloadonly

This downloads packagename update rpm to standard /var/cache/yum/ location

#yum update packagename –downloadonly

To specify a path to download, we add the –downloaddir= flag.

#yum update packagename –downloadonly –downloaddir=/root/downloads/

yumdownloader

The yumdownloader utility lets you download the rpms from a yum repository. This command line utility is included in the yum-utils package, so install that first.

#Install yum-utils

#yum -y install yum-utils

Download openssl RPM

#yumdownloader openssl

Download all RPMs on your system

#for rpmpak in `rpm -qa`; do yumdownloader $rpmpak; done