Friday, February 15, 2008

How to backup deb packages

Say you've downloaded a .deb program and now you want to back it up on your AptOnCD, or even transfer it to a friend of yours. The problem are the dependencies. If you ever cleared your /var/cache/apt/archives/ using 'sudo apt-get clean' or 'sudo apt-get autoclean' and the archives cache is emptied, you probably know what I'm talking about.


apt-get is a bit limited for making backups, because it checks if you already have the package installed and it will eventually say that it is installed without downloading anything, so we'll use aptitude's "download" command, which is pretty straight-forward.
NOTE for Ubuntu Newbies: From the menu Applications -> Accessories -> Terminal

First, we check the dependencies of a package:
sudo apt-get update
apt-cache depends PackageName
Don't forget to change the PackageName to match the package YOU want to backup/download.

You'll probably have a big list. We need to convert all those into a single line using this handy command:
apt-cache depends PackageName | grep "Depends:" | sed -e "s/ Depends: //" | xargs -d "\n"

NOTE: This way you get the dependencies only. If you want the recommended, suggested and predepended packages along with it, use this:
apt-cache depends PackageName | grep "Depends\|Recommends\|PreDepends\|Suggests" | sed -e "s/ \(Depends\|Recommends\|PreDepends\|Suggests\): //" | xargs -d "\n"
We also need to create a directory where we'll download the packages:
mkdir debbackup
cd debbackup
Finally we do this, putting the multiple packages (obtained using the apt-cache depends command) in a single line:
sudo aptitude download Package1 Package2 Package3 Package4
or if you want to put everything into a line:
sudo aptitude download `apt-cache depends PackageName | grep "Depends:" | sed -e "s/ Depends: //" | xargs -d "\n"`

Wait for those lovely packages to arrive.
After that, if you want to use it with AptOnCD, you can take it from there to the apt archive.
Assuming you're still in the gnome terminal and still in the directory where you downloaded the packages:
sudo cp *.deb /var/cache/apt/archives/

All done! The packages are ready to be used with AptOnCD, or transferred to a friend :)

P.S. I've attached a screenshot to see how it's actually done.

No comments: