≡ Menu

How To Use rsync Command To Backup Directory Under Linux

Q. How do I use rsync command to back up a home directory under Linux operating system?

A. rsync command easily backup your home directory to local secondary hard disk or remote server using ssh protocol. rsync is a software application for Unix systems which synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate.

Task: Backup /home/tom to /mnt/usbpen

Assuming that USB pen or external USB hard disk is mounted at /mnt/usbpen, enter the following command to backup (sync) new files and changes to existing files but don’t remove files in backup directory:
$ rsync -au /home/tom /mnt/usbpen
To delete files in backup directory that no longer exist in directory being backed up, enter:
$ rsync -au --delete /home/tom /mnt/usbpen

See our previous article about using rsync for transferring files under Linux or UNIX from local or remote network computer.

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 8 comments… add one }
  • Peterson Spaceport November 27, 2009, 12:38 am

    Thanks, simple and effective article! Going to test the commands =)

  • mitch February 12, 2010, 4:47 pm

    Thank you, very helpful
    M

  • pcman August 23, 2010, 10:55 am

    Yeah it is easy as can be…Thanks.

  • Leontianos December 16, 2010, 6:21 am

    Thank you :) very usefull

  • Erik February 17, 2011, 7:56 pm

    Thanks.
    I also do rsync -aurl –delete /source /destination
    to backup.

  • Amanullah March 25, 2013, 6:58 am

    Thanks for this ….very easy to use…:) very usefull

  • Francois Scheurer August 12, 2013, 3:37 pm

    thanks for this article.
    i wrote a free rsync script to backup a whole system:
    http://blog.pointsoftware.ch/index.php/howto-local-and-remote-snapshot-backup-using-rsync-with-hard-links/

    It uses the same idea of file deduplication thanks to hard-links, uses also MD5 integrity signature, ‘chattr’ protection, filter rules, disk quota, retention policy with exponential distribution (backups rotation while saving more recent backups than older, so with 10 backups can can keep one year of daily backups).

    it can be used locally on the servers or per network on a central remote backup server for DRP and datacenter replication using only little network bandwidth and transport encryption tunnel.

  • George October 6, 2013, 2:40 pm

    looks good, but how do you restore it from rsync if your main directory is messed up?

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , ,