apt-clone : To clone installed packages from one system and restore it on another fresh Ubuntu system

Package installation is become more easier on Ubuntu/Debian based systems when we use apt-clone utility.

apt-clone will help you lot , if you want to build few systems with same set of packages.

It’s time consuming process if you want to build and install necessary packages manually on each systems.

It can be achieved in many ways and there are many utilities are available in Linux.

We have already wrote an article about Aptik in the past.

It’s one of the utility that allow Ubuntu users to backup and restore system settings and data

What Is apt-clone?

apt-clone  allow you to create backup of all installed packages for your Debian/Ubuntu systems that can be restored on freshly installed systems (or containers) or into a directory.

This backup can be restored on multiple systems with same operating system version and architecture.

How To Install apt-clone?

The apt-clone package is available on Ubuntu/Debian official repository so, use apt Package Manager or apt-get Package Manager to install it.

Install apt-clone package using apt package manager.

$ sudo apt install apt-clone

Install apt-clone package using apt-get package manager.

$ sudo apt-get install apt-clone

How To Backup Installed Packages Using apt-clone?

Once you have successfully installed the apt-clone package. Simply give a location where do you want to save the backup file.

We are going to save the installed packages backup under /backup directory.

The apt-clone utility will save the installed packages list into apt-clone-state-Ubuntu18.2daygeek.com.tar.gz file.

$ sudo apt-clone clone /backup

We can check the same by running the ls Command.

$ ls -lh /backup/
total 32K
-rw-r--r-- 1 root root 29K Apr 20 19:06 apt-clone-state-Ubuntu18.2daygeek.com.tar.gz

Run the following command to view the details of the backup file.

$ apt-clone info /backup/apt-clone-state-Ubuntu18.2daygeek.com.tar.gz 
Hostname: Ubuntu18.2daygeek.com
Arch: amd64
Distro: bionic
Meta: libunity-scopes-json-def-desktop, ubuntu-desktop
Installed: 1792 pkgs (194 automatic)
Date: Sat Apr 20 19:06:43 2019

As per the above output, totally we have 1792 packages in the backup file.

How to restore the backup which was taken using “apt-clone”?

You can use any of the remote copy utility to copy the files on remote server.

$ scp /backup/apt-clone-state-ubunt-18-04.tar.gz Destination-Server:/opt

Once you copy the file then perform the restore using apt-clone utility.

Run the following command to restore it.

$ sudo apt-clone restore /opt/apt-clone-state-Ubuntu18.2daygeek.com.tar.gz 

Note: The restore will override your existing /etc/apt/sources.list and will install/remove packages. So be careful.

If you want to restore all the packages into a folder instead of actual restore, you can do it by using the following command.

$ sudo apt-clone restore /opt/apt-clone-state-Ubuntu18.2daygeek.com.tar.gz --destination /opt/oldubuntu

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

2 Comments on “apt-clone : To clone installed packages from one system and restore it on another fresh Ubuntu system”

  1. Thanks for this… 😉

    Will try this out to see if it becomes default practice for building images..

Leave a Reply

Your email address will not be published. Required fields are marked *