Compute a list of difference between packages installed on two hosts
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.
Solution 1:
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)
Solution 2:
on old server, run:
dpkg --get-selections > old-packages-list
copy the above file to new server and run this on new server:
dpkg --set-selections < old-packages-list
apt-get update
dselect update
Also, remember to add all the extra repositories from /etc/apt/sources.list
from old server to new server as well, before this migration of packages, as if you do not, then most packages will be left un-installed.
Solution 3:
You can use the following command to get the full list of packages on both servers:
dpkg -l | sort > old_file
dpkg -l | sort > new_file
Then, you can get the differences using:
diff -Nur old_file new_file > changes.txt
You can filter the needed changes using grep. Also, diff can be used to get the changes in configuration files and generate patches to be appåied when needed. By the way, diff can compare two folders not only two files.
Solution 4:
Blueprint is designed for exactly your need. It spits a description packages installed and config files that have been changed. It's able to convert these descriptions into Puppet or Chef scripts in order to apply them to clean boxes.
Solution 5:
Also found this helpful package, the description of which is as follows:
A Bash script which compares the filesystem tree of a Debian package to the current filesystem tree, printing unified diffs for files that differ.
https://code.google.com/p/dpkg-diffs/
Just a single bash file you can stick in your PATH somewhere and run - seems to work for me and its not too old.
Hope this helps someone.