Helpful command:: Rsync

Helpful command:: Rsync

What is Rsync?Rsync is a very useful alternative to rcp written by Andrew Tridgell and Paul Mackerras. Rsync is a program, which is used for taking the backups on regular basis. However it can also be configured to upload large portals and any other data on the remote servers. . This is a great method for backups as it is low on bandwidth and it is also commonly used to keep clustered servers working together. It is very similar to rcp but with many more features. It is based on remote-update protocols, which means that it only sees the differences between the source and destination files and if the files has been changed, takes the backup otherwise leaves it without taking any backup. This difference may be the time stamp difference i.e. the date when it was modified or created is changed. By virtue of which it speeds up the file transfers even if it is of several gigabytes.

Rsync configuration files

There are three configuration files to run rsync server viz.
1. /etc/rsyncd.conf,
2. /etc/rsyncd.pid
3. /etc/rsyncd.secrets
1) /etc/rsyncd.conf

When you run Rsync with –daemon mode /etc/rsyncd.conf is the runtime configuration file through inetd daemon. This way rsync becomes an rsync server listening on TCP port 873. Connections from Rsync clients are accepted for either anonymous or authenticated Rsync sessions. The rsyncd.conf file controls authentication, access, logging and available modules.

2. The file /etc/rsyncd.secrets can be like this containing the username and password with a colon in between on the client side i.e.

username : yourpassword

3. To create an empty file /etc/rsyncd.pid to place the process related arguments.

The general form is:

rsync source destination

A few real life examples are:

rsync -vrplogDtH /old/var/named/ /var/named/

That will sync the /old/var/named/ directorty to the /var/named/ directory on the same server.

If you want to use rsync to go between servers then use the following:

rsync -ave ssh [email protected]:/backup/ /backup/

That will take the backup directory on 192.168.0.1 and copy it to the server the command is run from. The command will also accept a remote destination if you adjust the command line accordingly. Below is the readout of rsync –help which also shows more of the command options available:

Usage: rsync [OPTION]… SRC [SRC]… [[email protected]]HOST:DEST

or rsync [OPTION]… [[email protected]]HOST:SRC DEST

or rsync [OPTION]… SRC [SRC]… DEST

or rsync [OPTION]… [[email protected]]HOST::SRC [DEST]

or rsync [OPTION]… SRC [SRC]… [[email protected]]HOST::DEST

or rsync [OPTION]… rsync://[[email protected]]HOST[:PORT]/SRC [DEST]

or rsync [OPTION]… SRC [SRC]… rsync://[[email protected]]HOST[:PORT]/DEST

SRC on single-colon remote HOST will be expanded by remote shell

SRC on server remote HOST may contain shell wildcards or multiple

sources separated by space as long as they have same top-level

Useful command-line switches

v, –verbose increase verbosity
-q, –quiet decrease verbosity
-c, –checksum always checksum
-a, –archive archive mode, equivalent to -rlptgoD
-r, –recursive recurse into directories
-R, –relative use relative path names
-b, –backup make backups (default ~ suffix)
–backup-dir make backups into this directory
–suffix=SUFFIX override backup suffix
-u, –update update only (don’t overwrite newer files)
-l, –links copy symlinks as symlinks
-L, –copy-links copy the referent of symlinks
–copy-unsafe-links copy links outside the source tree
–safe-links ignore links outside the destination tree
-H, –hard-links preserve hard links
-p, –perms preserve permissions
-o, –owner preserve owner (root only)
-g, –group preserve group
-D, –devices preserve devices (root only)
-t, –times preserve times
-S, –sparse handle sparse files efficiently
-n, –dry-run show what would have been transferred
-W, –whole-file copy whole files, no incremental checks
–no-whole-file turn off –whole-file
-x, –one-file-system don’t cross filesystem boundaries
-B, –block-size=SIZE checksum blocking size (default 700)
-e, –rsh=COMMAND specify the remote shell

Sharing

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.