rsync linxu real-time synchronization of files to windows

rsync linxu real-time synchronization of files to windows

rsync synchronizes data. Data pulling and pushing can only be operated on the client.

That is, you need to execute commands on the client and configure rsyncd on the server Conf file, start rsync.

linxu synchronizes files to windows in real time, so the client is linux and the server is windows.

1, Server windows

1. Download software: cwRsyncServer
Download link: https://files.cnblogs.com/files/yblue/cwRsyncServer_4.1.0_Installer.rar

2. Install cwRsyncServer software
It is recommended to choose the default path for installation. I just started to install disk D, but I never succeeded. Later, the default path was OK.

Default path: C:\Program Files (x86)\ICW.

When installing, there is a user account and password, which is set to be the same as that in your configuration file, that is, the value of auth users and the value of password in secrets file.

(windows Server windows server 2012 r2 will not automatically create users when installing this software. You need to add users to the computer. The password policy is very troublesome. You can see this picture)

3. Modify C: \ program files (x86) \ ICW \ rsyncd Conf configuration file

gid = 0
pid = 0
uid = 0
use chroot = false
strict modes = false
port = 873
max connections = 200
lock file = rsyncd.lock 
log file = /cygdrive/e/rsync_config/rsyncd.logtransfer 
logging = yes
hosts allow = *[server]path = /cygdrive/e/rsync_test_data
auth users = rsync
secrets file = /cygdrive/e/rsync_config/configPwd.passwd
read only = no
list = no

The main parameters are: []: module, path: the path to store data, auth users: virtual users, secrets file: password file, hosts all: the IP allowed to access.

For detailed parameters, please refer to this article: https://www.cnblogs.com/koushuige/p/9162920.html

4. Permission configuration

//jurisdiction
C:\Program Files (x86)\ICW\bin\chmod.exe 600 /cygdrive/e/rsync_config/configPwd.passwd
//owner
C:\Program Files (x86)\ICW\bin\chown.exe rsync /cygdrive/e/rsync_config/configPwd.passwd

Authorizing the user may invalidate the command. I've tried it many times. Go to the file to configure permissions.

4.1 the steps to modify the user authority of password file are as follows:


In this way, rsync users are authorized to add password files.

4.2 it is better to modify the user permissions of the synchronization file
For example, my path = /cygdrive/e/rsync_test_data, no error will be reported if it is not configured on the windows system today, but the error rsync: failed to set times on "will be reported when it is deployed to the Windows Server windows server 2012 r2." (in server): Is a directory (21) rsync.

5. Find RsyncServer in the service and start it

Here, the windows Server Rsync configuration is completed.

2, Client Linxu

1.linxu installation rsync

//Install rsync using yum or up2date
yum install rsync

2. The client only needs to create a password file. The password file only needs a password. The password needs to be consistent with the password file of the server and authorized.

//Create the file rsync.com under etc password
touch /etc/rsync.password
//Write password to password file
echo "123456">/etc/rsync.password
//View password file contents (not required)
cat /etc/rsync.password<br>//Authorization < br > Chmod 600 / etc / Rsync password

3. Real time monitoring with inotify
3.1 download and install inotify

//Download inotify directly. I downloaded it in the / home/tools / folder
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
//decompression
tar xf inotify-tools-3.14.tar.gz
//Enter directory
cd inotify-tools-3.14 
//Specify the parameter configure to set the installation location
./configure --prefix=/usr/local/inotify-tools-3.14
//Check whether the installation is successful
make && make install
echo $?//If it returns 0, enter ls for 127, and then execute echo $?
cd /usr/local/inotify-tools-3.14
//Set character set
LANG=EN

3.2 write inotify real-time monitoring script

//Create the / server/scripts directory and put the general scripts here
mkdir /server/scripts -p
cd /server/scripts
//Modify script file
vim inotify.sh

3.3 content of script

#!/bin/sh
#para 
host01=Server IP
src=Folders that the client needs to synchronize
dst=Server module name
user=Server user name
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify-tools-3.14/

#judge
if [ ! -e "$src" ] \
|| [ ! -e "${rsync_passfile}" ] \
|| [ ! -e "${inotify_home}/bin/inotifywait" ] \
|| [ ! -e "/usr/bin/rsync" ] ;
then
    echo "Check File and Folder"
    exit 9
fi    

${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \
| while read file
       do 
       #rsync  -avzP --delete --timeout=100 --password-file=${rsync_passfile} $src $user@$host01::$dst >/dev/null 2>&1
           cd $src && rsync -aruz -R --delete ./   --timeout=100 $user@$host01::$dst  --password-file=${rsync_passfile} >/dev/null 2>&1  
           done
exit 0

3.4 execute script file

//Test execution script file
sh -x inotify.sh

3.5 let the script run in the background

//View processes starting with inoti
ps -ef|grep inoti
//Killing process xxxx is the process number of all processes starting with inoti
kill xxxx
//Start background running of inotify process
nohup sh /server/scripts/inotify.sh & 

At this point, Linxu is configured.

3, Summary

rsync realizes file synchronization between systems. Data pulling and pushing can only be operated on the client. The key to determining the client depends on the flow direction of your data.

There are many file synchronization between different systems on the Internet. Linux - > linxu, linxu - > windows, windows - > linxu, windows - > window, and two-way synchronization (both sides are regarded as server and client, and both sides are equipped). In fact, they are almost the same.

The steps are as follows:

1: Server configuration
1. Configure Rsync on the server Conf file (refer to the above for details)

2. Permission configuration

Set password folder: full path of chmod 600 password file

Authorize password folder permissions to users: chown username password file full path

Set the storage location of synchronization data path: chmod 600 full path of password file (it is not authorized, and it is best to set permissions, otherwise an error may be reported)

3. Start rsync

windows startup service (Linxu starts rsync: rsync --daemon)

2, Client configuration
1. Configure the password file, which only needs the password of the password file on the server side

2. Permission configuration

Set password folder: full path of chmod 600 password file

3. Even if the command is executed, you can also write a script to run it (refer to the above for details)

3, Logic of troubleshooting
1. Firewall and selinux (remember that it's a local area network. If it's not a local area network, just the domain name. The IP you normally find is assigned by the local route, and the other IP is assigned there)

2. View the log file rsyncd log

3. Check whether there will be errors in the process you deploy

If you want to see more wonderful content, you can pay attention to my blog Garden
My blog Garden

Keywords: Linux rsync

Added by illzz on Wed, 02 Feb 2022 02:28:56 +0200