Tuesday, March 10, 2009

Yet another great trick with apt-get

I recently bought a new virtual private server to host some web sites on. I use debian derivatives for all my hosting, but the server derivatives usually come pretty stripped down by default. So while I was setting my shiny new server up I got to thinking "there has to be some way to clone my installed packages off my older server".

Turns out, as usual, apt delivers!

1. Back up /etc/apt/sources.list on your new server: jwoffenden@newserver# sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
2. Copy it over from your old one: jwoffenden@oldserver# scp /etc/apt/sources.list root@newserver:/etc/apt/sources.list
3. Update apt: jwoffenden@newserver# sudo apt-get update

And then here's the magic:

1. Store your currently installed packages list in a file: jwoffenden@oldserver# dpkg --get-selections > ~/selectionfile
2. Copy it to the new server: jwoffenden@oldserver# scp ~/selectionfile root@newserver:/root/selectionfile
3. Tell apt to sickem!!: root@newserver dpkg --set-selections < /root/selectionfile && apt-get dselect-upgrade

4. Go get a snack. When you get back all your shiny packages will be installed.

No comments: