Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rsync not synchronizing .htaccess file

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

like image 681
Sangfroid Avatar asked Jan 28 '12 16:01

Sangfroid


2 Answers

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.

like image 58
Adam Zalcman Avatar answered Sep 30 '22 07:09

Adam Zalcman


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. :)

like image 34
Brian Lacy Avatar answered Sep 30 '22 06:09

Brian Lacy