Robocopy 错误代码 6“句柄无效”
我编写了一个 python 脚本,它使用子进程调用 robocopy 从远程主机同步日志文件。
像这样:
program = 'Robocopy'
options = ['/S']
args.append(program)
args.append(options)
args.append('\\\\%s\%s' % (hostname, source_path))
args.append(local_path)
proc = subprocess.Popen(args=args, shell=True, stdout=cmd_log, stderr=error_log)
其中 source_path 是远程主机上的路径,local_path 是本地主机上的路径(都是 UNC 路径)。 该代码通常在守护进程中运行,并每隔几个小时启动一次。也可以直接在命令提示符下运行此代码。看来有时当它在守护进程中运行时,我会从 Robocopy 收到错误:
错误代码 6:“句柄无效”
但是当我在命令提示符下运行此命令时,我没有收到任何错误。根据我在网络搜索中发现的内容,这可能与正在传输的文件上已打开的文件句柄有关。有谁有关于此错误的更多信息以及避免该错误的方法吗?
I have written a python script that uses subprocess to call robocopy to sync log files from a remote host.
Like so:
program = 'Robocopy'
options = ['/S']
args.append(program)
args.append(options)
args.append('\\\\%s\%s' % (hostname, source_path))
args.append(local_path)
proc = subprocess.Popen(args=args, shell=True, stdout=cmd_log, stderr=error_log)
where source_path is the path on the remote host and local_path is the path on local host (both UNC paths).
The code typically runs in a daemon process and gets kicked off every few hours. It is also possible to runs this code directly on the command prompt. It appears that sometimes when it is running in a daemon process I get an error from Robocopy:
Error code 6: 'The handle is invalid'
But when I run this on the command prompt I get no errors. From what I found in a web search this may be related to file handles that are already open on the files being transferred. Does anyone have more information on this error and ways to avoid it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 搜索“robocopy 句柄无效” 建议您可能通过使用“备份模式”的 /b 选项来成功。
即使这不起作用,我建议添加代码以在复制(或记录)文件名时输出文件名,一旦您确定了特定的失败文件,您也可能会意识到问题是什么。
Google searches for "robocopy handle is invalid" suggest you might find success by using the /b option for "backup mode".
Even if that doesn't work, I'd suggest adding code to output the filenames as they are being copied (or log it), and once you've identified the specific failing file, you may well also realize what the problem is.