Use Cwrsync to synchronize "Go" with file timing in Windows

Source: Internet
Author: User

1. Reference documents:

Using Cwrsync to implement scheduled synchronization of files under Windows (Backup)

How to use the File Synchronization tool Cwrsync and the common commands

2. Background:

In the current SCADA architecture, there are 1 server,5 units FE and 1 client units. The schema is as follows:

Although the names are different, their installation files and configuration files are exactly the same. In most cases, it is also recommended that the configuration files on these servers be consistent so that only one version of Config can be maintained, without the need to personalize the config file on each server. This also brings a new problem, whenever I modify the configuration file on a machine, I also need to make the same changes on the other 6 machines, the duplication of work is very much. This resulted in the idea of deploying a set of file synchronization systems that needed to be modified on a single machine, with the other machines automatically timed to synchronize.

3. Solution:

Find some file synchronization program on the net, finally decided to use Cwrsync this software. Cwrsync is a Cygwin platform-based rsync software package that supports Windows-to-Windows, Windows-to-Linux, Linux-efficient file synchronization for Windows. Since Cwrsync has integrated the Cygwin class library, it is possible to save the Cygwin package when installing. Cwrsync also integrates openssh for Windows, enabling the same operation as Rsync under Linux. After using Cwrsync to synchronize files, only one master server is required to make file modification, and other mirror servers can synchronize automatically, including file update, deletion, renaming, etc.

Cwrsync is divided into paid version and free version, we only need to use the free version, on the official website download Cwrsync client version and server version.

Client version: Cwrsync 4.0.5 Installer

Server version: Cwrsyncserver 4.0.5 Installer

4. Installation:

For Cwrsync installation There is nothing to say, all I choose is the default installation, for the server version of the installation, here add a sentence, in the installation process will be prompted to ask us to enter the service account and password, If we do not specify the words will use Svccwrsync This account, the password is generated randomly, so remember this password. However, in the configuration behind me, this service account is not used.

5. Configuration:

The architecture of the Cwrsync is simple, with one server and multiple client components. After installing the server version of Cwrsync, start the Cwrsync service on the server and then execute the file Synchronization command on the client to achieve the file synchronization function. If we add a file synchronization command to a Windows scheduled task, you can implement the ability to define synchronization.

5.1 Server-side configuration

In the Cwrsync installation directory, you can find a rsyncd.conf configuration file, the following I according to their actual business needs to describe the name of the configuration file modification method, in the second section of the background I have already mentioned, I have 1 units server,5 fe,1 Taiwan client. Our SCADA system is installed in the same directory of seven machines, all D:\xxx, and then the config file directory is D:\xxx\config, I want to achieve the goal is: as long as I modify the server this machine config directory, Then the other six machines (5 FE and 1 client) will automatically synchronize the corresponding configuration information.

Below I put my own server-side configuration file, at the bottom of the configuration file, we see the [Config] tab, this is the Config directory we need to synchronize, it is important to note that the name of the file directory changes. We see a line in the configuration file that says "Remember Cygwin naming conventions:c:\work becomes/cygwin/c/work", that is, under Windows System, the directory address is C:\work, In our config file path, we need to modify it to/cygwin/c/work. Similarly, the directory that we currently want to synchronize is D:\xxx\config, so I write Path =/cygdrive/d/xxx/config. The other configurations are configured according to the given template.

Use chroot = falsestrict modes = falsehosts Allow = *log File = rsyncd.logpid File = rsyncd.pid Port = 8173 #默认端口8173 UID = 0 #不指定uid, do not add this line will not be able to use any account gid = 0 #不指定gid max connections = Ten #最大连接数10 # Module definitions# Remember Cygwin naming conv Entions:c:\work Becomes/cygwin/c/work#[config]path =/cygdrive/d/xxx/config #表示文件目录read only = falsetransfer logging = Yeslock File = Rsyncd.lock#auth users = Service-scada #认证用户名 #secrets file = Rsync.password #认证用户的用户名和密码存储位置

After the configuration is complete, we need to start the Cwrsync service next, we set this service to start automatically, as shown in.

Also, in the above we specify Rsyncserver port is 8173, we can netstat-an this command to check whether the 8173 port is listening, as shown in.

5.2 Client Configuration

After installing Cwrsync client, we see the default installation directory is C:\Program Files\cwrsync, we note this installation directory, the following will use this installation directory.

Create a new Notepad on the client and enter the following information in Notepad:

This notepad is then renamed to Config_rsync.bat, which forms a batch file. In the batch file, it is necessary to add the 1th, 2 rows, because when installing the Cwrsync client, the Cwrsync program directory is not added to the path of the environment variable, if you add C:\Program in the environment variable path files\ Cwrsync\bin, you do not need to add the 1th, 2 rows in the batch.

The third line of "Rsync-av rsync://10.138.16.54:8173/config/cygdrive/d/xxx/config" means synchronizing the config file from the server to the local D:\xxx\config directory. Synchronization will be based on the version above the server, if there is a file with the same name on the FE will be replaced.

5.3 Synchronizing files periodically by scheduling task clients

File synchronization or manual operation in front of a batch file can be done later by adding a scheduled task. We add a scheduled task called Rsync_scada, and then specify that its run script is Config_rsync.bat, as shown in:

Set the execution time in the schedule, as shown, so that the Config directory can be synchronized once every 10 minutes.

6. Log View:

For the log of file synchronization, it can only be viewed on a machine with server version Cwrsync installed. The server-side configuration file is mentioned in 5.1, with one line: Log file = Rsyncd.log. We can find rsyncd.log this file in the installation directory, open the file we can see all the records. I'll extract some of the log information below.

View Code7.Windows The Rsync service cannot start a workaround

After the server unexpectedly restarts, the Rsyncserver service cannot start, prompting "the Reyncserver service on the local computer has started and stopped." The method is to remove or rename the Rsyncd.pid file under the installation directory, and then restart the Rsyncserver service, OK, the Rsyncd.pid file will be regenerated automatically.

How to use 8.rsync exclusion directories

requirement Scenario: currently want to synchronize a folder above a server to 5 client, but do not want to synchronize all the files, the individual files do not need to synchronize, so you must add the files in the server's configuration file to exclude synchronization, This requires the use of the exclude parameter. This can be used on the client, or directly on the server configuration. The following example is configured on the server's rsyncd.conf file.

Case: Config file directory has test1, test2 and test3 These three directories, all of these three directories have a test.txt file. The following are different configuration information to achieve different synchronization requirements.

Envision--config--test1--test.txt

|| ——— Test2--test.txt

|| ——— Test3--test.txt

8.1 Exceptions to the Test1 directory through the Exclude keyword
[Config]path =/cygdrive/d/envision/config#exclude from = Rsync.excludeexclude = Test1/read = Falsetransfer Logging = Yeslock file = Rsyncd.lock
8.2 Exceptions to the Test2 and TEST3 directories with the Exclude from keyword
[Config]path =/cygdrive/d/envision/configexclude from = Rsync.exclude#exclude = Test1/read = Falsetransfer Logging = Yeslock file = Rsyncd.lock

Where the Rsync.excluede file is in the same directory as rsyncd.conf, where the file content is, where "/" is very important.

test2/test3/
8.2 The specified file under Exclude directory

Exclude and exclude from are not only restricted to directories, but also to the specified file names.

Add a file test2.txt under the Test1 directory and configure it as follows

[Config]path =/cygdrive/d/envision/configexclude from = Rsync.excludeexclude = Test1/test.txtread = Falsetransfer L ogging = Yeslock File = Rsyncd.lock

Executing the synchronization command again will find that the test1/test2.txt will be synchronized, and the test1/test.txt will not be synchronized.

Use Cwrsync to synchronize "Go" with file timing in Windows

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.