开发者

Rsync on Windows: wrong permissions for created directories

开发者 https://www.devze.com 2023-02-28 18:39 出处:网络
I\'m trying to push changes to my server through ssh on windows (cygwin) using rsync. The command I am using is:

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.1开发者_运维技巧10:/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?


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


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


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


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号