51

I'm trying to push changes to my server through ssh on windows (cygwin) using rsync. The command I am using is:

rsync -rvz -e ssh /cygdrive/c/myfolder/ rsyncuser@192.168.1.110:/srv/www/prj112/myfolder/

/srv/www/prj112/myfolder/ is owned by rsyncuser. My problem is that eventhough with rsync the sub directories are create as they publish, each directory is assigned default permission of d--------- so rsync fails to copy any files inside it.

How do I fix this?

Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
user391986
  • 29,536
  • 39
  • 126
  • 205
  • Could you post your Windows and Cygwin versions along with the output of the following command: ls -la /srv/www/prj112/myfolder? – Lars Wiegman May 06 '11 at 13:43

6 Answers6

74

The option to ignore NTFS permissions has changed in Cygwin version 1.7. This might be what's causing the problem.

Try adding the 'noacl' flag to your Cygwin mounts in C:\cygwin\etc\fstab, for example:

none /cygdrive cygdrive user,noacl,posix=0 0 0

You can pass custom permissions via rsync using the 'chmod' option:

rsync -rvz --chmod=ugo=rwX -e ssh source destination
Lars Wiegman
  • 2,397
  • 1
  • 16
  • 13
  • 20
    --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r (755DIRs 644FILEs, the default) – sabgenton May 25 '13 at 13:13
  • 2
    If you are running independent of a cygwin installation, use the `cygpath` utility to identify the location of the `fstab` to write to with `cygpath -w /etc/fstab`. This will usually be either relative to `%TMP%` or the current directory. – Alyssa Haroldsen May 17 '16 at 04:03
  • fwiw none of the `noacl` or `--chmod` suggestions above worked for me. But using `--no-perms` worked. – TTimo Oct 17 '17 at 15:51
  • No `cygpath` command when installing cwRsync through chocolatery as far as I'm concerned. How to edit dygwin\etc\fstab when it doesn't seem to be installed? – JesusIniesta Sep 10 '20 at 13:21
  • @JesusIniesta Did you find out where cwRsync reads fstab? This isn't a full cygwin installation, so I'm wondering the same. Maybe it's just the default C:/cygwin? – David Faure Jan 03 '23 at 19:14
8

Your problem stems from the fact that the Unix permissions on that directory really are 0. All of the access information is stored in separate ACLs, which rsync does not copy. Thus, it sets the permissions on the remote copy to 0, and, obviously, is unable to write to that directory afterwards. You can run

chmod -R 775

on that directory, which should fix your rsync problem.

After a look at the manpage I can tell that the chmod param is available in rsync since version ~2.6.8. But you have to use --chmod=ugo=rwX in combination with rsync -av

You should also try this command:

rsync -av <SOURCE_DIR> rsyncuser@192.168.1.110:/srv/www/prj112/myfolder

It would work on Linux at least. And note that rsync does not need to mention ssh--at least on Linux.

But if all fails and just to give an option you may take a look at this ready packed-up tool cwRsync

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
sra
  • 23,820
  • 7
  • 55
  • 89
7

if you deploy a site from windows (for ex. octopress use rsync) it's possible set permission to 775 adding multiple chmod command:

   rsync -avz --chmod=ug=rwx --chmod=o=rx -e ssh
Evilripper
  • 1,165
  • 1
  • 15
  • 26
2

To rsync from Windows to Unix/Linux you should provide a command like

SET BACKUP_SERVER=my.backup.server
SET SSH_USER=theUnixUserName
SET STORAGEPATH=/home/%SSH_USER%/Backup/
SET STORAGEURI=%BACKUP_SERVER%:%STORAGEPATH%    
SET SSH_ID=/cygdrive/c/Users/theWindowsUserName/Documents/keyfiles/id_dsa
SET EXCLUDEFILE=backup_excludes.txt
SET BACKUPLOGFILE=/cygdrive/c/Users/theWindowsUserName/Backuplogs/backup-%DATE%-%TIME::=-%.log

The ssh command then is

SET BACKUP=rsync -azvu --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --rsh="ssh -l %SSH_USER% -i '%SSH_ID%'" --exclude-from=%EXCLUDEFILE% --delete --delete-excluded --log-file="%BACKUPLOGFILE%"

with backup_excludes.txt containing lines of ignored elements like

.git
.svn
.o
\Debug
\Release

Then you would use this in a script with

%BACKUP% /cygdrive/c/mySensibleData %STORAGEURI%
%BACKUP% /cygdrive/c/myOtherSensibleData %STORAGEURI%
%BACKUP% /cygdrive/c/myOtherSensibleData2 %STORAGEURI%

and so on. This will backup your directories mySensibleData, myOtherSensibleData and myOtherSensibleData2 with the permissions 755 for directories and 644 for files. You also get backup logs in your %BACKUPLOGFILE% for each backup.

codingdave
  • 1,207
  • 16
  • 23
1

Cygwin rsync will report permission denied when some process has the target file open. Download and run Process Explorer and find out if anything else is locking the file or simply try renaming the file and see if you get the Windows error about some other process having the file open.

Mark
  • 86
  • 3
0

Also, you can try to create a (global) environment variable CYGWIN and set its value to nontsec

Kerb
  • 1,138
  • 2
  • 20
  • 39