【问题标题】:AutoRelocateFile parameter from restore-sqldatabase not recognized无法识别来自 restore-sqldatabase 的 AutoRelocateFile 参数
【发布时间】:2019-04-26 21:00:05
【问题描述】:

我一直在尝试使用 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 中。

Update-1:找出丢失的 cmdlet,这是由于模块过时造成的。已更新模块,并且 cmdlet 出现在智能感知中。但是,恢复仍然会引发错误。下面是当前的sn-p。

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 选项手动重新定位文件时,代码可以正常工作。

【问题讨论】:

    标签: sql-server powershell


    【解决方案1】:

    此选项 -AutoRelocateFile 已在版本 21.1.18102 中引入 所以请检查您是否使用了正确版本的模块

    附:我看到了你的更新。您是否删除了旧版本的模块? 或者尝试像这样使用 -RequiredVersion 选项导入模块

    Import-Module SqlServer -RequiredVersion 21.1.18102
    

    【讨论】:

    • 我已经更新了模块并且脚本在指定参数时抛出任何错误。但是,它的 throws 现在会为相同的参数引发运行时错误。
    • 万一其他人遇到问题:通过运行“Install-Module -Name SqlServer -AllowClobber”升级后,我必须退出 PowerShell 并再次启动它以使新模块版本生效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-30
    • 2019-07-14
    相关资源
    最近更新 更多