It will depend on the reader to judge how useful this is or if it is useful at all, but I do use it from time to time.

Whether you want to re install the same version of Ubuntu or you want to install it on a different machine this will save you some set up time.

The first time you install Ubuntu, if you do this one or two moths after release, you will notice that you need to install over 100 MB of packages updates and if you’ve been using it for a while you’ve already installed and updated the software you need. Well, I sometimes need to re install Ubuntu, because I messed it up and I’m too lazy to fix it or because I want it on a different computer.

You may have noticed that if you install a package via aptitude (or apt-get or Synaptic Package Manager) it downloads it from the net but if you uninstall it and later install it again it will not be downloaded and instead installed from the local cache. Much faster of course.

With this little scripts you can make this happen on a clean Ubuntu install saving you some downloading time. And probably some boredom as well.

To get started fire up a terminal.

First back up you cache:

mkdir -p ~/backup/var/lib/

sudo cp -R /var/lib/apt/ ~/backup/var/lib/

mkdir -p ~/backup/var/cache/

sudo cp -R /var/cache/apt/ ~/backup/var/cache/

mkdir -p ~/backup/etc/apt

sudo cp -R /etc/apt/ ~/backup/etc/

sudo chown -R $USER ~/backup

That will copy the apt cache and config to a “backup” folder within your home directory. Feel free to change that to whatever suits you best.

The you must, of course, copy that to some other media to either transfer to another computer or keep safe while you reinstall.

Now the restore process:

sudo cp -fR ~/backup/var/* /var/

sudo cp -fR ~/backup/etc/apt/* /etc/apt/

That will restore the files from the origin to the real location. After that run aptitude update and you are ready to install anything you had previously installed without the need to download it all over again. Including updates!

NOTE: this assumes that everything is back in your home directory. If this is not the case change “~” for the full path of the actual location.

Well hope this works for you!

From thie link you can get two scripts to do this. To use then un tar the file (tar -zxf aptitude-backup.tar.bz) and give then execution permission and then just run then with the location for the back up or restore from path as a parameter.

aptitude-backup.tar

Share