如何让 rsync 排除任何名为缓存的目录?

发布于 2024-12-10 12:36:59 字数 1359 浏览 0 评论 0原文

我是 rsync 的新手,并且已经阅读了一些有关排除文件和目录的内容,但我不完全理解并且似乎无法使其工作。

我只是尝试运行服务器 webroot 中所有网站的备份,但不需要任何 CMS 的缓存文件。

有没有办法排除任何名为缓存的目录?

这几周我尝试了很多事情(我不记得了),但最近我一直在尝试这些事情:

sudo rsync -avzO -e --exclude *cache ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

这个:

sudo rsync -avzO -e --exclude cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

这个:

sudo rsync -avzO -e --exclude */cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

这个:

sudo rsync -avzO -e --exclude *cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

抱歉,如果这很容易,我只是无法找到我理解的信息,因为他们都谈论排除的路径。

只是我没有想要排除的特定路径 - 只是一个目录名称(如果有意义的话)。

I'm new to rsync and have read a bit about excluding files and directories but I don't fully understand and can't seem to get it working.

I'm simply trying to run a backup of all the websites in a server's webroot but don't want any of the CMS's cache files.

Is there away to exclude any directory named cache?

I've tried a lot of things over the weeks (that I don't remember), but more recently I've been trying these sorts of things:

sudo rsync -avzO -e --exclude *cache ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude */cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

and this:

sudo rsync -avzO -e --exclude *cache/ ssh [email protected]:/home/ /Users/username/webserver-backups/DEV/home/

Sorry if this is easy, I just haven't been able to find info that I understand because they all talk about a path to exclude.

It's just that I don't have a specific path I want to exclude - just a directory name if that makes sense.

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

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

发布评论

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

评论(1

伊面 2024-12-17 12:36:59
rsync --exclude cache/ ....

应该像桃子一样工作。我认为您可能会混淆一些事情,因为 -e 需要一个选项(例如 -e "ssh -l ssh-user")。 编辑仔细查看您的命令行,事实证明这正是您的问题。您应该说过,

--exclude cache/ -e ssh

尽管您可以删除 -e ssh 因为 ssh 是默认设置。


我还建议您查看过滤规则:

rsync -FF ....

这样您就可以在整个目录树中包含 .rsync-filter 文件,其中包含类似这样的内容,

-cache/

这使得事情变得更加灵活,使命令行更具可读性,并且您可以在特定的内部进行例外处理子树。

rsync --exclude cache/ ....

should work like peaches. I think you might be confusing some things since -e requires an option (like -e "ssh -l ssh-user"). Edit on looking at your command lines a little closer, it turns out this is exactly your problem. You should have said

--exclude cache/ -e ssh

although you could just drop -e ssh since ssh is the default.


I'd also recommend that you look at the filter rules:

rsync -FF ....

That way you can include .rsync-filter files throughout your directory tree, containing things like

-cache/

This makes things way more flexible, make command lines more readable and you can make exceptions inside specific subtrees.

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