Rotten mud: synchronization of Linux and windows files, rotten mud linux

Source: Internet
Author: User

Rotten mud: synchronization of Linux and windows files, rotten mud linux

This article was sponsored by Xiuyi linfeng and first launched in the dark world.

In the previous article, we introduced file synchronization between Linux systems. This article describes file synchronization between Linux and windows systems and between windows and windows systems.

This article is divided into three parts:

1. Synchronize files from windows to Linux

2. Synchronize files from Linux to windows

3. file synchronization between windows and windows systems

1. Synchronize files from windows to Linux

To synchronize files in windows to Linux, We need to install rsync's windows client cwRsync.

CwRsync can be downloaded through the following connection:

Https://www.itefix.net/cwrsync

Of course, we can also download the cwRsync5.4.1 client through this connection.

Currently, the cwRsync version is 5.4.1. After downloading and unzipping the configuration, you can use it normally. As follows:

Note: In the cwrsync. cmd file shown in the figure, you can double-click the file to configure cwRsync or configure it yourself. However, I have verified that the file cannot be successfully configured with cwRsync, so we recommend that you manually configure it.

In fact, the configuration is to add the path of cwRsync to the environment variable of the system.

The manual configuration is as follows:

We can see that the rsync client cwRsync has been installed.

Note: The rsync client configuration in windows is the same as that in Linux, but there are differences in the path.

Configure the rsync client and create the rsync password file as follows:

The configuration of rsync server is the same as the article "mud: rsync learning for linux file synchronization (I.

Our current requirement is to synchronize the files in the E: \ www folder of the rsync client to the rsync server.

The rsync server is 192.168.199.247, And the rsync client is 192.168.199.245.

The rsync server is running normally. The configuration file is as follows:

All of the following operations are performed on the rsync client. Execute the following command:

Rsync-avz -- delete -- progress/cygdrive/e/www apache@192.168.199.247: www -- password-file =/cygdrive/e/rsyncd. password

Note: In the preceding command line,/cygdrive/e/indicates the edisk of the windows system,/cygdrive/e/rsyncd. password indicates the rsyncd. password File of the edisk..

We can see that files in windows have been synchronized to Linux.

However, the disadvantage of this synchronization is that it cannot be synchronized in real time. windows does not support inotify as it does in Linux.

However, we can use the task plan provided by windows to allow the system to perform synchronization on its own. Although there is still a time difference between this and the server, it is always better.

We can write the preceding command to a batch file and configure it in the task plan. As follows:

Ii. Synchronize files from Linux to windows

To synchronize Linux Files to OSS, We need to configure the rsync server on windows to install cwRsyncserver.

The free version of cwRsyncserver on the network is 4.1.0. You can download cwRsync_server4.1.0 through this connection.

After the cwRsyncServer is downloaded, install it. Note that the following prompt appears during installation:

In this dialog box, enter the user name and password of the cwRsyncServer to create a user in the system.

After cwRsyncServer is installed, we can see the rsync service in the windows service. As follows:

After rsyncserver is installed, configure rsyncserver. The configuration of rsyncserver in windows is not much different from that of rsync in Linux.

After rsyncserver is installed, the configuration file is generated. We can see it in its installation directory. As follows:

Now we can modify the rsync configuration file rsyncd. conf as follows:

Use chroot = false

Strict modes = false

Hosts allow = *

Log file = rsyncd. log

[Www]

Path =/cygdrive/e/www/

Ignore errors

Read only = no

List = no

Hosts allow = 192.168.199.0/255.255.255.0

Auth users = apache

Secrets file =/cygdrive/e/rsyncd. password

After the configuration file rsyncd. conf is modified, create a synchronization folder for the www module, as shown below:

Note: After the synchronization folder is created, make sure that the user we created when installing rsyncserver has full ownership of the folder. As follows:

After the synchronization folder is created, we will create the password file for synchronization as follows:

Note: After the file is created, you must use the chmod command to modify its permissions. This is the same as that in Linux.

The chmod command is in the bin directory of rsyncserver and can be directly used. As follows:

If the chmod command is not used for modification, the following error message is returned:

Chmod 600 rsyncd. password

After all the preceding modifications and configurations are complete, we can start rsyncserver as follows:

Now, on the Linux machine, check whether the connection is normal. rsync server. As follows:

We can see that the Linux machine can connect to the rsync server normally.

Now we start to synchronize data on the rsync client, as shown below:

Rsync-avz/www/apache@192.168.199.245: www -- password-file =/etc/rsyncd. password

Switch to the rsync server and check whether the data is synchronized. As follows:

You can see that the file has been synchronized to the windows System in Linux.

Because the rsync client is a Linux system, we can also synchronize Linux Files to windows in real time.

The synchronization script is as follows:

#! /Bin/bash

Src =/root/www/

Dest = www

Ip = 192.168.199.247

/Usr/bin/inotifywait-mrq -- timefmt '% d/% m/% y % H: % m' -- format' % T % w % F'-e modify, delete, create, attrib $ src | while read date time dir file;

Do

Filechange =$ {DIR }$ {FILE}

/Usr/bin/rsync-avz -- delete -- progress $ src apache @ $ ip: $ dest -- password-file =/etc/rsyncd. password &

Echo "At $ {TIME} on $ {DATE}, file $ filechange was backed up via rsynce">/tmp/rsync. log 2> & 1

Done

III,WindowsFile synchronization with windows systems

For file synchronization between windows and windows systems, you only need to install the corresponding rsync client and server on windows systems.

Rsync server 192.168.199.245 and rsync client 192.168.199.244.

If the rsync client is in windows, we need to modify the rsync server. Otherwise, an error is reported. The error message is as follows:

We need to add uid and gid to the rsyncd. conf configuration file, as follows:

Restart rsyncserver.

The rsync client tests the rsync server as follows:

Telnet 192.168.199.245 873

After the client has created the password file, we can synchronize it. As follows:

Rsync-avz/cygdrive/e/soft apache@192.168.199.245: www -- password-file =/cygdrive/e/rsyncd. password

After the synchronization is complete, switch to the rsync server to view the information as follows:

We can see that the rsync client has indeed synchronized the file to the rsync server.

Note: when you are in the same step, the system always prompts you to enter the password, even if you add the password file to the rsync command.

.

The content of the passwd.txt file is exactly the same as that of the rsyncd. password File. As follows:

Use the following synchronization command to synchronize data:

Rsync-avz/cygdrive/e/soft apache@192.168.199.245: www -- password-file =/cygdrive/e/rsyncd. password <E: \ passwd.txt

Note: Real-time file synchronization cannot be implemented between windows and windows. We can only implement scheduled synchronization tasks through task scheduling.

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.