sql-server - 无法识别来自 restore-sqldatabase 的 AutoRelocateFile 参数
问题描述
我一直在尝试使用 powershell 中的 restore-sqldatabase 模块恢复数据库,除非存在多个数据文件的情况,否则它似乎工作得很好。
为了克服这个问题,我尝试使用参数 AutoRelocateFile。以下是用于执行具有多个数据文件的数据库备份的脚本。
Restore-SqlDatabase -SqlCredential $credentialName -ServerInstance $DestinationSQLInstanceName -Database $DestinationDBName -BackupFile $BackupPath -Verbose -ReplaceDatabase -AutoRelocateFile
该脚本应该已经替换了服务器中的现有数据库。但是它抛出了以下错误。
Restore-SqlDatabase : A parameter cannot be found that matches parameter name 'AutoRelocateFile'.
注意:备份和恢复在两个不同的服务器中进行,备份存在于 BLOB 中。
更新 1:找出丢失的 cmdlet,这是由于模块过时造成的。已更新模块,并且 cmdlet 出现在智能感知中。但是,恢复仍然会引发错误。下面是当前的片段。
Restore-SqlDatabase -AutoRelocateFile -ServerInstance $DestinationSQLInstanceName -Database $DestinationDBName -BackupFile $BackupPath -SqlCredential $credentialName
这是抛出以下错误。
Restore-SqlDatabase : An exception occurred while executing a Transact-SQL statement or batch.
At F:\ps_test\Backup-Restore\Restore-BLOB.ps1:543 char:10
+ Restore-SqlDatabase -AutoRelocateFile -ServerInstance $Dest
-autorelocate
当未提及该选项并使用该选项手动重新定位文件时,该代码工作正常-RelocateFile
。
解决方案
此选项 -AutoRelocateFile 已在版本21.1.18102中引入, 因此请检查您是否使用了正确版本的模块
PS我看到了你的更新。您是否删除了旧版本的模块?或尝试像这样使用 -RequiredVersion 选项导入模块
Import-Module SqlServer -RequiredVersion 21.1.18102
推荐阅读
- flutter - 颤振:使用加速度计时基数 10 无效
- java - 使用 Spring Security 使用 Telegram 登录
- vba - 如何更新多张幻灯片上的 ActiveX 标签?
- java - 启动Tomcat时加载Java类
- powershell - 尝试在 Powershell 中签署代码时出现 UnknownError
- vba - 循环浏览下拉列表
- python - 如何加快枕头(python)中的图像加载速度?
- apache-flink - Flink 中的 Taskmanager、Task、Slots、Parallelism、CPU 核是什么?
- r - 手动设置图例名称
- java - javax.naming.NamingException:名称未绑定到上下文