nixCraft Poll

Topics

Linux Get list of installed software for reinstallation / restore software

Posted by Vivek Gite [Last updated: March 9, 2008]

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 stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. gt Says:

    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 Says:

    Much better :)

    Appreciate your post/script

  3. textshell Says:

    xargs yum install

  4. nuclearjoker Says:

    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 Says:


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

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

  6. gt Says:

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

  7. nixcraft Says:

    Dam … I should have used this one liner :)

  8. patrick Says:

    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 Says:

    Good article. Thanks.

  10. Jarl Says:

    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 Says:

    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 Says:

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

  13. TQ Says:

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

    Thanks.

  14. nixcraft Says:

    Short answer YES

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

  15. Matthew Hall Says:

    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 Says:

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

  17. nixcraft Says:

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

  18. Grant Says:

    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 Says:

    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 Says:

    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 Says:

    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 Says:

    That’s why I LOVE LINUX!

  23. peace Says:

    nice tut man I LOVE LINUX too much

  24. Don Says:

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

  25. ZaK Says:

    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 Says:

    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 Says:

    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?

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.