Use cwRsync to synchronize and back up files between windows Servers

Source: Internet
Author: User
Tags file size relative file permissions rsync

Use cwRsync for synchronization. Because windows does not have the inotify function, it can only implement regular synchronization. I actually use synchronization once every minute (considering that the upload speed is much lower than the intranet's 1 GB network speed, this solution is feasible ). The specific implementation process is as follows:

1. Software preparation:
Client version: cwRsync 4.0.5 Installer (the latest version is 5.22. Select as needed)

Server version: cwRsyncServer 4.0.5 Installer (the latest version is 5.22. Select as needed)

2. Installation:
Install cwRsyncServer on APP1 (defined as the master server). The installation of software in Windows is very simple. When installing cwRsync, you only need to remember the following Password. Other default values:

Install the cwRsync client version on app2. All are the default values.

3. Configuration:
3.1 Server configuration
In the installation directory of cwRsync (default path: C: Program Files (x86) ICW), you can find a configuration file of rsyncd. conf, back up one file, and then modify it.

The code is as follows: Copy code

Use chroot = false

Strict modes = false

Hosts allow = *

Log file = rsyncd. log

Uid = 0 # specify uid as 0.

Gid = 0

# Define the path to be synchronized with any name, so you can easily identify it yourself

[Bbsapp]

Path =/cygdrive/d/APPSYSTEM/bbs/# indicates path: d: \ APPSYSTEMbbs

Read only = false

Ignore errors

Transfer logging = yes

Hosts allow = 192.168.18.0/255.255.255.0

Auth users = SvcCWRSYNC # authentication account, the account used for installation

Secrets file = rsync. password # password file

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

The code is as follows: Copy code

SvcCWRSYNC: pw123456

Note: The preceding account name is prior to the colon, and the password prompted during installation can also be specified during installation.

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

3.2 Client configuration

Enter the default installation directory C: Program Files (x86) cwRsync on the client, create a new password file rsync. password, and write the above user password to this file (only the password ). Note that the permission of the file must be owned by the administrator and the permission is 600 (that is, only the administrator has the permission). Otherwise, the following error will be reported during synchronization:

The code is as follows: Copy code

Password file must be owned by root when running as root

Create a batch processing job in any location. The Command content is as follows:

The code is as follows: Copy code

Cd/d "C: Program Files (x86) cwRsyncbin"

Rsync-avz -- delete-after -- ignore-errors -- progress -- password-file = "/cygdrive/c/Program Files (x86)/cwRsync/rsync. password "SvcCWRSYNC @ Appenders IP: bbsapp/cygdrive/d/APPSYSTEM/bbs

Call this batch in a scheduled task and set it to once per minute.

4. cwRsync client commands:
-V, -- verbose detailed mode output

-Q, -- quiet simplified output mode

-C, -- checksum: enable the verification switch to force file transfer verification

-A, -- archive mode, indicating that the file is transmitted recursively and all file attributes are kept, equal to-rlptgoD.

-R, -- recursive processes subdirectories in recursive mode

-R, -- relative uses relative path information

-B, -- backup creates a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes.

-- Backup-dir: backs up files (for example ~ Filename) is stored in the directory.

-Suffix = SUFFIX defines the backup file prefix.

-U, -- update only performs updates, that is, skipping all files that already exist in DST and whose file time is later than the time to be backed up. (Do not overwrite the updated file)

-L, -- links retains soft links

-L, -- copy-links: Process soft links like regular files

-- Copy-unsafe-links: only copies links other than the SRC path directory tree.

-- Safe-links ignores links other than the SRC path directory tree

-H, -- hard-links

-P, -- perms to keep file permissions

-O, -- owner keeps file owner information

-G, -- group: Keep file group information

-D, -- devices: Keep device file information

-T, -- times preserve the file time information

-S, -- sparse performs special processing on sparse files to save DST space

-N, -- dry-run which files will be transmitted

-W, -- whole-file: Copy files without incremental detection

-X, -- one-file-system do not span the boundaries of the file system

-B, -- block-size = SIZE indicates the block size used by the algorithm. The default value is 700 bytes.

-E, -- rsh = COMMAND specifies that rsh and ssh are used for data synchronization.

-- Rsync-path = PATH specifies the path of the rsync command on the remote server

-C, -- cvs-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted

-- Existing only updates the files that already exist in DST, instead of backing up the new files.

-- Delete: delete the files that are not in the SRC file in DST.

-- Delete-excluded: delete files specified by this option at the receiving end.

-- Delete-after: delete after transmission

-- Ignore-errors is deleted when an IO error occurs in a timely manner.

-- Max-delete = NUM: a maximum of NUM files can be deleted.

-- Partial retains the files that are not completely transferred for any reason, so as to speed up subsequent re-transmission.

-- Force directory deletion, even if not empty

-- Numeric-ids does not match the number user and group ID with the user name and group name.

-- Timeout = time ip timeout, in seconds

-I, -- ignore-times do not skip files with the same time and length

-- Size-only: when determining whether to back up a file, only check the file size, regardless of the file Time

-- Modify-window = NUM determines whether the timestamp window of the file is used at the same time. The default value is 0.

-T -- temp-dir = DIR create a temporary file in DIR

-- Compare-dest = DIR: compare the files in DIR to determine whether to back up data.

-P is equivalent to -- partial

-- Progress displays the backup process

-Z, -- compress compresses backup files during transmission

-- Exclude = PATTERN specifies to exclude file modes that do not need to be transmitted

-- Include = PATTERN specifies the file mode to be transmitted without exclusion

-- Exclude-from = FILE: exclude files in the specified mode in the FILE.

-- Include-from = FILE: files with the specified FILE pattern matching are not excluded.

-- Version: prints version information.

-- Address: bind to a specific address

-- Config = FILE: specify other configuration files. The default rsyncd. conf FILE is not used.

-- Port = PORT specify other rsync service ports

-- Blocking-io: Block IO for remote shell

-Stats indicates the transmission status of some files.

-- SS actual transmission process during transmission

-- Log-format = formAT specifies the log file format

-- Password-file = FILE get password from FILE

-- Bwlimit = KBPS limits I/O bandwidth, KBytes per second

-H, -- help: displays help information

5. Question points:
5.1 service cannot be started:
After the server is accidentally restarted, the RsyncServer service cannot be started, and the system prompts "the reyncserver service on the local computer is stopped again after it is started" by running the rsyncd in the installation directory. you can delete or rename the pid file and restart the RsyncServer service. OK. rsyncd is successful. the pid file is automatically regenerated.

5.2 The Message "password file must be owned by root when running as root" is displayed"
When the client uses command synchronization, the above error is prompted because the password file has incorrect permissions. The file owner (owner) must be administrator and the permission is 600 (that is, only the administrator has permissions ).

6. Exclude
On the two servers, some cached directories or temporary files and specific configurations may not need to be synchronized, so you need to exclude them. Therefore, you must add the excluded synchronization file to the server configuration file, which requires the exclude parameter.

6.1 directory exclusion
The exclude parameter can be used on the client or configured directly on the server. The following example is configured on the rsyncd. conf file of the server.

Case: The configfile directory contains three directories: test1、test2and test3. each of these three directories has a test.txt file. The following uses different configuration information to implement different synchronization requirements.

ENVISION--config--test1--test.txt

| ---Test2--test.txt

| ---Test3--test.txt

Use the exclude keyword to implement exceptions in the test1 Directory

The code is as follows: Copy code

[Config]
Path
=/Cygdrive/d/ENVISION/

Config
# Exclude
From =

Rsync. exclude
Exclude
= Test1/read only = falsetransfer logging = yeslock file = rsyncd. lock

Use the exclude from keyword to implement exceptions in the test2 and test3 directories.

The code is as follows: Copy code

[Config]
Path
=/Cygdrive/d/ENVISION/

Config
Exclude
From =

Rsync. exclude
# Exclude
= Test1/read only = falsetransfer logging = yeslock file = rsyncd. lock

The rsync. excluede file and rsyncd. conf file are in the same directory. The file content is, and "/" is very important.

Test2/test3/
6.2 File exclusion
Exclude and exclude from refer not only to restrictions and directories, but also to specified file names.

Upload a file test2.txt in the test1directory and configure the file as follows:

The code is as follows: Copy code

[Config]
Path
=/Cygdrive/d/ENVISION/

Config
Exclude
From =

Rsync. exclude
Exclude
= Test1/

Test.txt
Read only
= Falsetransfer logging = yeslock file = rsyncd. lock

Execute the synchronization command again and we will find that test1/test2.txt will be synchronized, while test1/test.txt will not be synchronized. Well, if we want to implement automatic synchronization, we also need to make the following scheduled task:

The following describes how to create a scheduled task and execute a scheduled synchronization graph through the "task plan" in windows. The previous section describes the estimation of commands that some friends will do.

First, click "control panel"> "task plan"> "add task plan" on the client's machine, and click "next" in the corresponding pop-up window, click "browse" in the navigation window, as shown below, and select the previously created batch file "dnt_sync.bat ":
        
At this time, the system will display the following window prompts the execution method of the current scheduled task. Here I select to execute the task every day (once ):
     
Here, the system will create a task plan named dnt_sync, and prompt the start time of the task in the following window:
    
 
Do not make any changes here. Click next, and then perform identity authentication (usually the administrator). The task is scheduled to run smoothly. You must have sufficient permissions to complete the task :)
    
Click finish to create a task plan. However, it is executed by day. What should we do if we want it to be executed once every minute? In fact, it is very simple. Just click the newly created task plan with the mouse, select "properties" in the pop-up menu. In the displayed window, click "Advanced" in "schedule", as shown below:
    
 
In this case, a subwindow named "advanced plan options" is displayed, and the following settings are made for others:
    
At this point, the scheduled task will run 24 hours a day and synchronize the two previous folders every minute.
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.