» Restore packages using dselect-upgrade
It's always a good idea to backup important data. Your files and settings can easily be archived. But how can you backup & restore all applications that you've installed over the last couple of years? Here's an easy trick that works for both desktops & servers, and that can also be used to synchronize installed packages in a web cluster, making all the servers run the same software.
The method described in this article depends on the command apt-get, so it works on Debian & Ubuntu systems. This article does not describe a full backup & restore method, it's a trick to add to your existing backup procedure. Still, it's a trick that will really make your life easier.
APT packages
The basic idea is that we generate a list of all currently installed packages, keep it some place safe, and upon a reinstall, we can upload this list again and have the system install all the packages in this list automatically.
How to backup
So first we need to create a list of all the installed APT packages and save it in a file:
sudo dpkg --get-selections > /tmp/dpkglist.txt
That's it! The list is now stored in /tmp/dpkglist.txt. If you want you can add this command to your crontab and then just include the file /tmp/dpkglist.txt in your backup procedure so that it's safe and up to date at all times.
How to restore
Now if your system crashes (let's all hope it won't) and you need to reinstall, this will be the procedure:
- install a fresh OS (of course)
- restore the package list
- restore your important files & settings
But how can can we restore the package list? Simple. Just copy your backed up dpkglist.txt file to your fresh system's /tmp directory again and execute the following:
sudo dpkg --set-selections < /tmp/dpkglist.txt
sudo apt-get -y update
sudo apt-get dselect-upgrade
Great! All of your apt packages have been restored!
(Don't worry! This method only adds and upgrades packages, it will not remove packages that do not exist in the list)
Additional trick: PEAR packages (web servers only)
The same method can be used to restore PEAR extensions. Though there aren't any standard tools that I know of, with a little creativity it's not so hard.
How to backup
This will generate a list of all installed PEAR packages and save it to a file:
sudo pear -q list | egrep 'alpha|beta|stable' |awk '{print $1}' > /tmp/pearlist.txt
That's it! A list of your installed PEAR packages is stored in the file /tmp/pearlist.txt. Now, if you want you can add this command to your crontab and then just include the file /tmp/pearlist.txt in your backup procedure so that it's safe and up to date at all times.
How to restore
To restore: make sure PEAR is installed, simply copy the pearlist.txt file back to your new system's /tmp directory and type:
cat /tmp/pearlist.txt |awk '{print "pear install -f "$0}' |sudo bash
Great! All of your PEAR packages have been restored!
Like this article?
|
Then Digg it! Or use another bookmark button below to show your support & help me spread the word. |
Hot StuffFlaming articles» Survive heavy traffic with you... | RelatedArticles like this one» Make SSH connections with PHP |
tags: ubuntu, PEAR, backup
category: How to - System
read: 5,930 times






tagcloud
#9. Nima on 25 September 2007
I learned a new thing. :)
continue the good job.
#8. Kevin on 11 September 2007
#7. Angus MacGyver on 11 September 2007
I'd put the backup in a more permanent place like /var/tmp - or a file in /etc - simply as /tmp will get wiped on each and every reboot.
just my 0.02c
#6. Thomas on 07 August 2007
#5. Kevin on 07 August 2007
#4. Kevin on 07 August 2007
If you want the output of all your cronjobs in your mail, begin your crontab with:
MAILTO="thomas@yourdomain.com"
and remove the '> /tmp/dpkglist.txt' part from the jobs.
... [more]
If you only want this cronjob's output in your mail, make sure the following package is installed: aptitude -y update && aptitude install mailx
And then change the cronjob like this:
dpkg --get-selections |mail thomas@yourdomain -s "My APT packagelist $(date)"
Same goes for PEAR
#3. Thomas on 07 August 2007
Where is the default destination for mail from cron?
#2. Kevin on 05 August 2007
#1. Serge van Ginderachter on 05 August 2007
better:
sudo dpkg --set-selections < /tmp/dpkglist.txt