Rsync如何包含目录但不包含文件?

发布于 2024-09-16 05:39:37 字数 466 浏览 1 评论 0原文

我有一个目录结构,像这样的文件

data/
data/a.txt
data/folder/
data/folder/b.txt
data/folder/folder/
data/folder/folder/c.txt
...

a.txtb.txtc.txt 是计算机生成的大文件并且经常更新。它们不应该被备份 - 但我想备份目录结构:

data/
data/folder/
data/folder/folder/

如何使用 rsync 和 --exclude-from 执行此操作,而不指定每个文件夹,但类似于 rsync -a data/* --exclude -from=exclude.rsync "" --onlyfoldersandnotfiles""?

感谢您的帮助!

I have a directory structure and files like this

data/
data/a.txt
data/folder/
data/folder/b.txt
data/folder/folder/
data/folder/folder/c.txt
...

a.txt, b.txt, and c.txt are large files that are computer-generated and renewed frequently. They should NOT be backuped -- but I want to backup the directory structure :

data/
data/folder/
data/folder/folder/

How can I do this with rsync and --exclude-from, without specifying every folder, but something like rsync -a data/* --exclude-from=exclude.rsync "" --onlyfoldersandnotfiles""?

Thanks for help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

飘落散花 2024-09-23 05:39:37
rsync -a --include='*/' --exclude='*' source/ destination/

基本上,首先包含所有目录,然后排除所有文件。

rsync -a --include='*/' --exclude='*' source/ destination/

Basically, first include all directories, then exclude all files.

月寒剑心 2024-09-23 05:39:37
$ rsync -a -f"+ */" -f"- *" source/ destination/

“两个 -f 参数分别表示“复制所有目录”和“不复制其他任何内容”。

更多详细信息:http://psung.blogspot.com/ 2008/05/复制目录树-with-rsync.html

$ rsync -a -f"+ */" -f"- *" source/ destination/

"The two -f arguments mean, respectively, "copy all directories" and then "do not copy anything else"."

Further details: http://psung.blogspot.com/2008/05/copying-directory-trees-with-rsync.html

子栖 2024-09-23 05:39:37
rsync -a -f"-! */" source/ destination/

过滤规则的意思是“排除不是目录的任何内容”。

rsync -a -f"-! */" source/ destination/

Filter rule means "Exclude anything that's not a directory."

撩心不撩汉 2024-09-23 05:39:37

如果您想要同步除一个文件夹之外的所有内容,但仍想保留该排除文件夹的目录结构,您应该执行以下操作:

$ rsync -a -f"+ /var/log/**/*/" -f"- /var/log/**/*" source/ destination/

请参阅 排除列表rsync 命令为例。

If you want to sync everything except one folder but you still want to keep the directory structure of that excluded folder, you should do the following:

$ rsync -a -f"+ /var/log/**/*/" -f"- /var/log/**/*" source/ destination/

See the exclude-list and the rsync command as an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文