As part of a larger backup-restore scheme, I'm trying to get a concise list of an ubuntu 16.04 server's installed packages. I want the list to be as short as possible and potentially be useful even five years later on a new LTS version of ubuntu.
Consider the following scenario:
Day 1: I install ubuntu 16.04 server on a machine.
Day 2: I install php-fpm
Day 3: I install nginx
, php
, and sendmail
Day 4: I install atanks
. No, I don't know why I'm installing a graphical game on a headless server. The point is just to add more stuff which was manually installed to apt's database.
Day 5: My server explodes in a fiery inferno. Maybe a tank explosion had something to do with it. In any case, I need to create a new server based on the backup.
In my backup script, I'd like to be able to generate the following line based on my apt-get activity over the past few days:
apt-get install atanks nginx php php-fpm sendmail
So how do we do that?
First, I tried some apt queries,
apt-mark showmanual
but they seemed to list hundreds of packages more than I had manually installed.
Second, I found debfoster
:
Right after installing ubuntu, I'd run:
sudo apt-get update
sudo apt-get -y install debfoster
sudo debfoster -q
sudo cp /var/lib/debfoster/keepers ~/startkeepers
And normal server operations could continue. I or other users of the server might install any number of packages.
In my backup script, I'd have the following:
sudo debfoster -q
sudo echo $(diff --new-line-format="" --unchanged-line-format="" /var/lib/debfoster/keepers ~/startkeepers) > apt-get.list
And then I could restore on a new install with:
apt-get install -y $(cat apt-get.list)
Unfortunately, this method isn't working perfectly due to different packages either installing or not installing certain reccommends.
When after storing startkeepers
, I run
sudo apt-get install -y nginx php-fpm python-certbot-nginx sendmail composer php-mbstring php-xml php-zip php-mysql
sudo debfoster -q
sudo echo $(diff --new-line-format="" --unchanged-line-format="" /var/lib/debfoster/keepers ~/startkeepers) | tr ' ' '\n'
This last line has the following output:
composer
php-fpm
php-mbstring
php-mysql
php-xml
php-zip
python-certbot-nginx
sendmail
This is missing... nginx!!! That freaked me out, but then I realized that nginx
must be a dependency of python-certbot-nginx
, and I confirmed that. So maybe this method would work after all?
I ran sudo apt-get upgrade
on my test server and the output remained unchanged after using
sudo debfoster -q
sudo echo $(diff --new-line-format="" --unchanged-line-format="" /var/lib/debfoster/keepers ~/startkeepers) | tr ' ' '\n'
However, on my real server, the one I'm trying to configure this scripted duplication for, there are an additional two lines in it that I don't think should be there:
linux-headers-4.4.0-112-generic
linux-image-4.4.0-112-generic
I didn't manually install those... And don't want to install them on another server, unless whoever determined they were necessary does so again. Could it have been apt-update?
TLDR; What's a reliable way to keep track of a server-version agnostic list of manually installed packages, where manually means stuff the user knows about installing, not were installed by upgrades or however linux headers and kernel versions get installed? Anything that improves my process would be appreciated, bonus points for using apt tools instead of debfoster
, considering its developers claim apt supports all of its features.