【问题标题】:Backup-SqlDatabase PsDrive FilesystemBackup-SqlDatabase PsDrive 文件系统
【发布时间】:2017-02-01 17:11:01
【问题描述】:

我正在尝试使用 Backup-SqlDatabase cmdlet 将 SQL 数据库备份到远程位置,但没有成功。

我正在创建一个名为 TARGET 的 PSDrive,例如 \\server\sharedFolder。

New-PSDrive –Name TARGET -PSProvider FileSystem -Root \\server\sharedfolder -Credential (Get-Credentials)

但是当我像这样运行备份时:

Backup-SqlDatabase -ServerInstance $server -Database $dbName -BackupFile "TARGET:bckfile.bak" -Credential $sqlCredentials

我得到一个完全不同的位置和错误:

Backup-SqlDatabase:System.Data.SqlClient.SqlError:无法打开备份设备“E:\SQL_BCK\TARGET\TARGET:bckfile.bak”。操作系统错误 3(系统找不到指定的路径)。

但如果我像这样运行备份:

Backup-SqlDatabase -ServerInstance $server -Database $dbName -BackupFile "\\server\sharedfolder\bckfile.bak" -Credential $sqlCredentials

我没有问题。

问题是,我需要使用不同的凭据访问共享文件夹,所以 PSDrive 是完美的解决方案,因为在配置过程中我会要求用户提供凭据。

【问题讨论】:

  • 如何创建 psdrive TARGET?如果您在本地工作站上创建它,它在实际写入数据的服务器上是不可见的。
  • New-PSDrive –Name TARGET -PSProvider FileSystem -Root \\server\sharedfolder -Credential (Get-Credentials)...目标是正确的...但是在使用时不起作用备份-sql数据库
  • 试试New-PSDrive ... -Persist

标签: powershell backup-sqldatabase


【解决方案1】:

尝试将-Scope "Script"添加到New-PSDrive

检查doc中的范围部分

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-15
    • 2015-07-08
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 2016-09-21
    • 2013-04-28
    相关资源
    最近更新 更多