使用 Rsync 工具从 Windows 传输数据到 Linux
本文最后更新于 320 天前,如有失效请评论区留言。

前言

Rsync 常用在 Linux 上做文件同步,跟 FTP 和 scp 不同,Rsync 会检查两边的文件差异然后只传输变化的部分。但 Rsync 只能运行在 Linux 上,Windows 上需要部署的是 CwRsync ,CwRsync 可以在 Windows 之间、Windows 和 Linux 之间跨平台同步文件。

步骤如下:

  • 在 Linux 上部署 Rsync 服务端;
  • 在 Windows 上部署 CwRsync 客户端。

环境

Linux 环境

[root@rsync-server ~]# cat /etc/redhat-release 
Rocky Linux release 8.7 (Green Obsidian) #我这里用的是Rocky Linux。

Windows 环境

Windows 版本:Windows 10

Rsync server

在 Linux 上部署 Rsync Server。大部分 Linux 系统安装自带 Rsync,没有的话,可以用 yum 命令直接下载。

[root@rsync-server ~]# yum install -y rsync
[root@rsync-server ~]# rpm -qa | grep rsync
rsync-server3.1.3-20.el8_10.x86_64

创建配置文件 rsyncd.conf。

[root@rsync-server ~]# cat > /etc/rsyncd.conf <<\EOF
uid = root
gid = root
port = 873 #端口可以自定义
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup  # Rsync 协议使用的用户名
secrets file = /etc/rsyncauth.passwd # Rsync 协议使用的密码认证文件
log file = /var/logs/rsyncd.log
hosts allow = *
#####################################

[destination1] # 自定义的资源名
comment = welcome to  backup!
path = /data/destination1 #自定义资源对应服务器上的实际路径

[destination2]
comment = welcome to  backup!
path = /data/destination2
EOF

创建密码认证文件 rsyncauth.passwd

[root@rsync-server ~]# cat >/etc/rsyncauth.passwd <<\EOF
rsync_backup:Cuckooyang@2025!
EOF

[root@rsync-server ~]# chmod 600 /etc/rsyncauth.passwd

用 systemctl 管理 Rsync 服务

[root@rsync-server ~]# cat > /etc/sysconfig/rsyncd <<\EOF
OPTIONS=""
EOF

[root@rsync-server ~]# cat > /lib/systemd/system/rsyncd.service <<\EOF
[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf
[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS"
[Install]
WantedBy=multi-user.target
EOF

加入开机启动项

[root@rsync-server ~]# systemctl enable --now rsyncd
[root@rsync-server ~]# systemctl status rsyncd

CwRsync Client

在 Windows 上部署 CwRsync Client 。

打开官网:https://www.itefix.net/cwrsync/client 

image-20250214163944679

我这里下载的是 cwrsync_6.4.0_x64_free.zip 版本。在 Windows 上解压为C:\tools\cwrsync。

image-20250214164202787

将 CwRsync 的 bin 目录添加到 Windows 系统环境变量中。

image-20250214165146602

创建密码文件 zdlt_passwd.txt (名字自定义),填入 Rsync 服务端设置的密码 Cuckooyang@2025!

image-20250214165703677

创建 Windows 可执行文件 rsync.bat,填入 rsync 同步文件的命令。

@echo off
rsync.exe -avPz --port 873 --password-file=C:\tools\cwrsync\bin\zdlt_passwd.txt  /cygdrive/D/destination1/*  rsync_backup@192.168.200.200::destination1/

双击 rsync.bat 查看执行效果。

如果需要定时同步文件,只需要把 rsync.bat 加入 Windows 定时任务启动项就可以了。

版权声明:除特殊说明,博客文章均为cuckooyang原创,依据CC BY-SA 4.0许可证进行授权,转载请附上出处链接及本声明。 | 博客订阅:RSS | 广告招租:留言板 | 博客VPS |
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇