本文介绍了使用Rsync的包含和排除选项按模式包括目录和文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在正确设置rsync语法时遇到问题,我想知道我的场景是否可以使用rsync实际处理.首先,我已经确认rsync在我的本地主机和远程主机之间可以正常工作.在目录上进行直接同步是成功的.

I'm having problems getting my rsync syntax right and I'm wondering if my scenario can actually be handled with rsync. First, I've confirmed that rsync is working just fine between my local host and my remote host. Doing a straight sync on a directory is successful.

这是我的文件系统的样子:

Here's what my filesystem looks like:

uploads/
  1260000000/
    file_11_00.jpg
    file_11_01.jpg
    file_12_00.jpg
  1270000000/
    file_11_00.jpg
    file_11_01.jpg
    file_12_00.jpg
  1280000000/
    file_11_00.jpg
    file_11_01.jpg
    file_12_00.jpg

我想做的是仅在子目录中以"file_11_"开头的文件上运行rsync,并且我希望能够仅运行一个rsync作业来同步子目录中的所有这些文件.

What I want to do is run rsync only on files that begin with "file_11_" in the subdirectories and I want to be able to run just one rsync job to sync all of these files in the subdirectories.

这是我正在尝试的命令:

Here's the command that I'm trying:

rsync -nrv --include="**/file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

这将导致0个文件在我的空运行中被标记为要传输.我已经尝试了--include和--exclude语句的各种其他组合,但是要么继续未获得任何结果,要么获得了所有内容,就好像没有设置任何include或exclude选项一样.

This results in 0 files being marked for transfer in my dry run. I've tried various other combinations of --include and --exclude statements, but either continued to get no results or got everything as if no include or exclude options were set.

任何人都不知道该怎么做吗?

Anyone have any idea how to do this?

推荐答案

问题是--exclude="*"表示要排除(例如)1260000000/目录,因此rsync从不检查该目录的内容,因此永远不会注意到该目录包含您的--include会匹配的文件.

The problem is that --exclude="*" says to exclude (for example) the 1260000000/ directory, so rsync never examines the contents of that directory, so never notices that the directory contains files that would have been matched by your --include.

我认为最接近您想要的是:

I think the closest thing to what you want is this:

rsync -nrv --include="*/" --include="file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(将包括所有目录,以及与file_11*.jpg匹配的所有文件,但没有其他文件),或者也许如下:

(which will include all directories, and all files matching file_11*.jpg, but no other files), or maybe this:

rsync -nrv --include="/[0-9][0-9][0-9]0000000/" --include="file_11*.jpg" --exclude="*" /Storage/uploads/ /website/uploads/

(概念相同,但要包含的目录更加挑剔).

(same concept, but much pickier about the directories it will include).

这篇关于使用Rsync的包含和排除选项按模式包括目录和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 18:34