Rsync
通過rsync服務實現windows與linux之間的文件同步
准備
windows
同步工具
- cwRsyncServer_4.1.0_Installer
- 下載地址: https://dl.pconline.com.cn/download/901932-1.html
安裝如下,注意需要填寫一個windows系統的賬號密碼
安裝完成
linux
同步工具
- rsync --version
*若無,請安裝 yum install rsync
定時任務
- service crond status
文件同步
linux作為客戶端定時從windows服務端同步目錄下文件
服務端
- 修改配置文件 rsyncd.conf
uid=0 // 添加
gid=0 // 添加
use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
# Module definitions
# Remember cygwin naming conventions : c:\work becomes /cygwin/c/work
#
[test]
path = /cygdrive/d/rsync_test // 表示D盤目錄下的rsync_test目錄
read only = false
transfer logging = yes
-
修改服務為自啟動; 右鍵服務,並修改登錄的賬號密碼為安裝時的賬號密碼
-
測試服務端
telnet ip 873
客戶端
- 新建一個密碼文件
vi /etc/rsync_pwd
chmod -R 600 rsync_pwd
- 先測試同步命令是否可行
rsync -av --progress --delete --password-file=$pwdfile $user@$source $dest
- 編輯腳本文件 backup_fileserver.sh
#!/bin/bash
PASSWORD=/root/psn_passwd
SOURCE='172.19.82.143::test'
USER=psn
DEST=/rsync_test/
echo "start backup file server"
/usr/bin/rsync -av --progress --delete --password-file=$PASSWORD $USER@$SOURCE $DEST
if [ $? -eq 0 ]
then
echo "file server backup successfully!"
else
echo "file server backup failure, try again:"
/usr/bin/rsync -av --progress --delete --password-file=$PASSWORD $USER@$SOURCE $DEST
fi
- 加入定時任務
crontab -l //查看定時任務
crontab -e //編輯定時任務
*/1 * * * * /bin/bash /home/backup_fileserver.sh > /dev/null 2>&1 // 1分鍾同步一次