Debian – Compute a list of difference between packages installed on two hosts

debiandpkglxcpackage-management

I just add some problems with my Debian virtual servers and I add to reinstall all of them from scratch. However, I still had access to the old version and I could retrieve the list of installed packages.

In order to facilitate the process of restoring a virtual server in the future, I would like to create a list of specific packages for each one of my server.

To better explain what I want to achieve. I already have an automated process to create a new virtual server with some basic package and configuration used everywhere. Now I want to save the delta with this "skeleton" to ease the reinstallation of a particular server.

A real plus will be to also save the changed configuration files from the default, but I can live with only the package list.

In short, I want a way to create a list of packages installed on a host but not on another.

It will be really great if the list contains only manually installed packages and not the list of all dependencies.

If you have some existing tools which are designed to achieve this particular task, feel free to propose them, but I want to keep the dependency as small as possible. For information, they're not exactly virtual servers, but LXC containers.

Best Answer

On the reference installation (only once):

dpkg-query -W -f='${Package}\n' | sort > baselist.txt

(The following assumes bash)

To get the packages added from the reference installation (this doesn't show what was removed):

comm -1 -3 baselist.txt <(dpkg-query -W -f='${Package}\n' | sort)

Even better, avoiding copy of baselist.txt:

comm -1 -3 <(ssh user@refserver cat /path/to/baselist.txt) <(dpkg-query -W -f='${Package}\n' | sort)