rsync排除目录但包含子目录 [英] rsync exclude a directory but include a subdirectory

查看:439
本文介绍了rsync排除目录但包含子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用rsync将项目复制到我的服务器。
我在子目录中有项目特定的安装脚本

I am trying to copy a project to my server with rsync. I have project specific install scripts in a subdirectory

项目/规格/安装/项目1

我要做的是排除 project / specs 目录中的所有内容,但是项目特定的安装目录: project / specs / install / project1

What I am trying to do is exclude everything in the project/specs directory but the project specific install directory: project/specs/install/project1.

rsync -avz --delete --include=specs/install/project1 \
    --exclude=specs/* /srv/http/projects/project/ \
     user@server.com:~/projects/project

但是像这样,specs目录的内容被排除,但是不包含install / project1目录。

But like this the content of the specs directory gets excluded but the install/project1 directory does not get included.

我已尝试过一切,但我似乎没有让这个工作

I have tried everything but i just don't seem to get this to work

推荐答案

有时它只是一个细节。

只需更改包含模式,在包含模式的末尾添加一个尾随/它就可以了:

Just change your include pattern adding a trailing / at the end of include pattern and it'll work:

rsync -avz --delete --include=specs/install/project1/ \
    --exclude=specs/* /srv/http/projects/project/ \
    user@server.com:~/projects/project

或者,替代方案,准备一个这样的过滤器文件:

Or, in alternative, prepare a filter file like this:

$ cat << EOF >pattern.txt
> + specs/install/project1/
> - specs/*
> EOF

然后使用--filter选项:

Then use the --filter option:

rsync -avz --delete --filter=". pattern.txt" \
    /srv/http/projects/project/ \
    user@server.com:~/projects/project

如需了解更多信息,请访问过滤器规则部分。 rsync(1)手册页。

For further info go to the FILTER RULES section in the rsync(1) manual page.

这篇关于rsync排除目录但包含子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆