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”)

    $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.ReplaceDatabase = $true

    seems to work.

    PS H:\> $rstDatabase.Devices | select name


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.