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?

ADVERTISEMENTS

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.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
8 comments… add one
  • Peterson Spaceport Nov 27, 2009 @ 0:38

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

  • mitch Feb 12, 2010 @ 16:47

    Thank you, very helpful
    M

  • pcman Aug 23, 2010 @ 10:55

    Yeah it is easy as can be…Thanks.

  • Leontianos Dec 16, 2010 @ 6:21

    Thank you :) very usefull

  • Erik Feb 17, 2011 @ 19:56

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

  • Amanullah Mar 25, 2013 @ 6:58

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

  • Francois Scheurer Aug 12, 2013 @ 15:37

    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 Oct 6, 2013 @ 14:40

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.