1、安装rsync
yum instsall rsync
2、本地复制
rsync -auq --progress --delete /tongbu1/ /tongbu2/
rsync -auq --progress --delete --exclude-from='/root/exclude.txt' /opt/mysql/data/ /mysqlbak/binlog/
3、配置ssh密匙
4、远程复制
rsync -e ssh -a -z --compress-level=9 "${backdir}.zip" 192.168.20.2:/mnt
5、复制远程服务器的文件到本地
rsync -e ssh -a -z --compress-level=9 192.168.20.2:/mnt ./ rsync -e ssh -a -z --compress-level=9 "${backdir}.zip" 192.168.20.2:/mntrsync -e ssh -auqz --delete /home/backup/tapebackup 192.168.20.2:/backup/daily_backuprsync -e ssh -auq -z --compress-level=9 --delete /home/backup/tapebackup 192.168.20.2:/backup/daily_backup报错
[root@02 ~]# rsync -e ssh -ar -z --compress-level=9 /home/backup/tapebackup root@192.168.20.2:/backup/daily_backupAddress 192.168.20.2 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!bash: rsync: command not foundrsync: connection unexpectedly closed (0 bytes received so far) [sender]rsync error: remote command not found (code 127) at io.c(600) [sender=3.0.6]问题是客户端服务器没有安装rsync,需要两台机器都要安装rsync
rsync排除文件及目录
一、排除单独的文件夹和文件
要排除sources文件夹,我们可以添加 '--exclude' 选项: --exclude 'sources' 命令是这样的: rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' demo@123.45.67.890:/home/demo /backup/ 要排除 "public_html" 文件夹下的 "database.txt" 文件: --exclude 'public_html/database.txt' 命令是这样的: rsync -e 'ssh -p 30000' -avl --delete --stats --progress --exclude 'sources' --exclude 'public_html/database.txt' demo@123.45.67.890:/home/demo /backup/ 二、使用 '--exclude-from' 排除多个文件夹和文件 建立文件: /home/backup/exclude.txt 在里面定义要排除的文件夹和文件sourcespublic_html/database.*downloads/test/**.txt
转载请注明出处
转自
rsync命令排除文件和文件夹(exclude-from) - CSDN博客 https://blog.csdn.net/liangdsh/article/details/51769910
参考
https://blog.csdn.net/knight_zhen/article/details/47109077