Quick post on how to extract a red gate sqlbackup file back to native format using powershell. There’s no redgate cmdlets to do this, I’m just using invoke-expression (or use the ampersand for shorthand) to extract the backups. This will create multiple .bak files; one per each thread according to the number of threads that were specified when creating the original backup.
$file = "C:\PathToOriginalSPB_Backup\OriginalBackup.sqb" $extractor = "C:\Program Files (x86)\Red Gate\SQL Backup 7\sqb2mtf.exe" $destination = "C:\WhereYouWantYourExtractedBackupsToGO\NativeBackups.bak" $params = "`"$($file)`"", "`"$($destination)`"" & $extractor $params
I hade figured this out as well , now I all I need to figure out is how do a restore in powershell from multiple bak files….smo.BackupDeviceItem
does not seem to accept an array or have an ,add method 😦
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SMO”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.SmoExtended”)
[Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.ConnectionInfo”)
[Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Management.Sdk.Sfs”)
$connection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection(“tdb01-sqltest”)
$sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server($connection)
$rstDatabase = New-Object Microsoft.SqlServer.Management.Smo.Restore
$rstDatabase.Action = [Microsoft.SqlServer.Management.Smo.RestoreActionType]::Database
$rstDatabase.Database = “ApproveIT-Main”
$rstDatabase.ReplaceDatabase = “true”
foreach ( $file in $files) {
$bkpDevice = New-Object Microsoft.SqlServer.Management.Smo.BackupDeviceItem($file.Fullname, [Microsoft.SqlServer.Management.Smo.DeviceType]::File)
$rstDatabase.Devices.Add($bkpDevice)
}
$rstDatabase.ReplaceDatabase = $true
$rstDatabase.SqlRestore($sqlServer)
seems to work.
PS H:\> $rstDatabase.Devices | select name
Name
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_00.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_01.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_02.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_03.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_04.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_05.bak
C:\Restore_from_production\ApproveIT-Main\ApproveIT-Main_06.bak
Yup, was going to post that myself. I’ve got the restore part working also. Well, until I found a TDE enabled database that is….