Use rsync for file synchronization in Linux

Source: Internet
Author: User
Tags rsync
> Use rsync to synchronize data from the server. Here we only talk about one-way synchronization.

First install rsync

# Server Configuration
The server uses 'xinetd' to act as the 'rsync' daemon. If not, install
> Xinetd listens to a specified port, fork the service program corresponding to the configured port, and then continues to listen.

#1. Configure the xinetd configuration file for rsync:

# Nano/etc/xinetd. d/rsync

Service rsync
{
Disable = No
Flags = IPv4
Socket_type = stream
Wait = No
User = root
Server =/usr/bin/rsync
Server_args = -- daemon
Log_on_failure + = userid
}

#2. Configure rsync to automatically start

# Chkconfig rsync on

#3. Configure rsync

# Nano/etc/rsyncd. conf

Uid = root # the user who runs the rsync daemon
Gid = root # group for running the rsync daemon
Use chroot = No # Do not use chroot
Max connections = 0 # maximum number of connections, 0 Unlimited
Strict modes = yes # Check the permission on the password file. If yes, other users cannot access the password file.
Prot = 873 # listening port
PID file =/var/run/rsyncd. PID
Lock file =/var/run/rsync. Lock
Log File =/var/log/rsyncd. Log

# Backup module
[Backup]
Path =/opt/backup
Comment = backup files
Auth users = backupuser # the user that is allowed to access must be in the password file
Uid = root
Gid = root
Secrets file =/etc/rsyncd. Secret # Password File
Read Only = No
List = No

#4. Check whether the rsync port number in '/etc/services' is the same as that in its configuration file.

# Less/etc/services

...
Rsync 873/tcp # rsync
Rsync 873/udp # rsync
....

#5. Configure the password file

# Nano/etc/rsyncd. Secret

# Username: Password
Backupuser: passwd

Change Password File Permissions

# Chmod 400/etc/rsyncd. Secret

#6. Enable 'xinetd'

#/Etc/init. d/xinetd restart

Then check to see if the instance is started properly:

# Lsof-I: 873
Command PID user FD type device size node name
Xinetd 4396 root 5u IPv4 633387 tcp *: rsync (Listen)

# Client Configuration
You only need to install 'rsync' on the client.

#1. Configure the password file

# Nano/etc/rsyncd. Secret

# Password only
Passwd

Set permissions

# Chmod 600/etc/rsyncd. Secret

#2. synchronize data from the slave server

# Rsync-avz -- password-file =/etc/rsyncd. Secret backupuser@192.168.1.2: backupuser/opt/backup/

# Summary

You can place the synchronization script in the corntab on the client to regularly synchronize data.

# Common global options
** Motd file **: Set the welcome message.

** PID file **: This option tells daemon to write its process ID to the specified file. If the file already exists, daemon stops running, instead of overwriting the original file.

** Port **: Set the port of the daemon running listener. If daemon is run by inetd, this option is ignored. If -- port is specified in the command line, this option is replaced.

** Address **: Set the address of the rsync daemon runtime listener. Same as above. If daemon is run by inetd or -- port has been specified in the command line, this option will be ignored or replaced.

# Module Parameters
** Path **: Set the directory location of the module.

** Use chroot **: Specifies whether to use chroot. The value is yes or no. I recommend no.

** Max connections **: this parameter sets the maximum number of connections that daemon allows each client to initiate. If the maximum number of connections is exceeded, the client will receive a warning. If the value is 0, it indicates no restriction. If the value is negative, it indicates that this module is disabled.

** Lock file **: this parameter is used to support Max connection. It specifies a file to record client requests to ensure that client requests do not exceed the maximum number of connections.

** Log File **: Set the location of the log file of this module. If this parameter is not set, or rsync daemon fails to read the specified file, rsync uses syslog To record logs; if this parameter is set only in each module but not globally, the global log only records the message of Authorization failure or configuration file error.

** Read only **: Set whether to allow the client to upload files. The default value is yes, and files cannot be uploaded.

** Write only **: Specifies whether to allow the client to download files. The default value is no. This parameter indicates whether to allow downloading files)

** List **: Set whether the module is allowed to be listed. It is similar to Samba's browseable. The default value is yes. We can set it to no to create a hidden module.

** Uid **: When rsync daemon runs as a root user, this parameter is specified to transmit files to this module, or the user identity (User Name or user ID) When the file is transferred from this module. The default value is-2, that is, nobody user.

** GID **: indicates a uid. The default value is-2, that is, the nobody group.

** Incoming chmod **: this parameter allows you to specify multiple permission characters separated by commas. These permissions affect all files received by daemon. These permissions take effect after all other permissions, which means that if the client does not specify -- perms, They overwrite the default and (and or) Existing permissions of the target.

** Auth users **: this parameter specifies the list of users allowed to access this module. The user names in the list are separated by commas (,) and spaces. The specified user does not have to actually exist in the local system. The user name can also contain shell wildcards. The plain text username and password are stored in the file specified by the "Secrets file" parameter.

** Secrets file **: this parameter specifies a password file for authorization verification of this module. This file is considered only when the "auth users" parameter is specified. The password can contain no more than 8 characters. This parameter has no default value. You must manually create a password file and the file should not be accessed by other users.

** Strict modes **: this parameter determines whether to perform a permission check on the password file. If the value is yes, except for running rsync daemon, other users cannot access the file. The default value is yes.

** Fake super **: If this module is set to fake super = Yes, the effect is the same as if -- fake-Super is specified in the command line. It can store the complete attributes of a file without running daemon as root.
** Hosts allow **: in short, this parameter specifies the client name or IP address that is allowed to access the module. You can specify a specific IP address or use a mask to specify an IP address segment. When both hosts allow and hosts deny are specified, check hosts allow first, and the matching client will be allowed to access this module. Then check hosts deny, and the matching client will be rejected; clients that do not match hosts allow and do not match hosts deny will be allowed to access.

** Hosts deny **: the client specified by this parameter cannot access this module.

** Ignore errors **: If this parameter is specified, rsync ignores the I/O error of daemon during the delete operation during transmission. In general, if any I/O error occurs, rsync ignores the -- delete operation to prevent catastrophic (File) caused by temporary resource shortage or other I/O errors) lost.

** Timeout **: rsync timeout setting to prevent dead connections from the client, in seconds. The default value is 0, which means no timeout is defined.

** Dont compress **: This option allows you to specify some wildcard-based file names. When pulling files from daemon, these files will not be compressed. Option to accept a list of case-sensitive wildcard modes separated by spaces. Similar to -- skip-compress = List in the command line, and overwrites the parameters in the command.

** Filter **: this parameter accepts a list of daemon filter rules separated by spaces. Each module only accepts one filter parameter. Therefore, all rules must be written to one filter parameter. You can use the normal syntax to specify one or more merge-files as one rule.

** Exclude **: this parameter receives a list of daemon exclusion rules separated by spaces, just like the -- exclude option on the client, it uses "-" or "+" to specify exclusion or inclusion. One module can have only one exclude parameter.

** Include **: this parameter can overwrite the exclude effect. Each module can have only one include parameter.

** Exclude from **: this parameter specifies a file on the daemon to contain the daemon exclusion rules. Each row contains one rule ). Each module can have only one exclude from parameter. If multiple exclude-from files exist, you can regard them as a merge file in the filter parameter.

** Include from **: similar to exclude from.

# Rsync Command Parameters
**-V **, -- verbose detailed mode output

**-Q **, -- Quiet streamlined output mode

**-C **, -- checksum enables the verification switch and forces file transfer verification.

**-A **, -- Archive mode, indicates that the file is transmitted recursively, and all file attributes are kept, equal to-rlptgod.

**-R **, -- Recursive processes subdirectories in recursive Mode

**-R **, -- relative uses relative path information

**-B **, -- backup creates a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes.

** -- Backup-Dir ~ Filename) is stored in the directory.

**-Suffix = suffix ** defines the backup file prefix.

**-U **, -- Update is only updated, that is, all files that already exist in DST and whose file time is later than the time to be backed up are skipped. (Do not overwrite the updated file)

**-L **, -- links retains soft links

**-L **, -- copy-links handles soft links like regular files

** -- Copy-unsafe-links ** only copies links other than the src directory tree.

** -- Safe-links ** ignores links other than the SRC path directory tree.

**-H **, -- hard-links retains the hard link

**-P **, -- perms maintains the File Permission

**-O **, -- owner keeps file owner information

**-G **, -- Group maintains the file group information.

**-D **, -- devices keeps the Device File Information

**-T **, -- times maintains the file time information

**-S **, -- sparse performs special processing on sparse files to save DST Space

**-N **, -- dry-run which files will be transmitted in reality

**-W **, -- whole-file: copy a file without incremental Detection

**-X **, -- one-file-system does not span the file system boundary.

**-B **, -- block-size = size indicates the block size used by the algorithm. The default value is 700 bytes.

**-E **, -- RSH = command specifies that RSH and SSH are used for data synchronization.

** -- Rsync-Path = path ** specifies the path of the rsync command on the remote server.

**-C **, -- CVS-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted.

** -- Existing ** only updates the files that already exist in DST, instead of backing up the newly created files.

** -- Delete ** delete the files that SRC does not have in DST.

** -- Delete-excluded ** also deletes files excluded by this option on the receiving end.

** -- Delete-after ** Delete after transmission

** -- Ignore-errors ** Delete Io errors in a timely manner

** -- Max-delete = num ** a maximum of num files can be deleted.

** -- Partial ** retains the files that are not completely transferred for any reason to accelerate subsequent re-transmission.

** -- Force ** forcibly deletes a directory, even if it is not empty.

** -- Numeric-IDs ** does not match the number user and group ID with the user name and group name.

** -- Timeout = Time ** IP timeout time, in seconds

**-I **, -- ignore-times does not skip files with the same time and length.

** -- Size-only ** when deciding whether to back up a file, you only need to check the file size, regardless of the file time.

** -- Modify-window = num ** determines whether the timestamp window of the file is used at the same time. The default value is 0.

**-T ** -- temp-Dir = dir create a temporary file in Dir

** -- Compare-Dest = dir ** compare the files in Dir to determine whether to back up data.

**-P ** is equivalent to -- partial

** -- Progress ** displays the backup process

**-Z **, -- compress compresses the backup files during transmission

** -- Exclude = pattern ** specifies the file mode that does not need to be transmitted.

** -- Include = pattern ** specifies the file mode to be transmitted without exclusion

** -- Exclude-from = file ** exclude files in the specified mode in file.

** -- Include-from = file ** does not exclude files in the specified file mode.

** -- Version **: prints version information.

** -- Address ** bind to a specific address

** -- Config = file ** other configuration files are specified. The default rsyncd. conf file is not used.

** -- Port = port ** specify other rsync service ports

** -- Blocking-io ** use blocking Io for remote shell

**-Stats ** indicates the transmission status of certain files.

** -- Progress ** actual transmission process during transmission

** -- Log-format = format ** specifies the log file format

** -- Password-file = file ** get the password from File

** -- Bwlimit = kbps ** limits I/O bandwidth and Kbytes per second

**-H **, -- help displays help information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.