iT邦幫忙

0

[POWERSHELL] 如何遠端使用SQLPS模組備份SQL 2008 R2資料庫

  • 分享至 

  • xImage
  •  

環境:

Client : Win 2012 R2 安裝 SQL 2014 Feature Fack , 已安裝SQLPS

Server: SQL 2008 R2 , Instance 為預設安裝

需求:

要從Client 端遠端執行SQLPS ,備份Server 端資料庫

Code:

$server = 'X.X.X.X\MSSQLSERVER'   #預設安裝
$db = 'test'
$username = 'sa'
$password = 'xxxxxxxxxx'
$password = ConvertTo-SecureString -AsPlainText $password -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile "D:\test.bak" -Credential $cred

Problem

執行就會報錯:

Backup-SqlDatabase :  無法連接伺服器  X.X.X.X\MSSQLSERVER
D:\Source\backupSql.ps1:8 ??:1
+ Backup-SqlDatabase -ServerInstance $server -Database $db -BackupFile "D:\test.ba ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Backup-SqlDatabase], ConnectionFailureException
    + FullyQualifiedErrorId : Microsoft.SqlServer.Management.Common.ConnectionFailureException,Microsoft.SqlServer.Management.PowerShell.Backup   SqlDatabaseCommand

請問有人知道問題在哪嗎 ?

謝謝^^


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言