简体   繁体   English

Windows上的Rsync:创建的目录的权限错误

[英]Rsync on Windows: wrong permissions for created directories

I'm trying to push changes to my server through ssh on windows (cygwin) using rsync . 我正在尝试使用rsync通过Windows(cygwin)上的ssh将更改推送到我的服务器。 The command I am using is: 我使用的命令是:

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

/srv/www/prj112/myfolder/ is owned by rsyncuser . /srv/www/prj112/myfolder/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. 我的问题是,尽管使用rsync子目录是在发布时创建的,但每个目录都被分配了d---------默认权限,因此rsync无法复制其中的任何文件。

How do I fix this? 我该如何解决?

The option to ignore NTFS permissions has changed in Cygwin version 1.7. 在Cygwin 1.7版中,忽略NTFS权限的选项已更改。 This might be what's causing the problem. 这可能是导致问题的原因。

Try adding the 'noacl' flag to your Cygwin mounts in C:\\cygwin\\etc\\fstab, for example: 尝试将“noacl”标志添加到C:\\ cygwin \\ etc \\ fstab中的Cygwin挂载中,例如:

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

You can pass custom permissions via rsync using the 'chmod' option: 您可以使用'chmod'选项通过rsync传递自定义权限:

rsync -rvz --chmod=ugo=rwX -e ssh source destination

如果你从windows部署一个站点(例如octopress使用rsync),可以设置775添加多个chmod命令的权限:

   rsync -avz --chmod=ug=rwx --chmod=o=rx -e ssh

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. 您的问题源于这个目录上的Unix权限确实是0的事实。所有访问信息都存储在单独的ACL中,rsync不会复制。 Thus, it sets the permissions on the remote copy to 0, and, obviously, is unable to write to that directory afterwards. 因此,它将远程副本上的权限设置为0,显然,之后无法写入该目录。 You can run 你可以跑

chmod -R 775

on that directory, which should fix your rsync problem. 在该目录上,它应该修复您的rsync问题。

After a look at the manpage I can tell that the chmod param is available in rsync since version ~2.6.8. 在查看了联机帮助页后,我可以看出,自版本~2.6.8以来,chmod param在rsync中可用。 But you have to use --chmod=ugo=rwX in combination with rsync -av 但是你必须将--chmod=ugo=rwXrsync -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. 它至少可以在Linux上运行。 And note that rsync does not need to mention ssh--at least on Linux. 请注意,rsync不需要提及ssh - 至少在Linux上是这样。

But if all fails and just to give an option you may take a look at this ready packed-up tool cwRsync 但如果一切都失败了,只是给出一个选项,你可以看看这个准备好的打包工具cwRsync

To rsync from Windows to Unix/Linux you should provide a command like 要从Windows到Unix / Linux的rsync,您应该提供类似的命令

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 然后是ssh命令

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 backup_excludes.txt包含被忽略元素的行

.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. 这将备份您的目录mySensibleDatamyOtherSensibleDatamyOtherSensibleData2 ,其目录权限为755,文件为644。 You also get backup logs in your %BACKUPLOGFILE% for each backup. 您还可以在每个备份的%BACKUPLOGFILE%中获取备份日志。

Cygwin rsync will report permission denied when some process has the target file open. 当某个进程打开目标文件时,Cygwin rsync将报告拒绝权限。 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. 下载并运行Process Explorer并查看是否还有其他内容正在锁定文件,或者只是尝试重命名该文件,看看是否有关于文件打开的其他进程的Windows错误。

此外,您可以尝试创建(全局)环境变量CYGWIN并将其值设置为nontsec

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM