How to backup your data using rsync

How to backup your data using rsync

The most critical data to back up is data that is impossible, or very costly, to re-create. Usually this is user data that has grown over months or years of work. You can typically restore system data relatively easily by reinstalling from the original distribution media.The Linux utility rsync is a copy program designed to replicate large quantities of data. It can skip previously copied files and fragments and encrypt data transfers with ssh, making remote backups with rsync faster and more secure than they are with traditional tools like cp, cpio, or tar.

The syntax of the rsync command is:

rsync options source destination

The major command-line options for rsync are:

-a   Archive. This option fulfills most of the previously mentioned requirements, and it’s easier to type and pronounce   than     its equivalent, -Dgloprt.

-b  Make backup copies of already existing destination files instead of replacing them. You usually won’t want to use this option unless you want to keep old versions of every file. It can result in the backup servers being filled up very  quickly.

-D Preserve devices. This option is used when replicating system files; it is not  needed for user files. Works only when      rsync is run as root. Included in -a.

-g Preserve the group ownership of files being replicated. This is important for backups. Included in -a.

-H Preserve hard links. If two names being replicated refer to the same file inode, this preserves the same relationship in the destination. This option slows down rsync somewhat, but its use is recommended.

-l Copy symlinks as symlinks. You’ll almost always want to include this option; without it, a symlink to a file would be copied as a regular file. Included in -a.
-n Dry run: see what files would be transferred, but don’t actually transfer them.

-o Preserve the user ownership of files being replicated. This is important for backups.Included in -a.

-p Preserve file permissions. This is important for backups. Included in -a.

-P Enable –partial and –progress.
–partial Enable partial file transfers. If rsync is aborted, it will be able to complete the remainder of the file transfer when it resumes later.

–progress Display file transfer progress.
-r Enable recursion, transferring all subdirectories. Included in -a.
–rsh=’ssh’ Use SSH for file transfer. This is recommended because the default transfer protocol(rsh) is not secure. You can also set the RSYNC_RSH environment variable to ssh to get the same effect.

-t  Preserve the modification times on each file. Included in -a.

-v List the files being transferred.

-vv Like -v, but also list the files being skipped.

-vvv Like -vv, but also print rsync debugging info.

-z Enable compression; more useful over the Internet than on a high-speed LAN.

Back to top