However, Debian and Ubuntu have a handy way to get a list of everything that the aptitude package manager is keeping track of. Since that package management system is the main reason *why* many people are using Ubuntu or Debian, that means pretty much everything that's installed. And, since this list is in plain text, it's easy to edit and tweak, with each configuration taking up next to no space.
This article shows a basic version of getting this list into a file and even emailing the file to get it off of the machine in question and into my email. The linked example does this with the SMTP server on the machine in question. However, some of the machines I'm working with don't have any email server installed. And, I don't want to have to install a complete mail server, just to send out a simple set of files here and there.
Fortunately, there's a nice little commandline app for sending email via an SMTP. You just put it in /usr/local/bin as "sendEmail". Then, the package dump script can use it to send out the email.
The linked example also doesn't include the "sources.list", which is the file that points to the list of repositories used to fetch the packages. You actually need that if any of the packages in the list come from non-standard repositories.
So, a robust script would dump the list of packages, grab a copy of the sources.list, bundle them together into a tar.gz tarball and send that file as an attachment. Now, if you look here into my hat, you'll see such a magical script.
This is saved in the home directory of my regular user on all of these servers as package-dump.sh, which I make executable with "chmod +x package-dump.sh". Then, I run it as "./package-dump.sh" and the email gets done. It obviously will ask for the root password if it's not already cached.
Each chunk should be on its own line.
sudo dpkg --get-selections | grep "install" > package-dump/packages.txt
sudo cp /etc/apt/sources.list package-dump/sources.list
tar cfz packages.tar.gz package-dump
sudo rm -r package-dump
sendEmail -f FROMADDRESS -t TOADDRESS -s SMTPSERVER -xu SMTPUSER
-xp SMTPPASSWORD -u "Package List for Server" -m "Attached is a list
of packages and apt-get sources they came from." -a packages.tar.gz
To load the list up on a fresh server, put the sources.list in the appropriate place and follow the instructions in the linked article.