rsync not synchronizing .htaccess file
LinuxShellUnixWildcardRsyncLinux Problem Overview
I am trying to rsync directory A of server1 with directory B of server2.
Sitting in the directory A of server1, I ran the following commands.
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.
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.
thanks
Linux Solutions
Solution 1 - Linux
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, rsync
never receives these files as arguments.
You can pass .
denoting current working directory to rsync
:
rsync -av . server2::sharename/B
This way rsync
will look for files to transfer in the current working directory as opposed to looking for them in what *
expands to.
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.
Solution 2 - Linux
For anyone who's just trying to sync directories between servers (including all hidden files) -- e.g., syncing somedirA
on source-server
to somedirB
on a destination server -- try this:
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 rsync
commands from the destination server, because it's easier to make sure I've got proper write access (i.e., I might need to add sudo
to the command above).
Probably goes without saying, but obviously your remote user also needs read access to somedirA
on your source server. :)
Solution 3 - Linux
I had the same issue.
For me when I did the following command the hidden files did not get 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.
Solution 4 - Linux
I think the problem is due to shell wildcard expansion. Use . instead of star.
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
-av * server2::sharename/B
into
-av a.html z.js server2::sharename/B
before the command starts getting executed.
Solution 5 - Linux
The *
tell to rsynch to not synch hidden files. You should not omit it.