Extract a RedGate SPB Backup with Powershell

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

3 thoughts on “Extract a RedGate SPB Backup with Powershell

  1. 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 😦

  2. [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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.