How to back up your entire Linux system using Rsync

Today we wanted to reinstall one of the virtual machine that runs Ubuntu 16.04 LTS server. Before installing, we tried to make a backup of the entire system. When looking for an easy way to do this, found a compelling solution on the Arch Linux wiki page. We never thought it would be much easier. We have copied the entire root using one touch Rsync command. Yes, it’s just a one line command. While there are many tools out there to back up your systems, this method is much easier and more convenient. Also, this method is better than cloning a disk using the command dd… Because it doesn’t matter if your hard drive is of a different size, or uses a different file system. This method will work in all cases.

In this quick guide, we will explain how to a backup of the entire Linux system using the Rsync utility.

Backing up your entire Linux system with Rsync

First, insert the backup media (external hard drive or other media). Then find the disk ID using the “fdisk -l” command. In our case, the disk identifier / dev / sdb1… Mount the drive anywhere you choose.

sudo mount /dev/sdb1 /mnt

To back up the entire system, all you need to do is open a terminal and run the following command as user root:

sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt

This command will back up the entire directory /, except for the directories / dev, / proc, / sys, / tmp, / run, / mnt, / media, / lost + found.

Let’s break down the above command and see what each argument does.

  • rsync – Fast, versatile, local and remote file copy utility
  • -aAXv – Files are transferred in “archive” mode, which ensures that symbolic links, device, permission, ownership, modification time, ACLs, and extended attributes are preserved.
  • / – Source directory
  • -exclude – Excludes these directories from the backup.
  • / mnt – This is the destination folder for the backup.

Please remember that you should exclude the destination directoryif it exists on the local system. This will avoid an endless loop.

To restore a backup, simply swap the source and destination paths in the command above.

Please remember that this is only suitable for local and offline systems. If your system is actively accessing some other systems on the network, this is not the best solution. So, the content of these systems may be constantly updated every minute, and some files may change during the rsync process. Say, for example, when Rsync reaches file 2, the contents of the previous file (File 1) might be changed. This will leave you with a dependency error when you need to use that backup. In such cases, a snapshot backup is the best approach. Because the system will be “frozen” before starting the backup process and will allow it to “unfreeze” when the backup process finishes, so that all files will be compatible.

And it’s all. Hope this helps. If you find our article helpful, please share them on social, professional networks so that other users can benefit from them as well.

Sidebar