如何让 rsync 排除任何名为缓存的目录?
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该像桃子一样工作。我认为您可能会混淆一些事情,因为
-e
需要一个选项(例如-e "ssh -l ssh-user"
)。 编辑仔细查看您的命令行,事实证明这正是您的问题。您应该说过,尽管您可以删除
-e ssh
因为 ssh 是默认设置。我还建议您查看过滤规则:
这样您就可以在整个目录树中包含 .rsync-filter 文件,其中包含类似这样的内容,
这使得事情变得更加灵活,使命令行更具可读性,并且您可以在特定的内部进行例外处理子树。
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 saidalthough you could just drop
-e ssh
since ssh is the default.I'd also recommend that you look at the filter rules:
That way you can include .rsync-filter files throughout your directory tree, containing things like
This makes things way more flexible, make command lines more readable and you can make exceptions inside specific subtrees.