File synchronization based on cwRsync under Windows

  
 

How to achieve user callback retention?

You can use both session sharing and session keeping.

How to achieve user upload files can be accessed on multiple servers?

You can use shared storage (such as NFS, iSCSI, GFS2, etc.) or file synchronization (rsync+sersync+inotify).

Under the IIS+.Net platform, the same two problems are faced. The issue of Session sharing under IIS has been discussed in the previous article. Today's discussion of the second how to achieve access to multiple servers is the same data.

The logical architecture of the site is as follows:


Architecture Description:

The front-end load balancing is scheduled on the scheduling method, if the Request Method is Post , then dispatched to APP1, while other requests are scheduled based on methods such as least connection. This realizes that the user upload always accesses APP1, and the data of APP2 is completely synchronized with APP1.

Sync using cwRsync implementation. Since windows does not have inotify function, it can only achieve timing synchronization. In practice, I use synchronization every minute (considering that the user upload speed is actually much lower than the internal network 1GB network speed, so this scheme is feasible). The specific implementation process is as follows:

1, software preparation:

client version: cwRsync 4.0.5 Installer (latest version 5.22, select as needed)

Server version: cwRsyncServer 4.0.5 Installer (latest version 5.22, select as needed)

2, installation:

Install cwRsyncServer on APP1 (temporarily defined as the primary server); Windows
The installation of the software is very simple. When installing cwRsync, just remember the following password. Other defaults:


Install the cwRsync client version on APP2. The same is true by default.

3, configuration:

3.1, server-side configuration

in the cwRsync installation directory (default path: C:\\Program Files (x86)\\ICW), can Find a rsyncd.conf configuration file, back up one, and then modify it.

use chroot = false

strict modes = false

hosts allow = *

log file = rsyncd.log

uid = 0 ##Specifies that uid is 0. If you do not specify it, you will not be able to use it.

gid = 0

#Define the path you need to synchronize. The name is arbitrary, so you can identify it yourself

[ ,null,null,3],Bbsapp]

path = /cygdrive/d/APPSYSTEM/bbs/#表示路径:d:\\APPSYSTEM\\bbs

read only = false

ignore errors

transfer logging = yes

hosts allow = 192.168.18.0/255.255.255.0

auth users = SvcCWRSYNC #认证 account, the account at the time of installation

secrets file = rsync.password #密码文件

Create a password file rsync.password in the above installation directory, the content is as follows:

SvcCWRSYNC:pw123456

Description: The colon is in front of the above The account name, followed by the colon, is the password that was prompted during installation, and can also be specified during installation.

After configuration is complete, you can restart the cwRsync service, as follows:


3.2, client configuration

Enter the default installation directory of the client C: \\Program Files (x86)\\cwRsync, create a new password file rsync.password, and write the above user's password to this file (just the password). Note that the permissions of the file must be owner and the permissions are 600 (that is, only the administrator has permission), otherwise the following error will be reported when synchronizing:

password file must be owned by root when running as root< Br>

Then create a batch at any location, the command content is as follows:

cd /d "C:\\Program Files (x86)\\cwRsync\\bin"

rsync - Avz --delete-after --ignore-errors --progress --password-file=”/cygdrive/c/Program Files (x86)/cwRsync/rsync.password” SvcCWRSYNC@app1_IP::bbsapp /cygdrive/d/APPSYSTEM/bbs

Invoke this batch in the scheduled task and set it to once every minute.

4, cwRsync client command details:

-v, --verbose Detailed mode output

-q, --quiet Reduced output mode

-c, --checksum Turns on the checksum to force the file transfer to be checked

-a, --archive Archive mode, which means that the file is recursively transferred and keeps all file attributes equal to -rlptgoD< Br>

-r, --recursive Treats subdirectories in recursive mode

-R, --relative Use relative path information

-b, --backup to create backups, also Just rename the old file to ~filename when the same file name already exists for the purpose. You can use the --suffix option to specify a different backup file prefix.

--backup-dir Store backup files (such as ~filename) in the directory.

-suffix=SUFFIX Define backup file prefix

-u, --update Just update, that is, skip all files that already exist in DST and the file time is later than the file to be backed up. (Do not overwrite updated files)

-l, --links Retain soft links

-L, --copy-links Treat soft links like regular files

--copy-unsafe-links Just copy the link to the SRC path directory tree

--safe-links Ignore the link to the SRC path directory tree

-H, --hard-links Retain hard links

-p, --perms Keep file permissions

-o, --owner Keep file owner information

-g, --group keep file group information

-D, --devices keep device file information

-t, --times keep file time information

-S, - -sparse Special processing of sparse files to save space in DST

-n, --dry-run What files will be transferred

-W, --whole-file Copy files, Do not perform incremental detection

-x, --one-file-system Do not cross file system boundaries

-B, --block-size=SIZE Check the block size used by the algorithm, default Is 700 bytes

-e, --rsh=COMMAND Specifies to use rsh, ssh for data synchronization

--rsync-path=PATH Specifies the path of the rsync command on the remote server.

-C, --cvs-exclude Automatically ignore files in the same way as CVS, to exclude files that you don't want to transfer

--existing Update only those files that already exist in DST, not back up those Newly created files

--delete Delete files that are not available in SRC in DST

--delete-excluded Also delete files on the receiving end that are excluded by this option

--delete-after Delete after transfer

--ignore-errors Timely IO error is also deleted

--max-delete=NUM Delete up to NUM files

--partial keeps files that have not been completely transferred for some reason, so speed up subsequent retransmissions

--force Forces deletion of directories, even if not empty

--numeric-ids Do not match the user and group ID of the number to the username and group name

--timeout=TIME IP timeout in seconds

Copyright © Windows knowledge All Rights Reserved