利用rsync远程同步文件

解决已存在文件等复杂问题

rsync pi@192.168.2.145:/home/pi/2022/2022-03-31/ /home/peter/下载/2022/2022-03-31

对于非22端口,则需重新指定端口才能同步

rsync -aP "-e ssh -p 20123" peter@1.tcp.hk.cpolar.cn:/home/pi/ /Users/Downloads/

如果需要复制特定文件组,也就是需要增加“*”等通配符,此时需要将“”才能正常同步,如下:

rsync -aP "-e ssh -p 20123" "peter@1.tcp.hk.cpolar.cn:/home/pi/2022-03-31*" /Users/Downloads/

网站备份

rsync -aP pi@192.168.0.101:/var/www/ /Users/Downloads/roown.com/
需求:公司有两台备份服务器,一主一从,每天晚上8点开始从服务器就开始同步主服务上的一些数据,但是rsync总会断开连接,尝试了好多方法都没有用,写了个脚本临时解决这个问题,如下
#!/bin/bash
rsync -avzP --timeout=60 -e "ssh -p X" X.X.X.X:/kejiandata/streams/tarena/streams/* /h
zdata/streams/
while ((1 < 100));do
    ps aux | grep /kejiandata/streams/tarena/ | grep rsync | grep timeout
    if [ `echo $?` -eq 1 ];then
        rsync -avzP --timeout=60 -e "ssh -p X" X.X.X.X:/kejiandata/streams/tarena/stre
ams/* /hzdata/streams/
    fi
    sleep 30
    if [ `date +"%H%M"` -ge 0830 ];then
        exit
    fi
done