Rsync同步操作

Rsync同步操作

Rsync源目录/ 目标目录

Rsync源目录 目标目录

Rsync/opt /mnt

Rsync/opt/ /mnt

-n:测试同步过程,不做实际修改

--delete:删除目标文件内多余的文档

-a:归档模式,相当于-rlptgoD

-v:显示详细操作信息

-z:传输过程中的压缩与解压

Mkdir/stu01

Mkdir/dir1

Cp/etc/passwd /etc/group /etc/fstab

Rsync-avz /dir1 /stu01

Ls/stu01/

Rsync-avz /dir1/ /stu01/

Ls/stu01/

Cp/etc/resolv.conf /dir1/

Rsync-avz /dir1/ /stu01/

Echohaha >> /dir1/group

Rsync-avz /dir1/ /stu01/

Echoxixi >> /dir1/resolv.conf

Rsync-avz /dir1/ /stu01/

Rsync--delete -avz /dir1/ /stu01/


Rsync+SSH远程同步

Rsync/本地路径/源文件 用户名@对方的IP:目标路经

虚拟机A

Rsync--delete -avz /opt/ [email protected]:/opt/

Touch/opt/{1..5}.txt

Ls/opt/

Rsync--delete -avz /opt/ [email protected]:/opt/


实时的远程同步

  1. 取消用户名密码验证

Ssh-keygen

Ls/root/.ssh

Ssh-copy-id[email protected]

Ssh[email protected]

/root/.ssh/auth

Ifconfig| head -2






#!/bin/bash

Whileinotifywait -mrq /opt/

Do

Rsync--delete -avz /opt/ [email protected]:/opt/

Done


[root@sr7~]# cat ./while.sh

#!/bin/bash

whileinotifywait -rqq /opt/

do

rsync--delete -az /opt/ [email protected]:/opt/

done

猜你喜欢

转载自blog.csdn.net/weixin_40018205/article/details/80951540
今日推荐