Linux Get list of installed software for reinstallation / restore software

Hardware and Software failures are part of Life. That is why you need to have a backup. I have already written about backing files and MySQL databases. You need not to backup all installed binaries (mostly software) with following tips. It will not just save your time but both Debian and RHEL distro can update them instantly.

In order to reinstall or restore your installed software you need to have a list of all installed software.

Task: Backup list of installed software

Debian Linux
If you are using Debian Linux use dpkg command to list installed software:
$ dpkg --get-selections

Store list of installed software to a file called /backup/installed-software.log
$ dpkg --get-selections > /backup/installed-software.log

RPM based distributions (RHEL, Fedora Core, Cent OS, Suse Linux etc)
Use rpm command to get list of all installed software:
$ rpm -qa
OR
$ rpm -qa > /backup/installed-software.log

Task: Restore installed software from backup list

Now you have a list of installed software. After installing base system you can immediately install all software.

Debian Linux
Debian Linux makes your life easy. All you have to do is type following two commands:
# dpkg --set-selections < /backup/installed-software.log
Now your list is imported use dselect or other tools to install the package.
# dselect

Select 'i' for install the software.

RPM based distro
As far as I know RPM based distro does not offers dpkg kind of facility. But with little shell scripting technquie you can easily install all software:
# LIST="$( cat /backup/installed-software.log )"

If you are using yum, type the following for loop to install all software:
# for s in $LIST; do yum install $s; done
Update try out following command (thanks to gt):
# yum -y install $(cat /backup/installed-software.log)

OR if you are using RHEL (RHN subscriber) :
# for s in $LIST; do up2date -i $s; done

Alternatively you use following command:
# up2date -i $(cat /backup/installed-software.log)

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 29 comments… read them below or add one }

1 gt 08.24.06 at 7:15 am

better run yum only once:

rpm -qa > /backup/installed-software.log
for i in $(cat /backup/installed-software.log) ; do packages+="$i " ; done
yum install $packages

2 nixcraft 08.24.06 at 7:56 am

Much better :)

Appreciate your post/script

3 textshell 08.24.06 at 1:40 pm

xargs yum install

4 nuclearjoker 08.24.06 at 2:01 pm

And if you use Gentoo Linux it would be as follows:

# cat /var/lib/portage/world
to get the list of packages

#emerge -av $(cat /path/to/backupworldfile.txt)

:-)

5 gsiems 08.24.06 at 3:02 pm


rpm -qa > /backup/installed-software.log

yum install `cat /backup/installed-software.log | tr "\n" " "`

6 gt 08.24.06 at 5:40 pm

or barely:
yum install $(cat /backup/installed-software.log)
so simple!

7 nixcraft 08.24.06 at 6:27 pm

Dam … I should have used this one liner :)

8 patrick 08.24.06 at 6:31 pm

nuclearjoker, not to troll out of u

But whole point of this article is about binary software install/update, IMPO. What you pointing is source compile under gentoo linux

Please correct me if I am wrong.

9 Arun 08.24.06 at 6:38 pm

Good article. Thanks.

10 Jarl 08.24.06 at 6:41 pm

For me this approach is the same that install from DVD/CDROM with the regular installer. Where are the own files? configuration files, customizated setups, and so on.

11 nixcraft 08.24.06 at 6:48 pm

Jarl,
As I said earlier, I am assuming that you are having a backup of /etc config file and other important data to tape or FTP or NAS server. Please read following url. This article is actually follow-up to earlier article.
Once application installed you can simply restore both data and configuration file.

Also, consider the CD/DVD media is not up-to-date or does not carries patched version. This method offers out of box protection as both up2date, yum or apt-get installs patched/up-to-date version.

HTH

12 Daniel M. Webb 08.24.06 at 6:59 pm

You can also use “apt-get dselect-upgrade” instead of dselect.

13 TQ 08.24.06 at 7:16 pm

Instead of dselect, can aptitude be used instead? What are the parameters involved?

Thanks.

14 nixcraft 08.24.06 at 7:45 pm

Short answer YES

Long answer – Both dselect and aptitude act as a Debian package management frontend.

15 Matthew Hall 08.24.06 at 10:06 pm

Even easier – Fedora users should get their installed packages list automagically updated every day to ‘/var/log/rpmpkgs’ – so, assuming you’ve taken a backup and restored the file the following should suffice:

yum -y install $(cat /var/log/rpmpkgs)

16 zerohalo 08.25.06 at 2:51 am

How would you do this on Ubuntu using apt-get instead of dpkg?

17 nixcraft 08.25.06 at 4:47 am

apt-get command does not support this kind of facility. You need to use dpkg command only.

18 Grant 08.25.06 at 7:24 am

When you install with CentOS it puts the list of installed rpms in /root/install.log. If root’s home dir is backed up you’re in business. Although I doubt if it’s update after the install.

Couldn’t you just create a kickstart disk after install/config and pop it in to reinstall then do a yum update? That would get you closer than just reainstalling packages. Of course all of this is fun to talk about but realistically you’d have backups and you’d just restore… I backup MBRs and files. Throw a live cd in the machine to be restored and from the backup server – dd if=/backup/MBR.bin | ssh “cat | dd of=/dev/hda”

It’s late and this is from memory but I think that’ll work to restore the MBR across the network. Then format and restore from backup.

19 chewie 08.25.06 at 6:10 pm

For Debian systems, you can also grab the debconf database and use it to preseed the installation questions that occur, including how to partition your hard drive. This allows you to completely automate the installation process. Check out the debian-installer Install manual at http://d-i.alioth.debian.org/manual/en.i386/apb.html.

20 Motin 03.05.07 at 2:55 am

There is a huge disadvantage using package lists – it lists a lot packages that one have not chosen to install but are installed because they are dependencies. This makes it veeery tedious to restore if the list is somewhat old or using another distro since dependencies change a lot.

For debian-based system: Install “debfoster” and run it. After answering a lot of questions about your packages you will have a system without unnecessary packages and a short list of only the packages that you have actively chosen to install.

21 cambo81 06.24.07 at 12:08 am

hi im new to this comp. stuff but i just got 1 question. i installed a game as imess around my laptop i uninstalled the game that i just installed. how can i recover that lost game cause i do not have the disc anymore please help me.

22 Caio 10.20.07 at 6:50 pm

That’s why I LOVE LINUX!

23 peace 03.09.08 at 11:57 am

nice tut man I LOVE LINUX too much

24 Don 03.11.08 at 10:02 am

Just what I needed :-)
Linux is great!!!

25 ZaK 04.10.08 at 10:42 pm

Im new to linex i was viewing utorrent in VNC i closed it by mistake how do i run it again so i can view the current activities

26 Narendra Sisodiya 05.14.08 at 12:39 pm

suppose i have 3 software A B and C
now i have taken backup..in log file..
now,, I have installed D and E , and removed B
– If Now i will restore then i will be having A B C D E , but is now a full restore,,,
ideally,, you need to create a new backuplist of software which has A C D and E
and then find the diff so that you can get D and E are extra software to remove first and B is need to installed. also,, you need to check that software are available or not, but nice article ,,, can be integrated in Yumex

27 Diabolic Preacher 05.28.08 at 6:55 am

for debian/ubuntu method. will it reinstall all the 1313 packages that i noted as being saved to the backup log or will it skip the packages that need not be updated?

28 JK Wood 11.05.08 at 6:54 pm

For Slackware-based distros:

ls /var/log/packages

29 johnhere 04.07.09 at 10:26 pm

Nice to see Debian and RPM based distro’s working so peacefully together in this
gr8 tutorial. I gonna give it a try to put this as an aftercare script in a kickstart file.
I want to call it a ‘clone kickstart’. ;-)

ks.cfg extracted/edited from a fedora distro /root/anaconda-ks.cfg

for rpm:

%post
for i in $(cat /some_network/kickstart_server/installed-software.log) ; do
packages+=”$i ” ; done
yum install -y $packages
%end

Just an idea so correct me if i am wrong. That saves time. ;-)

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , , , , , , , , , ,

Previous post: GP2X – Linux powered game device review

Next post: OpenSUSE 10.2 New KDE killer Start Menu