2

I'm using Ubuntu 16.04 LTS. I'm a beginner. I installed a lot of Software(Applications, Programs).

I want to Install the same Ubuntu on another computer with the same settings as this one.

XChikuX
  • 250

1 Answers1

1

Backing Up

To get started, please open up a terminal, in Ubuntu this can be done by

Ctrl + Alt + T

Some directories require root or superuser permissions to read and write (needed for backup). For that just execute the following

sudo su

Then Type in your password. You need to have an Administrator privileged account.

For this example, we will change directories to root. This is where the backup will be made. This is an arbitrary decision, you should create the backup elsewhere. For instance to a mounted external hard drive, another partition or disk connected internally, even a folder in your home directory could be used. In all cases, ensure the location your saving the archive to has enough space. Simply use the cd command to navigate there.

cd / 

The following is an exemplary command of how to archive your system.

tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / 

To understand what is going on, we will dissect each part of the command.

tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained bellow.

c - create a new backup archive.

v - verbose mode, tar will print what it's doing to the screen.

p - preserves the permissions of the files put in the archive for restoration later.

z - compress the backup file with 'gzip' to make it smaller.

f - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.

--exclude=/example/path - The options following this model instruct tar what directories NOT to backup. We don't want to backup everything since some directories aren't very useful to include. The first exclusion rule directs tar not to back itself up, this is important to avoid errors during the operation.

--one-file-system - Do not include files on a different filesystem. If you want other filesystems, such as a /home partition, or external media mounted in /media backed up, you either need to back them up separately, or omit this flag. If you do omit this flag, you will need to add several more --exclude= arguments to avoid filesystems you do not want. These would be /proc, /sys, /mnt, /media, /run and /dev directories in root. /proc and /sys are virtual filesystems that provide windows into variables of the running kernel, so you do not want to try and backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev, so you also do not want to backup or restore it. Likewise, /run is a tmpfs that holds variables about the running system that do not need backed up.

It is important to note that these exclusions are recursive. This means that all folders located within the one excluded will be ignored as well.

Restoring

You will want to restore from a Live CD. If needed, first partition and format the drive. You can do this with gparted. Then simply mount the partition you are going to restore somewhere. If you open the drive in nautilus, it will be auto mounted somewhere under /media

That is, In the Backup step You should have copied the Archive to an external media (eg. Flash Drive, External Hard disk)

Take a look to find out where with:

ls /media

Restore Your Backup

sudo tar -xvpzf /path/to/backup.tar.gz -C /media/whatever --numeric-owner

A brief explanation:

x - Tells tar to extract the file designated by the f option immediately after. In this case, the archive is /home/test/backup.tar.gz

-C - This option tells tar to change to a specific directory before extracting. In this example, we are restoring to the root (/) directory.

--numeric-owner - This option tells tar to restore the numeric owners of the files in the archive, rather than matching to any user names in the environment you are restoring from. This is due to that the user id:s in the system you want to restore don't necessarily match the system you use to restore (eg a live CD).

This pretty much sums up what you are asking for in the question. For any more information visit https://help.ubuntu.com/community/BackupYourSystem/TAR from where I have modified my answer from.

XChikuX
  • 250