Hi
I am logged on to one of the live app servers ( as this has SQL Management studio)
I am trying back up one of the active db server instances
## Full + Log Backup of MS SQL Server databases/span> ## with SMO. [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.ConnectionInfo'); [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Management.Sdk.Sfc'); [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO'); # Requiered for SQL Server 2008 (SMO 10.0). [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended'); $Server = "SP2010Instance"; # SQL Server Instance. $Dest = "y:\"; # shared drive. $srv = New-Object Microsoft.SqlServer.Management.Smo.Server $Server; Write-Output $srv.Name; # If missing set default backup directory. If ($Dest -eq "") { $Dest = $server.Settings.BackupDirectory + "\" }; Write-Output ("Started at: " + (Get-Date -format yyyy-MM-dd-HH:mm:ss)); # Full-backup for every database foreach ($db in $srv.Databases) { Write-Output $db.Name. If($db.Name -ne "tempdb") # Non need to backup TempDB { $timestamp = Get-Date -format yyyy-MM-dd-HH-mm-ss; $backup = New-Object ("Microsoft.SqlServer.Management.Smo.Backup"); $backup.Action = "Database"; $backup.Database = $db.Name; $backup.Devices.AddDevice($Dest + $db.Name + "_full_" + $timestamp + ".bak", "File"); $backup.BackupSetDescription = "Full backup of " + $db.Name + " " + $timestamp; $backup.Incremental = 0; # Starting full backup process. $backup.SqlBackup($srv); # For db with recovery mode <> simple: Log backup. If ($db.RecoveryModel -ne 3) { $timestamp = Get-Date -format yyyy-MM-dd-HH-mm-ss; $backup = New-Object ("Microsoft.SqlServer.Management.Smo.Backup"); $backup.Action = "Log"; $backup.Database = $db.Name; $backup.Devices.AddDevice($Dest + $db.Name + "_log_" + $timestamp + ".trn", "File"); $backup.BackupSetDescription = "Log backup of " + $db.Name + " " + $timestamp; #Specify that the log must be truncated after the backup is complete. $backup.LogTruncation = "Truncate"; # Starting log backup process $backup.SqlBackup($srv); }; }; }; Write-Output ("Finished at: " + (Get-Date -format yyyy-MM-dd-HH:mm:ss));
The script seems to list each (sharePoint ) database but then gives up!!!!!!
StateService_6e9ed1bd62e6471abe38f92fe145e98e
.
Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server '
SP2010DB01M'. "
At E:\daniel\backup_alldbs.ps1:32 char:26
+ $backup.SqlBackup <<<< ($srv);
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "SqlBackup" with "1" argument(s): "Backup failed for Server '