How to Back Up Entire Linux System?

Creating a backup is one of the primary duties of a system administrator. It is because the data can be lost under certain situations, which can be recovered if it is backed up. Professionals highly recommend keeping a backup of essential data from time to time. What if a Linux system is corrupted or requires a fresh install, and it is evident that most of the data are lost during installation? Now the question is how to back up the entire Linux system.

This guide will shed some light on the possible ways to back up the entire Linux system:

  • dd Command
  • tar Command
  • GNOME Disk Utility

Method 1: Back up the Linux System Using the dd Command

The “dd” is a powerful command line tool primarily used to copy files from one location to another. Other uses include cloning and wiping the disk data. Since Linux treats everything as a file, it makes using the “dd” command even more prominent.

To perform a complete system back of your Linux system, make sure to know the disk you are doing back up of using this command:

$ sudo cfdisk

The above image shows that there are three devices and there are a few other commands as well which are explained in detail in this guide. Here, the “/deb/sda” is where the Linux system is installed. 

Backup the File System:

To backup, it, use this dd command:

$ sudo dd if=/dev/sda3 of=Path-To-Where-The-Backup-Is-Stored<filename.img>

Here is the breakdown of the above command:

  • The “dd” is used to invoke the command
  • if=/dev/sda3 is the disk whose backup is being done
  • of=path.filename.img  specifies the name, location, or drive where the backup file is stored.

The backup process takes a few minutes to complete, and once done, the backup file can be found in the specified location. Ensure to provide the file name at the end; otherwise, it will start creating the backup of the current disk to the other disk.

Restore the Linux System:

To restore this backup to another drive, use this command:

$ sudo dd if=Path-To-Backup-File.img of=Path-To-Destination bs=1k

Here is a breakdown of the above command:

  • The “dd” is used to invoke the command
  • if=Path specifies the path for the backup file.
  • of=Path specifies the destination disk where the backup is to be restored.
  • bs=1k specifies the block size, which the dd command uses to read and write bytes per block.

Method 2: Backup the Linux System Using the tar Command

One of the features of the “tar” command on Linux includes data backup, which can save disk space by compressing the backup file. It stands for tape archive, which can combine multiple files and directories/

Backup the File:

To create a backup file of the entire Linux system using the tar command, this format is used:

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

Here is a breakdown of the above command:

  • The “tar” command invokes the command.
  • -c is used to create a new archive (for backup).
  • -v or verbose mode to view what is happening.
  • -p preserves the file permissions, which can later be restored.
  • -z uses the gzip command for compression.
  • –exclude=/backup.tar.gz ensures that the backup.tar.gz file is not in the backup since the tar command backups all the data.
  • –one-file-system is there to ensure not to include the different file systems (in case the Windows file system is mounted). 

Restore the File:

To restore the backup created using the tar command, use this format:

$ sudo tar -xvpzf /path/to/backup.tar.gz -C /path/to/restore --numeric-owner

Here is a breakdown of the above command:

  • -x is used to extract the file.
  • -v or verbose mode to view what is happening.
  • -p preserves the file permissions, which can later be restored.
  • -z uses the gzip command for compression.
  • -f tells the tar command that the following argument is the name of the backup archive.

Method 3: Backup the Linux System Using the GNOME Disks

GNOME disks utility offers the management of the disks through GUI. It comes by default with most GNOME-based Linux distributions. To use it to back up the entire Linux system, follow the steps provided below:

Step 1: Install GNOME Disk Utility

The GNOME Disk Utility is pre-installed on Ubuntu and Debian. Use these commands if not installed.

$ sudo apt install gnome-disk-utility                 #Ubuntu/Debian
$ sudo dnf install gnome-disk-utility                 #Fedora
$ sudo zypper install gnome-disk-utility          #OpenSUSE
$ sudo pacman -s gnome-disk-utility                   #Arch Linux

The above image confirms the installation of gnome disk utility on Ubuntu 22.04 LTS.

Step 2: Open GNOME Disk Utility.

To open GNOME disk utility, press the “window” key or click on “Activities” in the upper left corner of the screen. Now type “Disk” and then open it.

A new window opens up after clicking on “Disks.

Step 3: Choose the File System and Create a Disk Image

From the Disks, select the drive where the Linux system is installed (1), then select the volume (2). Click on the three vertical dots from the pop-up, and select “Create Disk Image (3).”

From the next screen, specify the name (1) and the location where to save it (2).

And when you click on “Start Creating,” the backup process will start.

Step 4: Restore the Linux System From the Backup File. 

When the backup process is completed, go to “Disks” again, and from the “three dots,” select “Restore Disk Image.”

From the new screen, select the backup file (.img file created in the previous step) and click on “Start Restoring.

The backup file will now replace all the files on the current disk.

Conclusion

Linux offers the “dd” and “tar” command line utilities to back up the system using commands. Moreover, the GNOME  disks utility provides GUI support to serve the purpose. Comparing the above two, the command line method is recommended and effective. This post has presented the multiple methods to back up the entire Linux system.