Use cwrsync between multiple Windows hosts to synchronize/back up/transfer files

Source: Internet
Author: User
Tags rsync

Note: Please indicate the source for reprinting and ensure the integrity of the article.

 

 

If you have multiple computers and want their directories to be consistent (for example, you often change the directories of files), If you manually copy and paste the files, it is too inefficient. If there are too many folders, you will be exhausted. Therefore, it is extremely important to use some synchronization software.

Here, we recommend rsync. Explanation on the Internet: Rsync is a widely used file transfer and synchronization program on Linux and UNIX. This software is quite powerful, and after some configuration, it can make it extremely simple and easy for you to synchronize backups from now on. This software is available in a Windows version calledCwrsync. The official explanation is: cwrsync-rsync for Windows.

 

Download Page:Http://www.itefix.no/i2/download

You need to install cwrsync's server software cwrsyncserver on one computer and cwrsync's client software on another computer. However, because the server software already contains the functions of the client software, in my actual use, I have installed server software on multiple computers (the software is only a few MB, it doesn't matter). I think this is more convenient, because any of my computers can be used as rsync servers.

 

During cwrsyncserver installation, you are required to set a user name and password. We recommend that you change the password instead of using the default password. The user name and password you provide will create an account in the System user (you can see it in the Windows logon interface ).

Since the rsync server is started in the form of a service in Windows, you should check whether your rsync service has been started before using it. The system service name corresponding to the cwrsyncserver software is rsyncserver, which is not automatically started by default.

 

The following describes how to set up rsync servers and clients so that they can synchronize files in a directory.

 

Rsync is from Linux/Unix, so even cwrsync in Windows is quite like rsync in Linux. This style is reflected in that you still need to modify the configuration file (a text file) to set the rsync server, but there is no graphical interface for you to solve the problem with a few clicks.

 

Use NotePad to open rsyncd under the cwrsyncserver installation directory. CONF file (this file is the configuration file of the rsync server), which defines the parameters of the rsync server. When the service starts, it reads the file and initializes the rsync service. If you modify the parameters, You need to restart the service to take effect.

 

The rsyncd. conf file already has some default content. You can add the required parameters by referring to the following format (excluding the horizontal line:

 

Port = 873# Rsync service port (873 is the default port, you can change it)
Use chroot = false# Default, unchanged
Strict modes = false# Default, unchanged
Read Only = Yes# Server File Read-Only (client modification or deletion not allowed)
List = No# The client-to-Server File List is not allowed
Hosts allow = *# List of IP addresses of the clients allowed to connect to the server (* indicates no restriction)
Max connections = 10# Maximum number of connections

Uid = 0# This is very important for some occasions. I will explain it later.
Gid = 0# This is very important for some occasions. I will explain it later.

Auth users = ruser# Username of the server to be connected
Secrets file = rsyncd. Secrets# The format of account files allowed to connect to the server is described below
Motd file = rsyncd. motd# Welcome information file (when the client connects, the service will send a welcome message to the client, its content is the content of this file)
Log File = rsyncd. Log# Log files
Lock file = rsyncd. Lock# Lock files
Transfer logging = Yes# Logs recorded during transmission

# Module Definitions
# Remember cygwin naming conventions: C:/work becomes/cygwin/C/work
#

[Test]# The name of a module, which can be customized but meaningful
Path =/cygdrive/D/test# Path of the synchronized directory, where disk D is"/Cygdrive/d", So this path refers to the test directory under disk D.

 

[Another]

Path =/cygdrive/e/Documents ents and settings/another

 

 

 

Notes:

(1) The rsync server port you set must be opened in the firewall; otherwise, the client cannot be connected.

(2) rsyncd. in the conf file, the upper part of the module is a public parameter, that is, the parameters shared by all modules. If different values are set for this parameter in the module, it is calculated based on the internal values of the module.

(3) The content format of the rsyncd. Secrets file is as follows:

User name: Password

For example:

Ruser: rupass

(4) In general, If You Want To synchronize a directory, you need to add a "module" in rsyncd. conf and set parameters such as paths for the module.

(5) When the client connects to the rsync server, it prompts that chdir fails, and your logon username and password are set correctly, then you probably need to add the above "uid = 0" and "gid = 0", and I used this to solve the problem.

(6) The module path can contain spaces.

 

 

All right, the settings on the server are basically complete, and then you can start the rsync service.

 

Next we will perform the client's work to complete the synchronization task.

As mentioned above, I have also installed cwrsyncserver on the client because it contains the functions of the client.

On the client, we need to execute a command with many parameters under the command line to complete the synchronization function. Because of this, it is impossible for me, run cmd to open the command line, and then run the long rsync command to complete synchronization. Otherwise, it would be too painful. Therefore, we can write a batch processing file (*. BAT) to complete this task. The content of the batch file is actually quite simple:

 

 

 

Cd d:/ICW/bin
D:

Rsync.exe-ravz -- Progress -- password-file =/cygdrive/f/rsync/pass_file ruser@192.168.1.100: Test // cygdrive/"d/program files/test"

 

 

Rsync.exe-ravz -- Progress -- password-file =/cygdrive/f/rsync/pass_file ruser@192.168.1.100: Another // cygdrive/"E/another"

 

 

Pause

 

 

 

Note:

(1) The first line indicates that the directory where the rsync program is located should be changed as needed.

(2) The second line indicates switching to the D disk (the disk where the rsync program is located ).

(3) 192.168.1.100 is the IP address of the rsync server. Change it as needed.

(4) -- password-file parameter specifies the password file of the account used when the client logs on to the server. For example, the above "/cygdrive/f/rsync/pass_file" indicates that it is F: /rsync/pass_file. The file contains the password of the account used to log on to the rsync server.

(5) The red text specifies the module name set in the rsync server configuration file, which must be consistent.

(6) If multiple directories need to be synchronized, write multiple rsync commands. When you double-click this batch of files, they will be executed in sequence.

(7) The first rsync command in the preceding example means to synchronize the directory specified by the test module in the remote rsync server to the local D/program files/test directory. On the client side, if the path contains spaces, enclose the path with double quotation marks (as shown in the preceding example ).

 

 

After the configuration is completed, double-click the batch file to synchronize the two directories. In the future, you will no longer need to manually Synchronize files. Rsync will automatically determine which files have been modified and which have not been modified, only modified files are transmitted (and incremental transmission is also performed), which saves your bandwidth and is extremely efficient.

 

Rsync is not generally powerful. For more configuration options of rsync, it is absolutely impossible to describe it here. Please refer to its manual.

 

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.