\begin{exe} {Rebuilding the \textbf{RPM} Database}

   There are conditions under which the \textbf{RPM}
   database stored in \filelink{/var/lib/rpm} can be
   corrupted.  In this exercise we will construct a new one
   and verify its integrity.

   This lab will work
   equally well on \textbf{Red Hat} and \textbf{SUSE}-based systems.

   \begin{enumerate}
      \item
      Backup the contents of \filelink{/var/lib/rpm} as the
      rebuild process will overwrite the contents.  If you
      neglect to do this and something goes wrong you are in
      serious trouble.
      \item
      Rebuild the data base.
      \item
      Compare the new contents of the directory with the
      backed up contents; don't examine the actual file
      contents as they are binary data, but note the number
      and names of the files.
      \item
      Get a listing of all \textbf{rpms} on the system.  You
      may want to compare this list with one generated
      before you actually do the rebuild procedure.  If the
      query command worked, your new database files should
      be fine.
      \item
      Compare again the two directory contents.  Do they
      have the same files now?
      \item
      You could delete the backup (probably about 100 MB in
      size) but you may want to keep it around for a while
      to make sure your system is behaving properly before
      trashing it.
   \end{enumerate}

   \begin{sol}

      \begin{enumerate}
         \item
         \begin{cmd}
$ cd /var/lib
$ sudo cp -a rpm rpm_BACKUP
         \end{cmd}
         \item
         \begin{cmd}
$ sudo rpm --rebuilddb
         \end{cmd}
         \item
         \begin{cmd}
$ ls -l rpm rpm_BACKUP
         \end{cmd}
         \item
         \begin{cmd}
$ rpm -qa | tee /tmp/rpm-qa.output
         \end{cmd}
         \item
         \begin{cmd}
$ ls -l rpm rpm_BACKUP
         \end{cmd}
         \item
         Probably you should not do this until you are sure the
         system is fine!
         \begin{cmd}
$ sudo rm -rf rpm_BACKUP
         \end{cmd}
      \end{enumerate}
   \end{sol}
\end{exe}

