说明:
使用rsync -av –exclude=upload /home/mysql/backup /home/mysql/backup2/ 只能排除upload文件/目录。但如果要排除多个文件/目录,就需要新建个exclude.list,然后rsync -av –exclude-from=”exclude.list”指定不需要同步的文件/目录
实现:
# rsync -av --exclude-from=/root/exclude.list /home/mysql/backup /home/mysql/backup2/ //将/home/mysql/backup目录拷贝到/home/mysql/backup2目录下,/root/exclude.list中指定文件不拷贝。
注意exclude.list里面填写要排除的文件/目录,一行一个,直接写文件名即可。这里,可以把/home/mysql/backup看成根目录,所以如果要排除a,b.1,b.2,tmp/g,那么exclude.list里就应该写
a b.* tmp/g
而不是填写以下完整url。不然这样还是会同步a,b.1,b.2,tmp/g
/home/mysql/backup/a /home/mysql/backup/b.* /home/mysql/backup/tmp/g
当然以下这种写法也是会同步a,b.1,b.2,tmp/g文件的,也是有问题
./home/mysql/backup/a ./home/mysql/backup/b.* ./home/mysql/backup/tmp/g
附录:
–exclude=PATTERN exclude files matching PATTERN
–exclude-from=FILE read exclude patterns from FILE
–include=PATTERN don’t exclude files matching PATTERN
–include-from=FILE read include patterns from FILE