Rsync does not sync .htaccess file

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

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

rsync -av * server2::sharename/B 

but it’s interesting that it synchronizes all files and directories except .htaccess or any hidden file in directory A. Any hidden files in subdirectories are synchronized.

I also tried the following command:

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

but the results are the same.

Any ideas why hidden directory files are not syncing and how to fix them. I work as root user.

thank

+50
linux unix shell wildcard rsync
Jan 28 '12 at 16:18
source share
5 answers

This is because * by default applies to all files in the current working directory, with the exception of files whose name begins with a period. Thus rsync never receives these files as arguments.

You can pass . by specifying the current working directory on rsync :

 rsync -av . server2::sharename/B 

This rsync method will look for files to transfer in the current working directory, and not look for them in what * extends.

Alternatively, you can use the following command to do * expand for all files, including those starting with a period:

 shopt -s dotglob 

See also shopt man page .

+69
Jan 28 '12 at 16:22
source share

For those who are just trying to synchronize directories between servers (including all hidden files) - for example, synchronizing somedirA on source-server to somedirB on the target server - try :

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

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




Also, it’s easiest for me to execute rsync commands from the target server, because it’s easier to make sure that I have proper write access (i.e. I may need to add sudo to the above command).

Perhaps it goes without saying, but obviously, your remote user also needs read access to somedirA on the source server. :)

+30
May 21 '13 at 14:41
source share

I had the same problem.

For me, when I executed the following command, hidden files did n’t get rsync'ed

 rsync -av /home/user1 wobgalaxy02:/home/user1 

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

 rsync -av /home/user1/ wobgalaxy02:/home/user1/ 

Pay attention to the slashes at the end of the paths , as Brian Lacy said that slashes are the key. I have no reputation to comment on his post, or I would do it.

+7
Nov 25 '15 at 19:04
source share

I think the problem is with shell expansion expansion. Use. instead of a star.

Consider the following example directory contents

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

The shell wildcard extension converts the argument list that rsync receives from

 -av * server2::sharename/B 

at

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

before the command starts running.

+3
Jan 28 '12 at 16:27
source share

* Tell rsynch not to sync hidden files. Have you tried to skip it?

+2
Jan 28 '12 at 16:23
source share



All Articles