使用msdeploy迁移IIS 10时遇“文件已存在无法创建”错误求助
IIS 10服务器迁移时MSDeploy报错:无法创建已存在的文件
我们尝试使用以下命令将IIS 10从一台服务器迁移至另一台:
msdeploy -verb:sync -source:webServer,computername=academicApp01T -dest:webServer,computername=WEBAAPPT01WA, -enablelink:AppPoolExtension -disableLink:Content -replace:objectName=metaProperty,scopeAttributeName=name,scopeAttributeValue="ServerBindings",match=sourceIP,replace=newdestinationIP
已安装MSDeploy的「完整」版本(非自定义/典型版本),但持续出现如下错误:
C:\Program Files\IIS\Microsoft Web Deploy V3>msdeploy -verb:sync -source:webServer,computername=academicApp01T -dest:webServer,computername=WEBAAPPT01WA, -enablelink:AppPoolExtension -disableLink:Content -replace:objectName=metaProperty,scopeAttributeName=name,scopeAttributeValue="ServerBindings",match=sourceIP,replace=newdestinationIP Info: Using ID 'ab29a6b0-c2d7-4e0c-afad-f410a54db50c' for connections to the remote server. Info: Using ID '830a233d-98f3-4a9a-ab8e-c4437cb94b92' for connections to the remote server. Info: Updating section (MSDeploy.webServer/webServer/appHostConfig[@path='']/configSections/sectionGroup[@name='system.webServer']/section[@name='httpCompression']). Info: Adding child appHostConfig (MSDeploy.webServer/webServer/appHostConfig[@path='']/location[@path='']). Error: (12/28/2023 9:36:54 AM) An error occurred when the request was processed on the remote computer. Error: Cannot create a file when that file already exists. (Exception from HRESULT: 0x800700B7)
解决方法
1. 排查目标服务器的重复配置节点
根据日志中的httpCompression和空路径location节点提示,目标服务器的applicationHost.config(路径:C:\Windows\System32\inetsrv\config\applicationHost.config)大概率已存在相同配置项。打开该文件搜索httpCompression,删除重复的配置段后重试同步。
2. 添加跳过规则避免冲突
在原命令中加入-skip参数,跳过已存在的冲突节点:
- 跳过
httpCompression配置:
msdeploy -verb:sync -source:webServer,computername=academicApp01T -dest:webServer,computername=WEBAAPPT01WA -enablelink:AppPoolExtension -disableLink:Content -replace:objectName=metaProperty,scopeAttributeName=name,scopeAttributeValue="ServerBindings",match=sourceIP,replace=newdestinationIP -skip:objectName=section,scopeAttributeName=name,scopeAttributeValue=httpCompression
- 若为空路径
location节点冲突,追加:
-skip:objectName=location,scopeAttributeName=path,scopeAttributeValue=""
3. 重置目标服务器IIS默认配置
如果目标服务器是新部署的,先重置IIS配置到默认状态,再执行迁移命令:
%windir%\system32\inetsrv\appcmd reset config
4. 验证执行账号权限
确保执行命令的账号在目标服务器拥有管理员权限,权限不足可能导致配置写入时抛出异常错误。
内容的提问来源于stack exchange,提问作者gabriel
相关产品推荐
相关产品推荐

