rsync not synchronizing .htaccess file

Sangfroid picture Sangfroid · Jan 28, 2012 · Viewed 65.5k times · Source

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

Answer

Adam Zalcman picture Adam Zalcman · Jan 28, 2012

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.