Home Command line utilities Backup Installed Packages And Restore Them On Freshly Installed Ubuntu System
Apt-clone - Backup Installed Packages

Backup Installed Packages And Restore Them On Freshly Installed Ubuntu System

By sk
1691 Views

Installing the same set of packages on multiple Ubuntu systems is time consuming and boring task. You don't want to spend your time to install the same packages over and over on multiple systems. When it comes to install packages on similar architecture Ubuntu systems, there are many methods available to make this task easier. You could simply migrate your old Ubuntu system’s applications, settings and data to a newly installed system with a couple mouse clicks using Aptik. Or, you can take the backup entire list of installed packages using your package manager (Eg. APT), and install them later on a freshly installed system. Today, I learned that there is also yet another dedicated utility available to do this job. Say hello to apt-clone, a simple tool that lets you to create a list of installed packages for Debian/Ubuntu systems that can be restored on freshly installed systems or containers or into a directory.

Apt-clone will help you on situations where you want to,

  • Install consistent applications across multiple systems running with similar Ubuntu (and derivatives) OS.
  • Install same set of packages on multiple systems often.
  • Backup the entire list of installed applications and restore them on demand wherever and whenever necessary.

In this brief guide, we will be discussing how to install and use Apt-clone on Debian-based systems. I tested this utility on Ubuntu 18.04 LTS system, however it should work on all Debian and Ubuntu-based systems.

Backup Installed Packages And Restore Them Later On Freshly Installed Ubuntu System

Apt-clone is available in the default repositories. To install it, just enter the following command from the Terminal:

$ sudo apt install apt-clone

Once installed, simply create the list of installed packages and save them in any location of your choice.

$ mkdir ~/mypackages
$ sudo apt-clone clone ~/mypackages

The above command saved all installed packages in my Ubuntu system in a file named apt-clone-state-ubuntuserver.tar.gz under ~/mypackages directory.

To view the details of the backup file, run:

$ apt-clone info mypackages/apt-clone-state-ubuntuserver.tar.gz 
Hostname: ubuntuserver
Arch: amd64
Distro: bionic
Meta: 
Installed: 516 pkgs (33 automatic)
Date: Sat Sep 15 10:23:05 2018

As you can see, I have 516 packages in total in my Ubuntu server.

Now, copy this file on your USB or external drive and go to any other system that want to install the same set of packages. Or you can also transfer the backup file to the system on the network and install the packages by using the following command:

$ sudo apt-clone restore apt-clone-state-ubuntuserver.tar.gz

Please be mindful that this command will overwrite your existing /etc/apt/sources.list and will install/remove packages. You have been warned! Also, just make sure the destination system is on same arch and same OS. For example, if the source system is running with 18.04 LTS 64bit, the destination system must also has the same.

If you don't want to restore packages on the system, you can simply use --destination /some/location option to debootstrap the clone into this directory.

$ sudo apt-clone restore apt-clone-state-ubuntuserver.tar.gz --destination ~/oldubuntu

In this case, the above command will restore the packages in a folder named ~/oldubuntu.

For more details, refer help section:

$ apt-clone -h

Or, man pages:

$ man apt-clone

Suggested read:


Resource:

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

5 comments

Habadeer September 16, 2018 - 5:22 pm

Does this include packages installed from ppa’s? If so, does it add the ppa to software sources?

Reply
Ievgen Sobko September 18, 2018 - 6:23 pm

From what I see at `https://github.com/mvo5/apt-clone/blob/master/apt_clone.py` it tries to restore `sources.list.d` directory that usually represents ppa repositories
“` python
tar.extract(self.TARPREFIX+”etc/apt/sources.list.d”, targetdir)
“`

Reply
IronManMH12 September 26, 2019 - 12:00 pm

Can this utility be used to clone (backup) on Ubuntu 16.04 and then restore on Ubuntu 18.04 ?

Reply
sk September 26, 2019 - 4:10 pm

No, both source and destination should have the same OS and architecture.

Reply
Guido van Harten November 30, 2019 - 3:58 pm

On a clean system (Ubuntu 18.04 Server) I installed apt-clean using the above mentioned tutorial.
When I ran
[code]# apt-clone info mypackages/apt-clone-state-ubuntuserver.tar.gz[/code]
my system replies:
[code]Traceback (most recent call last):
File “/usr/bin/apt-clone”, line 104, in
info = clone.info(args.source)
File “/usr/lib/python3/dist-packages/apt_clone.py”, line 375, in info
“Date: %(date)s\n” % self._get_clone_info_dict(statefile)
File “/usr/lib/python3/dist-packages/apt_clone.py”, line 330, in _get_clone_info_dict
distro = self._get_info_distro(statefile) or “unknown”
File “/usr/lib/python3/dist-packages/apt_clone.py”, line 316, in _get_info_distro
with tarfile.open(statefile) as tar:
File “/usr/lib/python3.6/tarfile.py”, line 1571, in open
return func(name, “r”, fileobj, **kwargs)
File “/usr/lib/python3.6/tarfile.py”, line 1636, in gzopen
fileobj = gzip.GzipFile(name, mode + “b”, compresslevel, fileobj)
File “/usr/lib/python3.6/gzip.py”, line 163, in __init__
fileobj = self.myfileobj = builtins.open(filename, mode or ‘rb’)
FileNotFoundError: [Errno 2] No such file or directory: ‘mypackages/apt-clone-state-ubuntuserver.tar.gz’
[email protected]:/home/guido#[/code]

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More