我需要运行一个可能会破坏“apt-get”数据库的脚本。我应该备份什么?

我需要运行一个可能会破坏“apt-get”数据库的脚本。我应该备份什么?

我正在编写一个包装脚本,但rm它可能会apt-get在处理过程中出现故障。

apt-get如果数据库损坏,我需要首先备份哪些文件?

答案1

经过一番挖掘,我发现apt-get数据库是由dpkg

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.

更多来自Debian 常见问题解答,它说

重要的是要了解,更高级别的包管理工具(例如 aptitude 或 synaptic 依赖于 apt),而 apt 本身依赖于 dpkg 来管理系统中的包。

因此,如果dpkg将其自己的数据库放入/var/lib/dpkg/status,则意味着apt-get数据库和由维护的所有其他包管理器dpkg也将放入/var/lib/dpkg/status。因此,只需备份/var/lib/dpkg/status(其中dpkg已将其备份放入/var/backups/)即可解决您搞砸的担忧apt-get

相关内容