Sunday, 26 August 2012

Backup and Restore Packages in Ubuntu/Linux Mint/Debian



Here’s a simple tutorial on how to backup a list of all your installed repository applications, and restore them to another machine, perhaps even the same machine after a clean installation.  This can save you an incredible amount of time, especially when this task must be repeated often.  Of course, being that Ubuntu is based on Debian, this will work for any Debian based platform.


First, from a computer with all the applications preinstalled, retrieve your installed package list and redirect the output to a file called packages.txt.  Save this package list somewhere so that you can use it for the restore process.
sudo dpkg --get-selections > packages.txt
To restore all the applications from your list, you must follow a three step process very carefully.
sudo dpkg --clear-selections
sudo dpkg --set-selections < packages.txt
sudo aptitude install
You will be prompted to install all the new applications in the list.
Another example of what this process allows you to do is create a baseline of all the applications after a clean installation of Ubuntu.  Let’s say you would like to remove any applications installed since the clean install, perform the exact same process, and any package not defined in that list will be removed.
sudo dpkg --get-selections > clean-install-package-list.txt
sudo dpkg --clear-selections
sudo dpkg --set-selections < clean-install-package-list.txt
sudo aptitude install
The very first command of “–clear-selections” marks all currently installed packages to the state “deinstall”.  When you restore the list of applications using “–set-selections”, only packages ommited from the list will remain in the “deinstall” state.  Aptitude will honor the deinstall state and remove the extra packages, leaving you only with packages from the list. 

Also there is another way to backup your installed packages

First type in the Terminal

 sudo apt-get install dpkg-repack fakeroot

Then create a directory (for eg. dpkg-repack) anywhere on your external drive or hard drive

mkdir ~/dpkg-repack

 cd ~/dpkg-repack

Now type the following the deb packages will be stored in current directory

 fakeroot -u dpkg-repack `dpkg --get-selections | grep install | cut -f1`

After that is finished  install them whenever you want from terminal as follows

sudo dpkg -i  *.deb

via Ubuntu Forums

1 comment: