我正在尝试备份SQL Server 2008 R2数据库,数据库名称为test
。
我正在使用以下PowerShell脚本,但是我收到一条错误消息,指出数据库不存在,但我可以看到test
数据库和表,我可以查询它。
Backup-SqlDatabase -ServerInstance testpc-001\SQLEXPRESS -Database test -BackupAction
Database
如果我尝试使用
编辑上述脚本$date = Get-Date -Format yyyyMMddHHmmss
$dbname = 'test'
Backup-SqlDatabase -ServerInstance SQLEXPRESS -Database $dbname -BackupFile
"C:\DBbackups\$($dbname)_db_$($dt).bak"
我收到错误,无法连接到SQLEXPRESS
答案 0 :(得分:6)
$date = Get-Date -Format yyyyMMddHHmmss
$dbname = 'test'
Backup-SqlDatabase -ServerInstance testpc-001\SQLEXPRESS -Database $dbname -BackupFile
"C:\DBbackups\$($dbname)_db_$($date).bak"
-ServerInstance参数
中存在拼写错误答案 1 :(得分:0)
$datetime = (Get-Date).ToString('MM-dd-yyyy');
$database1 = "Path\to\folder" + $datetime + ".bak";
$password = ConvertTo-SecureString "password" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("password", $password)
Backup-SqlDatabase -ServerInstance "SERVER ADDRESS" -Credential $Cred -Database Dummy_Bkp -Initialize -BackupFile $database1;
start-sleep -Seconds 20