Use rsync to synchronize files

Source: Internet
Author: User
Tags custom name

Rsync-> remote synchronize
Well, you don't have to explain it. Let's explain it. What does file synchronization mean...

First, download the free software.

Rsync.samba.org/or samba.anu.edu. au/rsync
Latest Version on this site
Http://www.jb51.net/softs/2149.html
PS: You must go to the official website to download the latest version,
In versions earlier than 2.6.1, the module path traversal vulnerability exists...

After decompression, compilation is simple
./Configure-Prefix =/usr/local/rsync & make install

Configure the server first.

Edit the server configuration file first.

# Vi/etc/rsyncd. conf

# Global configuration
Uid = root
Gid = root
Hosts allow = 192.168.0.0/24
# Hosts deny = 0.0.0.0/32

Use chroot = No # Do not use chroot
Max connections = 10 # the maximum number of connections is 10
# Motd file =/etc/rsyncd. motd # Welcome information file name and storage location (this file does not exist, you can add it on your own)
PID file =/var/run/rsyncd. pid # specify the PID file of rsync
Lock file =/var/run/rsync. Lock # specifies the lock file that supports the max connections parameter. The default value is/var/run/rsyncd. Lock.
Log File =/var/log/rsyncd. log # specify the rsync log file instead of sending the log to syslog.

# Below is the configuration of each module
[Rsync_module_name1] # The Authentication Module name must be specified on the client.
Path =/rsync_path/dir1 # directory of the image
Comment = rsync files
Ignore errors # ignore unrelated Io errors
Read Only = yes # Read-Only
List = No # column Files Not Allowed
Auth users = rsync_user # The authenticated user name. If this row is not used, the user name is anonymous. Multiple users are separated by commas (,).
Secrets file =/etc/rsyncd. Pas # authentication file name
# PID file =/var/run/rsyncd. PID
# Log file =/var/log/rsyncd. Log
# Lock file =/var/run/rsync. Lock

[Rsync_module_name2]
......

In this case, I personally think that no configuration item can be configured both globally or within the module. If there is a global configuration in the module,
The internal configuration of the module overwrites the global configuration.

Then edit the authentication file you specified above. Here I am:/etc/rsyncd. Pas

# Vi/etc/rsyncd. Pas
Format: Username: Password
Rsync_user: rsyncofpass

For security reasons, modify the attributes of the authentication File
# Chmod 0600/etc/rsyncd. Pas

OK. Start now and try again.

#/Usr/local/rsync/bin/rsync-daemon
You can also specify the port on which rsync runs.
#/Usr/local/rsync/bin/rsync-Daemon-Port = 873

There are several different methods to get the service up at startup, such:

Add inetd. conf
Edit/etc/services, add rsync 873/tcp, and set the service port of rsync to 873.
Edit/etc/inetd. conf and add rsync stream tcp Nowait root/bin/rsync-daemon

Add RC. Local

In various operating systems, RC files are stored in different locations and can be modified so that rsync-daemon is loaded when the system starts.

Add/etc/rc. Local directly here.
/Usr/local/rsync/bin/rsync-Daemon-Port = 873
873 is the default port number of rsync.

Remember to configure the firewall to allow the TCP and UDP protocols of your rsync ports.
873: TCP 873: UDP

Configure the client

In the following command line, the V in vzrtopg is verbose,
Z is compressed transmission,
R is recursive,
Topg is a parameter that maintains the original attributes of a file, such as the owner and time.
U is only used to synchronize updated files to avoid repeated updates to non-updated files. Note the clock synchronization between the two machines.
-Progress indicates the detailed progress,
-Delete: if the server deletes the file, the client also deletes the file to ensure true consistency.
The following rsync_user@192.168.0.2: rsync_module_name1, after rsync_module_name1 is the module name, that is, in/etc/rsyncd. the custom name in Conf. rsync_user is the user name that can be synchronized specified in the specified module.
The last/tmp is the name of the local directory that is backed up.
You can also use the-e SSH parameter to establish an encrypted connection.
You can use-password-file =/password/path/file to specify the password file, so that you can use it in the script without entering the verification password interactively, note that only the owner can read the permission attribute of the password file.

#/Usr/local/rsync/bin/rsync-vzrtopg-progress-delete rsync_user@192.168.0.2: rsync_module_name1/tmp/
Password:
Or you can create a password file.
Because the system crontab is required for execution, the password file is read here,
At this time, it is successful.

# Vi/etc/rsyncd. Pas
Join
Rsync_user: rsyncofpass
Note that the password file on the client only requires a password instead of a user name!

Rsyncofpass

Change file permissions:
# Chmod 0600/etc/rsyncd. Pas

#/Usr/local/rsync/bin/rsync-vzrtopgu-progress-delete-password-file =/etc/rsyncd. Pas rsync_user@192.168.0.2: rsync_module_name1/tmp/
I don't know why. The following authentication errors are always prompted.
@ Error: AUTH failed on module rsync_module_name1
Rsync error: Error starting client-server protocol (Code 5) at main. C (1383) [handler ER = 2.6.9]
I'm depressed. I don't know how to handle it. I also hope that experienced friends can provide me with support...

After entering only the password in the client password file today, it is finally successful.

If you have time to study the authentication issue in the future, it's time-consuming and the task is urgent. You can bypass the verification first.

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.