1

I'm working on a wrapper script for rm that might break apt-get part way through processing.

What file(s) do I need to back up first in case apt-get database gets corrupted?

1 Answers1

1

After some digging,i found out that apt-get database is managed by dpkg

From man dpkg

   /etc/dpkg/dpkg.cfg
          Configuration file with default options.

   /var/log/dpkg.log
          Default log file (see /etc/dpkg/dpkg.cfg(5) and option --log).

   The other files listed below are in their default directories, see option --admindir to see how to
   change locations of these files.

   /var/lib/dpkg/available
          List of available packages.

   /var/lib/dpkg/status
          Statuses  of  available packages. This file contains information about whether a package is
          marked for removing or not, whether it is installed or not, etc.  See  section  INFORMATION
          ABOUT PACKAGES for more info.

          The  status  file is backed up daily in /var/backups. It can be useful if it's lost or cor‐
          rupted due to filesystems troubles.

Also from The Debian FAQ,it says

It is important to understand that the higher level package management tools such as aptitude or synaptic rely on apt which, itself, relies on dpkg to manage the packages in the system.

So if dpkg puts its own database in /var/lib/dpkg/status, that means apt-get database and all other package mangers maintained by dpkg will also be in /var/lib/dpkg/status.So simply by backing up /var/lib/dpkg/status (of which dpkg already puts its backups in /var/backups/) will solve your worries of screwing up with apt-get.

  • 1
    Also when you use ll /var/lib/dpkg/*old you see status is one of the four files with on-line backups there. Thanks for your quick research! – WinEunuuchs2Unix Jan 03 '17 at 11:40
  • In case you are wondering the rm wrapper script worked perfectly and didn't break apt-get so the database never got corrupted. Knowing before hand what could break was reassuring though. – WinEunuuchs2Unix Jan 03 '17 at 11:57
  • Yes,glad no harm occurred :) !that is called defensive mechanism,its better to taking measures of stopping the problem than fixing it. – Arduino_Sentinel Jan 03 '17 at 12:03