【发布时间】:2018-10-09 18:40:15
【问题描述】:
我有一个 powershell 脚本,可以使用 robocopy 将文件从一台计算机复制到另一台 UNC。最近,它使用一个新的用户帐户运行,并在目标上获得了拒绝访问。 重试限制设置为 10,因此此时失败。 问题是命令的返回并没有显示失败,退出码是0,所以没有捕捉到失败。 完整日志如下。您可以在顶部看到使用的选项:(仅更改了服务器名称) ( 最后一行来自 PS 命令
Write-Host "Robocopy.exe 使用代码 $lastexitcode")
[18:54:04][Step 1/1] Started : Monday, October 8, 2018 6:54:04 PM
[18:54:04][Step 1/1] Source : C:\Source
[18:54:04][Step 1/1] Dest : \\Server\Target
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Files : *.*
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /NP /R:2 /W:30
[18:54:04][Step 1/1]
[18:54:04][Step 1/1] ------------------------------------------------------------------------------
[18:54:04][Step 1/1]
[18:54:06][Step 1/1] 438 C:\Source
[18:54:06][Step 1/1] 2018/10/08 18:54:06 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:06][Step 1/1] Access is denied.
[18:54:06][Step 1/1]
[18:54:38][Step 1/1] Waiting 30 seconds... Retrying...
[18:54:38][Step 1/1] 2018/10/08 18:54:38 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:54:38][Step 1/1] Access is denied.
[18:54:38][Step 1/1]
[18:55:10][Step 1/1] Waiting 30 seconds... Retrying...
[18:55:10][Step 1/1] 2018/10/08 18:55:10 ERROR 5 (0x00000005) Accessing Destination Directory \\Server\Target
[18:55:10][Step 1/1] Access is denied.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ERROR: RETRY LIMIT EXCEEDED.
[18:55:10][Step 1/1]
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] ------------------------------------------------------------------------------
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Total Copied Skipped Mismatch FAILED Extras
[18:55:10][Step 1/1] Dirs : 1 0 1 0 0 0
[18:55:10][Step 1/1] Files : 0 0 0 0 0 0
[18:55:10][Step 1/1] Bytes : 0 0 0 0 0 0
[18:55:10][Step 1/1] Times : 0:01:06 0:00:00 0:01:00 0:00:06
[18:55:10][Step 1/1] Ended : Monday, October 8, 2018 6:55:10 PM
[18:55:10][Step 1/1]
[18:55:10][Step 1/1] Robocopy.exe completed with code 0
即使在这一点上,我唯一的预感是特定错误“访问目标目录”有些奇怪。当我尝试简单地删除文件权限的测试时,我收到错误
14:08:15 ERROR 5 (0x00000005) Copying File
并且 robocopy 正确返回退出代码 8,FAILED 计数 = 1。
TIA
JS
【问题讨论】:
-
但是 robocopy 没有失败;它完成了(它继续过去的“拒绝访问”消息)。 robocopy documentation 没有列出您想要的特定退出代码。您需要写出日志文件并在之后检查以确定您的情况是否发生。
-
如果 robocopy 遇到不同的错误,通常它会失败。 E:G:
-
如果 robocopy 遇到不同的错误,通常它会失败。 E:G:从 c:\temp\target 删除所有继承的权限。此命令:robocopy.exe C:\temp\Source C:\temp\target /e /purge /r:2 /w: write-host "exit code : $lastexitcode" 返回:Older 3 Fiel.txt 2018/10 /10 10:46:00 错误 5 (0x00000005) 复制文件 C:\temp\Source\Fiel.txt 访问被拒绝。错误:超过重试限制。退出代码:8
-
重点是robocopy的行为就是这样;你将无法改变它。如果它没有捕获您想要的错误,我建议创建一个日志文件(或捕获标准输出,如答案所述)并以这种方式检查错误。
标签: powershell robocopy