在理解子path的rsyncfilter规则方面,我有一个很大的问题。 我有这个目录树:
|-- index.php |-- other-file-php.php |-- filesource.php | |-- album1 | | |-- firstphoto.jpg | | |-- second.jpg | | |-- index.php | | `-- thumbs | | |-- _map.txt | | |-- _title_ciao.jpg.txt | | |-- _120_second.jpg | | |-- _dir_album1.jpg | | `-- _300_second.jpg | |-- altre | | |-- img_1172.jpg | | |-- album2 | | | |-- index.php | | | `-- thumbs | | | |-- _title_img_1172.jpg.txt | | | |-- _dir_album2.jpg | | | `-- _guestbook.html
我只能使用rsync的选项-f -filter,因为我必须将所有规则写入一个文件。 在这个树中,有不同types的文件可以在树的任何级别。 我要:
.php , .txt , .htmltypes的所有文件 _开头的备份.jpg文件 _dir开头的备份.jpg文件 为了解决您的观点:
使用:
+ **/*.php + **/*.txt + **/*.html
使用:
+ **/*.jpg - **/_*.jpg
我不知道你的意思。
将以下几行放入filter.txt :
+ */ + *.php + *.txt + *.html + **/_dir*.jpg - **/_*.jpg + *.jpg - *
然后像这样运行rsync :
rsync -a --include-from=filter.txt /path/to/source/ /path/to/dest
filter.txt解释:
首先,请注意,过滤规则的sorting非常重要,因为rsync按顺序对它们进行评估,并应用匹配的第一条规则 。
默认情况下, rsync包含所有未明确排除的文件,因此filter.txt的最后一条规则是排除上述规则未明确包含的所有内容。 第一个规则包括所有的目录(如尾部所示),它应该照顾你的#1条件。 规则2至4分别处理php,txt和html文件,而规则5至7则允许以_dir开头的所有jpg文件,否则不以_开头。
(规则5和规则6具有**前缀,以便将通配符规则锚定到任何目录深度的文件名部分的开头,没有**前缀,这些规则只会匹配顶级源目录。
最后说明:如果你不能(由于某种原因)使用--include-from ,那么你应该能够在命令行中将过滤规则指定为一系列-f选项。
编辑
要在rsnapshot使用rsnapshot ,可以通过include_file参数在rsnapshot.conf指定它,如下所示:
include_file /path/to/filter.txt
编辑#2
如果您需要为每个备份使用一组不同的filter,则可以对rsnapshot.conf每个backup行使用不同的include_file ,例如:
... backup /path/to/src1/ dest1/ include_file=/path/to/src1_filter.txt backup /path/to/src2/ dest2/ include_file=/path/to/src2_filter.txt ...
最适合你的是使用选项来创build文件:– --files-from使用find命令,如下所示:
cd dirtobackup;find . |egrep '\.php$|\.txt$|\.html$|^[^_].*\.jpg$|^_dir.*\.jpg$' >/tmp/files_tobackup rsync --files-from=/tmp/files_tobackup dirtubackup dst