How To Backup Your Entire Linux System Using Rsync

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.

Backup Your Entire Linux System Using Rsync

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.

sudo mount /dev/sdb1 /mnt

To backup the entire system, all you have to do is open your Terminal and run the following command as root user:

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

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.

Recommended Read: ExplainShell – Find What Each Part Of A Linux Command does

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.



Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

  • dzs

    Greetings Dear Writer!

    This article is look so useful, however I don’t know one thing or maybe I could not solve.

    If I have back up my entire system for a pendrive with rsync – in this case – , what shall I do with the system that the pendrive contains?. May I get an .iso or something else file or can I use for a ‘Live media’?

    Sorry for my bad english and my silly question. 🙂

    Best regards, Laci

  • InvisibleInk

    I like to backup only my home directory, minus the hidden dot files. That way, I can get a fresh, clean start on a new distro.

    Here I’m backing up my home folder on an Ubuntu or Ubuntu-based distro to a folder named “synced-backup” on an external USB hard disk with the volume label “Seagate.”

    rsync -r -t -v –progress –delete –exclude=”.*” –exclude “.*/” -s /home/$USER/ /media/$USER/Seagate/synced-backup

    • SK

      Great tip. Thank you.

  • H0rnet

    Rsync is not a backup tool, instead it’s an efficient way transfer files and directories. It offers no point in time recovery options by it self. If you delete​ something on Monday you wouldn’t​ be able to restore it on Wednesday because Tuesdays backup will also remove the deleted file. You would be better off with a tools like rdiff-backup.

  • Dan St.André

    There is a package called LuckyBackyup [ — I am not affiliated. ] that is a desktop GUI deployment of ‘rsync’ based backup and restore. It runs as two editions: one as end-user; one as root-user. If you really like ‘rsync’ for backup-recovery, I encourage you to take a look at LuckyBackup.

    • SK

      Thank you Dan. I will check it soon.

  • Cesar Jimenez

    I modified for faster input instead of
    Just use
    important no space after comma.
    –exclude={/bak1,/cdrom,/dev,/home,/lost+found,/media,/mnt,/proc,/run,/sys,/tmp} / /bak1