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)
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email this to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: Mar/9/2008



{ 31 comments… read them below or add one }
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
Much better :)
Appreciate your post/script
xargs yum install
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)
:-)
rpm -qa > /backup/installed-software.log
yum install `cat /backup/installed-software.log | tr "\n" " "`
or barely:
yum install $(cat /backup/installed-software.log)
so simple!
Dam … I should have used this one liner :)
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.
Good article. Thanks.
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.
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
You can also use “apt-get dselect-upgrade” instead of dselect.
Instead of dselect, can aptitude be used instead? What are the parameters involved?
Thanks.
Short answer YES
Long answer – Both dselect and aptitude act as a Debian package management frontend.
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)
How would you do this on Ubuntu using apt-get instead of dpkg?
apt-get command does not support this kind of facility. You need to use dpkg command only.
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.
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.
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.
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.
That’s why I LOVE LINUX!
nice tut man I LOVE LINUX too much
Just what I needed :-)
Linux is great!!!
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
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
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?
For Slackware-based distros:
ls /var/log/packagesNice 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. ;-)
i can’t automate the installation process in fedora since it is asking
“Total Download size:xxMB
Is this ok [y/n]?”
every time for all packages i have to give ‘y’ to download the package …………
is there any other way to automate the process?
please helpme……………………
But….
rpm -qa
Returns the long name, with version number, distro and arch,
for ex. gnome-utils-libs-2.28.3-1.fc11.i586
And if you try to install this list on a newer version distro you get
No gnome-utils-libs-2.28.3-1.fc11.i586 package availabe.
You shoud use:
rpm -qa –queryformat “%{NAME}\n” > packages.log
The problem is that I’ve just figure out this, just when I’ve formatted and installed a newer version of Fedora. Is there a trick to use the list I have? because there is no pattern at all to use sed/awk, isn’t it?