I'm currently running Ubuntu 20.04.4 LTS
.
Four times over the past year or two, my apt
database got screwed up somehow (I don't know how), and the next time I ran apt
, apt-get
, and aptitude
, I was told that I have more than 1,000 packages that are set up to be removed. If I did an autoremove
with the intention of later trying to reinstall, my entire system would have become unusable, because most of the normal, everyday programs would then have been removed during that autoremove
.
I did not (!!!) delete the top-level desktop package, nor any top-level package. This error occurred due to something (??? I don't know what) which somehow damaged the integrity of the apt
databases on my machine.
I was able to fix this each time by going through the procedure which I have outlined in the "Answer" to this question: Fixing broken apt **without** destroying my system via "apt autoremove"
However, the fact that this has occurred multiple times means that whatever caused this might cause it to happen again. In order to help fix this situation if/when it happens again, I'd like to know the following ...
What directories on my system should I back up if I want to preserve the state of the entire apt
system at any given time? I want to take periodic backups of all of these apt
-related directories, so that next time this error occurs, I could quickly restore my apt
environment by restoring all of these directories to their last backed-up versions.
Thank you for any pointers and suggestions as to what directories I should back up in order to preserve the integrity of my entire apt
environment.
I have part of the answer. Install TimeShift
It takes snapshot of your system and lets you restore to previous state. I like it cause you can create a daily schedule and set how many days of restore to retain. 'Set it and forget it'
Let us know if this helped and a good enough solution.
apt-clone seems to be one option or
How to backup settings and list of installed packages
here is a little info off the page, but lots of other ideas
I discovered that
/var/lib/dpkg
is probably the directory tree that I should back up and restore.But that's specifically for
apt
anddpkg
, and it doesn't necessarily contain everything thataptitude
uses, sinceaptitude
is a newer utility which built uponapt
.I'll treat this as a provisional answer until I find out more about the database in which
aptitude
stores its own data.UPDATE
I now see the following files:
/etc/cron.daily/dpkg
and/etc/cron.daily/aptitude
. These do the backups of thedpkg
database and theaptitude
database, respectively.So, my work is already being done by the OS, and if my
apt
environment ever gets hosed again, I believe that I can restore it by restoring from those backups.Onward!