欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

rsync备份和删除指定文件 博客分类: linuxjava数据库  

程序员文章站 2024-03-15 12:15:11
...
文件异地备份时,需要将本地文件合并到服务器上,且不能删除服务器上已有的文件
rsync -avzP    --delete -f '+ MT_*' -f '- *.*' -f 'P **/'  -f 'P *.*'    --password-file=/root/sbin/rsync.password  /var/ztmis/ rsync@192.168.1.15::data-files

参数解释
-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)
-v, --verbose               increase verbosity
-z, --compress              compress file data during the transfer
-P                          same as --partial --progress
--delete                delete extraneous files from dest dirs
-f, --filter=RULE           add a file-filtering RULE

FILTER RULES

exclude, - specifies an exclude pattern.
include, + specifies an include pattern.
merge, . specifies a merge-file to read for more rules.
dir-merge, : specifies a per-directory merge-file.
hide, H specifies a pattern for hiding files from the transfer.
show, S files that match the pattern are not hidden.
protect, P specifies a pattern for protecting files from deletion.
risk, R files that match the pattern are not protected.
clear, ! clears the current include/exclude list (takes no arg)


上面的表达式,只同步"MT_"开头的文件,也同步删除"MT_"开头的文件,不同步本服务器其它文件,也保留目标服务器的其它文件

rsync参考文档