Backup and restore apt packages on Debian/Ubuntu

Suppose you want to install all the apt packages already installed on one server to another one.

On the source machine execute the following commands to make a list of installed packages and their “states” (installed manually or automatically):

sudo dpkg --get-selections > pkgs_selection.lst
sudo apt-mark showauto > pkgs_auto.lst
sudo apt-mark showmanual > pkgs_manual.lst

Copy files pkgs_selection.lst, pkgs_auto.lst and pkgs_manual.lst to the destination machine.

On the destination machine execute the following commands to install the packages that are installed in the source machine and set the correct “state” for packages:

sudo apt-get install dselect
sudo dselect update
sudo dpkg --set-selections < pkgs_selection.lst
sudo apt-get dselect-upgrade
sudo apt-mark auto $(cat pkgs_auto.lst)
sudo apt-mark manual $(cat pkgs_manual.lst)
Advertisements

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.