It can happen that a particular version of a specific tweaked package no longer available elsewhere or you want the exact “clone” of the running software. If you have installed some Debian package on your server and want to install the same package on another server either to avoid downloading them again or “clone” with the settings then there are some tools which can help you. If the second machine lacks an internet connection then you’ll need to install the dependencies as well.
The dpkg-repack utility can be helpful in many situations where you want to move the original .deb file :
1 2 | # man https://manpages.ubuntu.com/manpages/disco/en/man1/dpkg-repack.1.html |
You can easily install it :
---
1 | sudo apt install dpkg-repack |
You can repackage any software such as apache2 first by stopping any running instance and then running this kind of command :
1 | dpkg-repack apache2 |
If you can’t rebuild the deb file due to any permission issues, then run the command from fakeroot environment:
1 | fakeroot -u dpkg-repack apache2 |
You can install the resulting deb file with the below command :
1 2 3 | sudo dpkg -i <package-name> # install the dependencies sudo apt-get -f install |
We can print the dependencies on the main server running the original software :
1 | apt-cache depends Package_name |awk '{print $2}' |
You can create a script to automate the dependency installation :
1 2 | package=package dpkg-repack $(apt-cache depends --false-suggests $package |awk '{print $2}') $package |

However, dpkg-repack utility will not copy your custom settings. dpkg-repack is helpful to get the original deb file we used on our main server. That is helpful in a certain scenario where an exact copy of the settings is not desired.
apt-clone is another utility which copies all the settings and create a debian installation file :
1 2 | http://manpages.ubuntu.com/manpages/bionic/man8/apt-clone.8.html https://packages.debian.org/stretch/apt-clone |
You can install apt-clone utility by running :
1 | sudo apt-get install apt-clone |
If we want to clone a running instance of apache2 then we need to run :
1 | apt-clone clone apache2 |
This creates a file apache2.apt-clone.tar.gz. Copy it to the destination machine, and run
1 2 | apt-get install apt-clone apt-clone restore apache2.apt-clone.tar.gz |
You can manually install the same packages from one server to another with the below commands :
1 2 3 | dpkg -l | grep ^ii | awk '{print $2}' > installed # another server sudo apt-get install $(cat installed) |
Usually, the settings are saved in the /etc/ directory. There are tools such as etckeeper which can be used with git to restore the settings :
1 | http://etckeeper.branchable.com/ |