当前位置: 移动技术网 > 科技>操作系统>windows > 通过WSL使用rsync同步本文件

通过WSL使用rsync同步本文件

2019年05月18日  | 移动技术网科技  | 我要评论

农村致富路,人偶师的痕迹,马超群干爹是谁

1、安装wls

主要参考windows10上使用linux子系统(wsl)这篇文章进行安装,不要通过lxrun /install /y去安装,这种方法安装貌似没有wsl命令。

先把win 10 版本升级到16215.0以上,否则在microsoft store里的所有linux都会显示免费下载为不可点击,升级win 10参考download windows 10即可。

如在microsoft store里选择ubuntu,安装完启动并设置用户密码便可使用。

installing, this may take a few minutes...
please create a default unix user account. the username does not need to match your windows username.
for more information visit: https://aka.ms/wslusers
enter new unix username: sandwich
enter new unix password:
retype new unix password:
passwd: password updated successfully
installation successful!

2、rsync

配置rsync,/home/sandwich/rsyncd/rsyncd.conf中加入以下内容:

log file = /home/sandwich/rsyncd/rsyncd.log
port = 8730
use chroot = false
read only = false

[windows_project_rsync_path]
path = /home/sandwich/rsyncd/dest

通过以下命令即可启动rsync

rsync --daemon --config=/home/sandwich/rsyncd/rsyncd.conf --no-detach

测试rsync同步

c:\users\sandwich>wsl rsync --port=8730  -rlptdvzhs --progress --delete /home/sandwich/rsyncd/source/ sandwich@127.0.0.1::windows_project_rsync_path
sending incremental file list
./
a.txt
              5 100%    0.00kb/s    0:00:00 (xfr#1, to-chk=0/2)

sent 118 bytes  received 42 bytes  320.00 bytes/sec
total size is 5  speedup is 0.03

3、脚本修改

删除32位的python,参考安装python 64位,32位无法通过shell_command调用wsl。

重新mysql-python参考windows 10安装python 2.7和mysql-python

添加方法rsyncfiles用于同步,替换原来的copyfiles方法:

def rsyncfiles(source, target):
    source_path = wsl_project_rsync_path + source + "/"
    target_path = "sandwich@127.0.0.1::" + windows_project_rsync_path + target
    shell_command("wsl rsync --port=8730  -rlptdvzhs --progress --delete " + source_path + " " + target_path)

4. 参考

windows10上使用linux子系统(wsl)

download windows 10

[python subprocess.call() cannot find windows bash.exe](https://stackoverflow.com/questions/39812882/python-subprocess-call-cannot-find-windows-bash-exe)

windows and ubuntu interoperability

windows 10安装python 2.7和mysql-python

解决"pip fatal error in launcher: unable to create process using ... "的错误

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网