Backup Your Entire Linux System Using Rsync
Today, I wanted to reinstall one of my virtual machine which is running with Ubuntu 16.04 LTS server. Before reinstalling, I tried to backup the entire system. While searching for an easiest way to do this, I found a plausible solution in Arch Linux wiki page. I never thought that it was going to be that much simple. I copied my entire root / tree with Rsync in a single line command. Yes, it is just a one line command. While there there so many tools to backup your systems, I find this method is much easier and convenient, at least to me. Also, this method is better than disk cloning with dd command. Because It doesn’t matter if your hard drive is different size, or use different filesystem. This method will work in all cases.
In this brief tutorial, I will explain how to backup your entire Linux system using Rsync utility.
First, insert your backup medium (Pend drive or External hard disk). Then find the drive letter using ‘fdisk -l’ command. In my case, my Pen drive id is /dev/sdb1. Mount your drive to any location of your choice.
To backup the entire system, all you have to do is open your Terminal and run the following command as root user:
This command will backup the entire / directory, excluding /dev, /proc, /sys, /tmp, /run, /mnt, /media, /lost+found directories.
Let us break down the above command and see what each argument does.
- rsync – A fast, versatile, local and remote file-copying utility
- -aAXv – The files are transferred in “archive” mode, which ensures that symbolic links, devices, permissions, ownerships, modification times, ACLs, and extended attributes are preserved.
- / – Source directory
- –exclude – Excludes the given directories from backup.
- /mnt – It is the backup destination folder.
Please be mindful that you must exclude the destination directory, if it exists in the local system. It will avoid the an infinite loop.
To restore the backup, just reverse the source and destination paths in the above command.
Please be mindful that this is suitable for local and stand-alone systems only. If your system is being actively accessed by some other systems on the network, it isn’t better solution. Because, the contents of these systems might be constantly updated every minute, and some files may change during the rsync process. Say for example, when rsync will reach the file 2, the contents of the previous file (File 1) might be changed. This will leave you with a dependency error when you will need to use that backup. In such cases, a snapshot-based backup is the better approach. Because the system will get “froze” before the backup process starts and get it “unfreeze” when the backup process finishes, so all the files are consistent.
And, that’s all. Hope this helps. If you find our guides useful, please share them on your social, professional networks, so that other users can also benefit from them. We will be keep posting more good stuffs everyday. Stay tuned with us to read awesome stuffs.
Cheers!
Source:
No comments:
Post a Comment