RPM Database Crash

It was an interesting weekend. I planned on updating the RPM packages on the system over the weekend using Red-Carpet. However, it indicated there weren’t any packages to update, which I knew was wrong. I did some checking and it appeared that my RPM database was corrupted. The solution to that seemed to be running rpm –rebuilddb. That rebuilds the database from the header files stored on the computer. Well…do you know what happens if your headers are also corrupted? You end up with a database of RPM’s significantly smaller than you had before.

Fortunately for me RedHat outputs to a log file (/var/log/rpmpkgs) the current packages installed. After rebuilding my database I compared it with the log file. The rebuilt database was about 1/5 the size. What this means is my rebuilt database was missing 4/5 of the RPM’s I had installed on my system. Everythings was still installed and ran fine but I knew I’d run into dependency problems and such if I ever wanted to update my packages or install a new package. So…basically I was left with the task of rebuilding my entire RPM database. Which, according to the rpmpkgs log file was around 800 packages. WHAT A MESS. However, after a few hours I came up with a pretty slick way to do it. I wrote a simple bash script to read through the rpmpkgs log file, download the package from the RedHat distribution and then add it to the database. Here’s the script I used:

#!/bin/bash
exec < rpmpkgs.1
exec > zoutput.txt

while read line
do
wget ftp://ftp.rpmfind.net/linux/redhat/8.0/en/os/i386/RedHat/RPMS/$line
rpm -iv –nodeps –justdb –noscripts –force –notriggers $line
done

I used the rpmfind website instead of ftp.redhat.com cause it seemed to have more bandwidth. Anyway, I let this run over night. Then wrote another script to determine which packages it couldn’t find. Basically it was just a script to figure out which files it couldn’t find. I stored these in a file called znotfound.txt. Then I used that file as my input file (instead of rpmpkgs.1) and used the same script to scan the Red-Carpet cache of packages I had on my system (I installed all packages in the Red-Carpet cache first). Anyway, here’s the script (basically just as simple as the previous):

#!/bin/bash
exec < znotfound.txt
exec > znotfound2.txt

while read line
do
if ! test -e $line
then
echo $line
fi
done

Basically all this does is check to see if the RPM file exists. After running these scripts I was left with 5 packages that were sill missing. NOT BAD! I can handle installing 5 packages manually, 800 is another thing. After all was said and done I ran rpm -Va to verify the packages installed. Everything looked good. No missing dependencies or conflicts. I think I’ll start adding the RPM database directory (/var/lib/rpms) to my backup script.

ADDENDUM: I still haven’t been able to figure out what caused the corruption in the first place, which has me concerned. We did have a couple power outages recently which sent the machine down hard so maybe that had something to do with it. I dunno…all the more reason to get a server I can colocate at a data center. Unfortunately I can’t seem to find a colocation price that is as cheap as just hooking it up to my DSL line :).

One Response to “RPM Database Crash”

  1. David Says:

    You always have such fun weekends. You’re so lucky.