Rsync synchronizes CODE files between Windows Linux
rsync CODE files between Windows and Linux
I. environment
Windows:
OS:Microsoft Windows Web Server 2008 SP1
IP:192.168.88.197
Linux:
OS:CentOS release 6.4 (Final)
IP:192.168.88.238
II. Install server software and configure it under Windows
1.cwRsyncServer(installation process omitted), note that the installation process will create a user to start the service
Start cwsync
services.msc-Find RsyncServer Change the startup type to automatic and start the service
2. Configure cwrsync
Create synchronization directory
Here I created the directory: E:\sync
Empowering new directories
Right-click the directory sync and select Security Click Edit to add SvcCWRSYNC and grant all permissions
Configure the rsyncd.conf file with the following directory path
C:\Program Files (x86)\ICW
Modify to the following configuration
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[197bak]
path = /cygdrive/e/sync #path needs to be converted to E:\sync
read only = true
list = no
hosts allow=192.168.88.238 #Allow those IPs to synchronize, multiple IPs separated by commas, allow all direct yes *
auth users = qssync #synchronously verify user names
secrets file = etc/rsyncd.secrets #Specify the path to the password file
UID = 0
GID = 0
Create password file
Note that the password file path should be consistent with the rsyncd.conf path
etc/rsyncd.secrets(this path is relative)
The real physical path is C:\Program Files (x86)\ICW\etc
The edit file rsyncd.secrets has the following format
sync:Abc23332c2014
Backup CODE under windows
The BAT script is as follows: backup.bat
@echo off
set p=C:\Program Files\WinRAR
"%p%\rar" a E:\sync\code%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.rar D:\app\code >>rar%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.log
forfiles /p "E:\sync" /d -7 /c "cmd /c echo deleting @file ... && del /f @path" >>rar%date:~,4%%date:~5,2%%date:~8,2%%time:~,2%%time:~3,2%%time:~7,1%.log
3. Linux configuration (here Linux as client)
1. Install Linux client (selinux is recommended to be turned off) and configure
yum install rsync xinetd
configured
[root@zjqs-05 scripts]# vim /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
Change disable from yes to no
Create password file
vim/etc/passwd.txt reads as follows
[root@zjqs-05 scripts]# cat /etc/passwd.txt
Abc23332c2014
The password here is consistent with the server side.
Create synchronization scripts
[root@zjqs-05 scripts]# cat /export/scripts/rsync197.sh
#!/ bin/sh
rsync -vzrtopg --port=873 --progress --delete --exclude-from '/export/scripts/exclude.txt' sync@192.168.88.197::197bak /data/197bak --password-file=/etc/passwd.txt
#exclude-from prevents something that needs to be kept for a long time. synchronous
exclude.txt reads as follows
[root@zjqs-05 scripts]# cat /export/scripts/exclude.txt
bianfeng20140911.bak
bianfeng
Create mission plans
02 02 * * * /export/scripts/rsync197.sh >/export/scripts/rsync`date +%F`.log 2>&1