Linux rsync 不同步 .htaccess 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9046749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:15:57  来源:igfitidea点击:

rsync not synchronizing .htaccess file

linuxshellunixwildcardrsync

提问by Sangfroid

I am trying to rsync directory A of server1 with directory B of server2.

我正在尝试将 server1 的目录 A 与 server2 的目录 B 同步。

Sitting in the directory A of server1, I ran the following commands.

坐在server1的目录A中,我运行了以下命令。

rsync -av * server2::sharename/B

but the interesting thing is, it synchronizes all files and directories except .htaccess or any hidden file in the directory A. Any hidden files within subdirectories get synchronized.

但有趣的是,它同步所有文件和目录,除了 .htaccess 或目录 A 中的任何隐藏文件。子目录中的任何隐藏文件都会同步。

I also tried the following command:

我还尝试了以下命令:

rsync -av --include=".htaccess" * server2::sharename/B

but the results are the same.

但结果是一样的。

Any ideas why hidden files of A directory are not getting synchronized and how to fix it. I am running as root user.

为什么 A 目录的隐藏文件没有同步以及如何修复它的任何想法。我以 root 用户身份运行。

thanks

谢谢

回答by Adam Zalcman

This is due to the fact that *is by default expanded to all files in the current working directory except the files whose name starts with a dot. Thus, rsyncnever receives these files as arguments.

这是因为*默认情况下会扩展到当前工作目录中的所有文件,但名称以点开头的文件除外。因此,rsync永远不要接收这些文件作为参数。

You can pass .denoting current working directory to rsync:

您可以将.表示当前工作目录传递给rsync

rsync -av . server2::sharename/B

This way rsyncwill look for files to transfer in the current working directory as opposed to looking for them in what *expands to.

这种方式rsync将在当前工作目录中查找要传输的文件,而不是在*扩展到的目录中查找它们。

Alternatively, you can use the following command to make *expand to all files including those which start with a dot:

或者,您可以使用以下命令*扩展到所有文件,包括以点开头的文件:

shopt -s dotglob

See also shopt manpage.

另请参阅shopt 联机帮助页

回答by DonCallisto

The *tell to rsynch to not synch hidden files. You should not omit it.

*告诉rsynch不同步隐藏文件。你不应该省略它。

回答by vkraemer

I think the problem is due to shell wildcard expansion. Use . instead of star.

我认为问题是由于 shell 通配符扩展。用 。而不是明星。

Consider the following example directory content

考虑以下示例目录内容

$ ls -a .
. .. .htaccess a.html z.js

The shell's wildcard expansion translates the argument list that the rsync program gets from

shell 的通配符扩展转换了 rsync 程序从中获取的参数列表

-av * server2::sharename/B

into

进入

-av a.html z.js server2::sharename/B

before the command starts getting executed.

在命令开始执行之前。

回答by Brian Lacy

For anyone who's just trying to sync directories between servers (including all hidden files) -- e.g., syncing somedirAon source-serverto somedirBon a destination server -- try this:

对于任何人谁只是想同步的目录服务器之间(包括所有隐藏文件) -例如,同步somedirAsource-serversomedirB目标服务器上-试试这个

rsync -avz -e ssh --progress user@source-server:/somedirA/ somedirB/

Note the slashes at the end of both paths.Any other syntax may lead to unexpected results!

注意两条路径末尾的斜线。任何其他语法都可能导致意外结果!



Also, for me its easiest to perform rsynccommands from the destination server, because it's easier to make sure I've got proper write access (i.e., I might need to add sudoto the command above).

此外,对我来说,rsync从目标服务器执行命令最容易,因为确保我有正确的写访问权限更容易(即,我可能需要添加sudo到上面的命令中)。

Probably goes without saying, but obviously your remote user also needs read access to somedirAon your source server. :)

可能不言而喻,但显然您的远程用户也需要somedirA对您的源服务器进行读取访问。:)

回答by harleygolfguy

I had the same issue.

我遇到过同样的问题。

For me when I did the following command the hidden files did notget rsync'ed

对我来说,当我做了下面的命令隐藏的文件并没有得到rsync'ed

rsync -av /home/user1 server02:/home/user1

But when I added the slashes at the end of the paths, the hidden files were rsync'ed.

但是当我在路径的末尾添加斜杠时,隐藏的文件被同步。

rsync -av /home/user1/ server02:/home/user1/

Note the slashes at the end of the paths, as Brian Lacy said the slashes are the key. I don't have the reputation to comment on his post or I would have done that.

请注意路径末尾的斜线,正如 Brian Lacy 所说,斜线是关键。我没有资格评论他的帖子,否则我会这样做。