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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5798807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:20:13  来源:igfitidea点击:

Rsync on Windows: wrong permissions for created directories

windowsrsync

提问by user391986

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

我正在尝试使用rsync. 我使用的命令是:

rsync -rvz -e ssh /cygdrive/c/myfolder/ [email protected]:/srv/www/prj112/myfolder/

rsync -rvz -e ssh /cygdrive/c/myfolder/ [email protected]:/srv/www/prj112/myfolder/

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

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

How do I fix this?

我该如何解决?

回答by Lars Wiegman

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

Cygwin 1.7 版中更改了忽略 NTFS 权限的选项。这可能是导致问题的原因。

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

回答by sra

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

您的问题源于该目录的 Unix 权限确实为 0。所有访问信息都存储在单独的 ACL 中,rsync 不会复制这些 ACL。因此,它将远程副本上的权限设置为 0,并且之后显然无法写入该目录。你可以跑

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. But you have to use --chmod=ugo=rwXin combination with rsync -av

查看手册页后,我可以看出 chmod 参数自版本 ~2.6.8 起在 rsync 中可用。但是你必须--chmod=ugo=rwX结合使用rsync -av

You should also try this command:

你也应该试试这个命令:

rsync -av <SOURCE_DIR> [email protected]:/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.

它至少可以在 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

回答by Evilripper

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

如果您从 Windows 部署站点(例如 octopress 使用 rsync),则可以将权限设置为 775 添加多个 chmod 命令:

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

回答by codingdave

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

要从 Windows rsync 到 Unix/Linux,您应该提供一个命令,如

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.txtcontaining 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, myOtherSensibleDataand myOtherSensibleData2with the permissions 755 for directories and 644 for files. You also get backup logs in your %BACKUPLOGFILE%for each backup.

等等。这将备份您的目录mySensibleDatamyOtherSensibleDatamyOtherSensibleData2,目录权限为 755,文件权限为 644。您还可以在%BACKUPLOGFILE% 中获得每次备份的备份日志。

回答by Mark

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.

当某个进程打开目标文件时,Cygwin rsync 将报告权限被拒绝。下载并运行进程资源管理器,看看是否还有其他东西锁定了文件,或者只是尝试重命名文件,看看是否收到有关打开文件的某个其他进程的 Windows 错误。

回答by Kerb

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

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