CentOS system rsync file Sync installation configuration

Source: Internet
Author: User
Tags custom name rsync

Rsync is a data-mirroring Backup tool under Unix-like systems, which can be seen from the name of the software--remote sync

it has the following characteristics:
The entire directory tree and file system can be saved in a mirror.
It is easy to keep the original file permissions, time, soft and hard links and so on.
Install without special permissions.
Fast: When you synchronize for the first time, rsync copies the entire content, but only the modified files are transferred the next time. Rsync can compress and decompress in the process of transmitting data, so it can use less bandwidth.
Security: You can use SCP, SSH and other means to transfer files, of course, you can also through a direct socket connection.
Support anonymous transmission, to facilitate the site mirror image.


First, server-side configuration:
# yum-y Install xinetd

# Vi/etc/xinetd.d/rsync
The following code

Copy CodeThe code is as follows:
Service rsync
{
Disable = yes
Socket_type = Stream
wait = no
user = root
Server =/usr/bin/rsync
Server_args =–daemon
Log_on_failure + = USERID
}

In the Disable = yesChange into Disable = no

Then start xinetd
#/etc/init.d/xinetd Start or service xinetd restart
Note: If a firewall is installed on the server, remember to open the port, the default port is 873

# telnet 127.0.0.1 873
Trying 127.0.0.1 ...
Telnet:connect to address 127.0.0.1:connection refused
# iptables-a input-s 192.168.0.0/255.255.255.0-p tcp-m tcp--dport 873-j ACCEPT
# iptables-a input-p tcp-m tcp--dport 873-j DROP

# vi/etc/rsyncd.conf (this file is created if it does not exist)

#Global Settings
UID = root #以什么身份运行rsync
GID = root
Use chroot = no #不使用chroot
Max connections = #最大连接数
Secrets file =/etc/rsyncd.secrets #密码文件位置, authentication files settings, setting user name and password
Log file =/var/log/rsyncd.log #指定rsync的日志文件 without sending the log to the Syslog
PID file =/var/run/rsyncd.pid #指定rsync的pid文件
Lock file =/var/run/rsync.lock #指定支持max The connections parameter, the default value is/var/run/rsyncd.lock
Comment = Hello World
#motd file =/etc/rsyncd.motd #欢迎信息文件名称和存放位置 (this file is not, you can add it yourself)

[Backup] # Here is the authentication module name, which needs to be specified on the client side
Path =/titan24/www/repos # needs to be mirrored in the directory
Auth users = rsync # Authorized account number. The authenticated user name, if not this line, indicates that it is anonymous, used by multiple users, separated
Read Only = no # Yes ReadOnly value is no meaning readable writable mode, data recovery with no
Hosts allow = 192.168.3.128 #允许访问的服务器IP
Hosts deny = * #黑名单
List = true # Allow column file
#ignore errors # can ignore some unrelated IO errors
#exclude = cache/111/cache/222/#忽略的目录

# Vi/etc/rsyncd.secrets (Set access (authentication) Username password)

rsync:111111 # User name: password

Correct permissions to the file
# chown Root:root/etc/rsyncd.secrets
# chmod 600/etc/rsyncd.secrets # (must be 600)

Second, the client side to synchronize

The client default seems to have Rsync installed, without the following:
# yum-y Install rsync

To perform an asynchronous synchronous operation:

/usr/bin/rsync-avz--progress [Email protected]::backup/www

# crontab-e # (can synchronize files every three minutes at regular intervals)

*/3 * * * * RSYNC-AVZ--progress [email protected]::backup/www

The following command is complete:

#vi/etc/rsyncd.pas
Add password
Rsyncofpass
Note that the client's password file requires only a password, not a user name!

To change file permissions:
#chmod 0600/etc/rsyncd.pas

#rsync-vzrtopgu--progress--delete--password-file=/etc/rsyncd.pas [email protected]::rsync_module_name1/www/

The V in-VZRTOPG in this command line is verbose,
Z is a compressed transmission,
R is recursive,
TOPG are the parameters that preserve the original attributes of the file, such as owner and time.
U is to synchronize only the files that have been updated, to prevent the files that are not updated from being updated again, but note the synchronization of the clocks of the two machines.
–progress means to show detailed progress,
–delete means that if the server side deletes the file, then the client also deletes the file accordingly, maintaining true consistency.
After the [email protected]::rsync_module_name1, the rsync_module_name1 is the module name, which is the custom name in/etc/rsyncd.conf, rsync_ User is the username specified in the specified module that can be synchronized.
The last/www is the directory name that is backed up to local.
In this case, you can also use the parameters of-e ssh to establish an encrypted connection.
You can use the –password-file=/password/path/file to specify the password file, so that it can be used in the script without the need to interactively enter the authentication password, it is important to note that this password file permission property to be set to only the main readable.

#/usr/local/rsync/bin/rsync-vzrtopg–progress–delete[Email protected]::rsync_module_name1/tmp/
Password:
Or you can also make password files
Because of the need for the system crontab execution, so here is the way to read the password file,
This is the time to succeed.

synchronization Command Description:

1 Displaying directory Contents

Command
——
A) rsync
b) rsync-r
c) rsync [email protected]::
d) rsync [email protected]:

Command description
———
A) Display directory contents (first tier)
b) Recursive display of directory contents
c) Display the contents of the remote host directory
* NOTE 1: Port mode, based on rsync user authentication
* Note that directories on 2:rsync server must have XX7 permissions.

d) View the contents of the remote host directory
* Note 1:remote shell mode, system-based local user authentication via SSH connection
* NOTE 2: This only uses a colon (:), the user name is the remote host SSH user, the password is also the SSH user's corresponding password.
* Note 3: Use "" To list information about the folder itself. To List Folder contents, you should use "/".

Parameter description
———
-R recursively working with directories

2 Synchronizing between local directories

Command
——
a) rsync-av–progress/* * * * NOTE (/) * * *
b) rsync-av–progress
c) Rsync-avu–progress–delete/
D) rsync-av–progress–temp-dir=/tmp/

Command description
———
A) Synchronize all files under the Src-dir directory to the Dst-dir directory
b) Synchronize all files under the Src-dir directory to the Dst-dir/src-dir directory
c) The Src-dir directory content to the Dst-dir directory for the differential update, there are additions/updates are added to replace, there is a reduction in its deletion
D) More than a –temp-dir=/tmp, that is, specify/tmp as the temporary swap area, this can avoid the lack of target directory space caused by the inability to synchronize the file error.

Parameter description
———
-A is equivalent to a collection of-rlptgod
-U is equivalent to –update and is not updated when the target file is newer than the source file
-V Show Synchronized files
–progress show the percent progress, transfer rate for file synchronization
–delete Delete files in the destination directory that are more than the source directory

3 Synchronizing between offsite hosts
Command
——
a) rsync-avz–progress [email protected]::/
b) rsync-avz–progress [email protected]::/–password-file=/home/jack/rsync.jack
c) Rsync-avuz–progress–delete [email protected]::/–password-file=/home/jack/rsync.jack
d) rsync-avz–progress [email protected]::/

Command description
———
A) Synchronize the contents of the local directory to the directory of the remote host 192.168.0.1, Jack is the Rsync database user (see 3./etc/rsync.secrets)
b) Synchronization of non-interactive login files by automatically reading user passwords
c) more than B)-U and –delete
d) Synchronizing remote host content to a local directory

CentOS system rsync file Sync installation configuration

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.