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
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.
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
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:
Great! All of your PEAR packages have been restored!
These were imported from my old blog. Please use disqus below for new comments
on 2012-04-05 13:53:47
Thank you very much!
Works smoothly and miraculous magical from Ubuntu 10.04 to Pear OS 3.0.
Great contribution to Linux lovers which is making life very comfortable.
on 2011-08-13 11:32:09
very good trick to save nerves.
one more thing:
cp /etc/apt/sources.list tmp/sources.list
to be on the save site, if you have any repositories added.
David Dyess II
on 2011-06-30 06:45:00
I LIKE LIKE LIKE LIKE this bit of info. This one as it has been a lifesaver to me, I just found this nugget.
Thanks keep good info up.
From Millry Al
on 2008-12-24 17:45:13
this is simply great!!!!
dpkg is THE package manager.
thanks for sharing this. it's helping me with all my friend's ubuntu installations. it saves me a LOT of time.
i just keep one ubuntu on my brother's laptop and use this method.
on 2007-09-25 08:40:03
Great tip kevin.
I learned a new thing. :)
continue the good job.
on 2007-09-11 22:31:23
@ Angus MacGyver: You're supposed to run the command before your actual backup, and have the backup include that file, so no problems there.
on 2007-09-11 08:03:47
Great article - just one comment.
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
on 2007-08-07 13:43:58
Ah, I see you've already discussed crontab's mail output, natch. Thanks for the kind pointer, and all the great howtos.
on 2007-08-07 10:30:36
@ Thomas, again: BTW, if you want to know more about crontab, you might also want to read my article 'Schedule Tasks on Linux using crontabs' here: http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/