Skip to content

rsync-linux-to-win

实战:从linux同步数据到winodws(增量定时同步)-2023.11.3(测试成功)

目录

[toc]

环境

bash
linux服务器:centos7.9.2009(rsync version3.1.2)win10(cwRsync_4.1.0_Installer.exe)

软件

链接:https:[root@hexo-blog ~]# cp /etc/rsyncd.conf /tmp/[root@mkdocs-server html]# vim /etc/rsyncd.conf# /etc/rsyncd:configuration file for rsync daemon mode# See rsyncd.conf man page for more options.# 进行通信的端口,如果 firewall 打开的话,需要将对应的端口添加进去port=8730# 日志文件logfile=/var/log/rsync.log# rsync 的进程 idpidfile=/var/run/rsync.pid##编辑[cmi-MdImages]# 同步的目标文件夹path=/test/# rsync daemon 在传输前是否切换到指定的 path 目录下,并将其监禁在内,用于增加传输的安全性usechroot=no# 指定最大的连接数maxconnections=4# yes 表示只读本地文件无法同步到服务器readonly=no# 客户端请求显示模块列表时,该模块是否显示出来list=true# 服务运行时的用户uid=root# 服务运行时的用户组gid=root# 进行验证时的用户名,必须是系统存在的用户authusers=root# 连接用户时的密码secretsfile=/etc/rsyncd.passwd# 允许的 iphostsallow=*

重启rsync服务:

2、验证

  • 云服务器上,创建测试文件
bash
[root@hexo-blog ~]# mkdir /test[root@hexo-blog ~]# echo test >/test/1.txt[root@hexo-blog ~]# ll /test/1.txt -rw-r--r--1rootroot5Nov3005:44/test/1.txt
  • 开始同步数据:
bash
rsync.exe-avPzruh--delete--port8730--password-file=/cygdrive/D/password.txtroot@47.97.48.237::cmi-MdImages//cygdrive/D/cmi-MdImages-local

  • 报错了:。。。

虽然报错了,但是文件还是被同步下来了哦。(完美。)

3、配置windows定时任务

1、新建D:\rsyncMdImages.bat文件,填入以下内容

bat
rsync.exe -avPzruh --port 8730--password-file=/cygdrive/D/password.txt root@47.97.48.237::cmi-MdImages/ /cygdrive/D/BaiduSyncdisk/cmi-MdImages-local

将该文件另存为rysnc.bat文件,编码为ANSI

注:如果编码为utf8,文本中的中文会出现乱码导致执行出错。

2、开启定时任务

批处理完成了,怎么来实现周期性的运行该脚本呢?windows自带了非常强大的定时任务功能。进入计算机管理(此电脑右键“管理”),在系统工具->任务计划程序->任务计划程序库中能看到你电脑所有的定时任务,右键可以创建基本任务。 (或者直接在cmd输入compmgmt.msc

按图中输入名称及描述,点击下一步设置触发器(任务触发时间)

点击下一步设置任务执行操作,这里选择启动程序

选择刚才制作的bat脚本,点击下一步

点击完成创建任务

选择刚创建的任务,右键点击属性打开属性对话框,点击触发器并双击已设置的触发器设置任务重复执行

点击确定完成定时任务设置,右击任务启动任务。

参考

https:t="1711730357270" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4392" width="16" height="16" >打赏支持