2016-06-10 4 views
2

EDIT zu beheben:Powershell: Backup-SQLDatabase versagt Pfad

Ich fand heraus, dass ich auch die ServerInstance angeben benötigt:

Backup-SqlDatabase -ServerInstance [ServerName] -Database [DBName] -BackupFile "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Copy.bak" 

ORIGINAL POST:

Ich versuche, Sichern Sie eine Datenbank mit dem Cmdlet Backup-Sqldatabase. Dies ist das Skript i zu laufen bin versucht:

Backup-SqlDatabase -Database "LokalUdvikling" -CompressionOption "On" -CopyOnly -Path “C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA" -BackUpFile "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup\Copy.bak" 

Dies führt zu diesem Fehler:

Backup-SqlDatabase : Failed to resolve the path ‘C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL’ to an object of type 'Microsoft.S 
qlServer.Management.Smo.Server'. Either set your location to the proper context, or use the -Path parameter to specify the location. 
At line:1 char:1 
+ Backup-SqlDatabase 
+ ~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (C:\Program File...SQLSERVER\MSSQL:String) [Backup-SqlDatabase], SqlPowerShellContextException 
    + FullyQualifiedErrorId : ContextError,Microsoft.SqlServer.Management.PowerShell.BackupSqlDatabaseCommand 

Der Pfad, in dem die Datenbankdateien befinden. Was mache ich falsch?

Ich hoffe wirklich, dass jemand helfen kann/klären Dinge :)

Antwort

0

irgendeine Sache versuchen wie folgt aus:

Function Invoke-SQLBackup { 

[CmdletBinding()] 
param(
    [Parameter(Mandatory=$true)] 
    [String] $ServerInstance, 

    [Parameter(Mandatory=$true)] 
    [String] $DatabaseName, 

    [Parameter(Mandatory=$true)] 
    [String] $BackupFile 

    ) 

if (Get-Module -ListAvailable -Name SQLPS) 
    { 
     Import-Module SQLPS -Force 

      Backup-SqlDatabase -ServerInstance $ServerInstance -Database $DatabaseName -BackupFile $BackupFile -Verbose 
    } 

ELSE 

    { 
     Write-Output "SQLPS Module not Installed. Please install and try again." 
    } 
} 

Ich schrieb und ausgeführt, um die oben in meiner Testumgebung und die Sicherung ohne Probleme abgeschlossen.

Syntax auszuführen und zu dem unten ähnlich aussehen:

PS SQLSERVER:\> Invoke-SQLBackup -ServerInstance 'SERVERNAME\INSTANCENAME' -DatabaseName 'TestDatabase' -BackupFile 'C:\SomePath\Filename.bak' 
    WARNING: The names of some imported commands from the module 'SQLPS' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb. 
    VERBOSE: Performing the operation "Backup-SqlDatabase" on target "[SERVERNAME\INSTANCENAME]". 
    VERBOSE: BACKUP DATABASE [KB] TO DISK = N'C:\SomePath\FileName.bak' WITH NOFORMAT, NOINIT, NOSKIP, REWIND, NOUNLOAD, STATS = 10 
    VERBOSE: 10 percent processed. 
    VERBOSE: 21 percent processed. 
    VERBOSE: 32 percent processed. 
    VERBOSE: 40 percent processed. 
    VERBOSE: 51 percent processed. 
    VERBOSE: 61 percent processed. 
    VERBOSE: 72 percent processed. 
    VERBOSE: 80 percent processed. 
    VERBOSE: 91 percent processed. 
    VERBOSE: Processed 296 pages for database 'DatabaseTest', file 'DatabaseTest' on file 4. 
    VERBOSE: 100 percent processed. 
    VERBOSE: Processed 2 pages for database 'DatabaseTest', file 'DatabaseTest_log' on file 4. 
    VERBOSE: BACKUP DATABASE successfully processed 298 pages in 0.217 seconds (10.728 MB/sec). 

Da Sie SQL-Ordner in Programmdateien stellen Sie sicher, Sie führen das Skript als ein Konto zu speichern versuchen, auf Standard, der Zugriff hat zu schreibe an den Ort. Zum Beispiel ein Administrator-Konto oder wenn Sie ein Dienstkonto für Backups von denen haben, würde funktionieren. Das Administratorkonto sollte standardmäßig auf den Ordner mit den Programmdateien zugreifen können, vorausgesetzt, die Berechtigungen wurden nicht geändert.

Hoffe, das hilft.