commands

^

Select-DbaBackupInformation

Author Stuart Moore (@napalmgram), stuart-moore.com
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Select-DbaBackupInformation on GitHub.
Want to see the Bill Of Health for this command? Check out Select-DbaBackupInformation.

Synopsis

Select a subset of backups from a dbatools backup history object

Description

Select-DbaBackupInformation filters out a subset of backups from the dbatools backup history object with parameters supplied.

Syntax

Select-DbaBackupInformation
    [-BackupHistory] <Object>
    [[-RestoreTime] <DateTime>]
    [-IgnoreLogs]
    [-IgnoreDiffs]
    [[-DatabaseName] <String[]>]
    [[-ServerName] <String[]>]
    [[-ContinuePoints] <Object>]
    [[-LastRestoreType] <Object>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\server1\backups$
PS C:\> $FilteredBackups = $Backups | Select-DbaBackupInformation -RestoreTime (Get-Date).AddHours(-1)

Returns all backups needed to restore all the backups in \server1\backups$ to 1 hour ago

Example: 2
PS C:\> $Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\server1\backups$
PS C:\> $FilteredBackups = $Backups | Select-DbaBackupInformation -RestoreTime (Get-Date).AddHours(-1) -DatabaseName ProdFinance

Returns all the backups needed to restore Database ProdFinance to an hour ago

Example: 3
PS C:\> $Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\server1\backups$
PS C:\> $FilteredBackups = $Backups | Select-DbaBackupInformation -RestoreTime (Get-Date).AddHours(-1) -IgnoreLogs

Returns all the backups in \server1\backups$ to restore to as close prior to 1 hour ago as can be managed with only full and differential backups

Example: 4
PS C:\> $Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\server1\backups$
PS C:\> $FilteredBackups = $Backups | Select-DbaBackupInformation -RestoreTime (Get-Date).AddHours(-1) -IgnoreDiffs

Returns all the backups in \server1\backups$ to restore to 1 hour ago using only Full and Log backups.

Required Parameters

-BackupHistory

A dbatools.BackupHistory object containing backup history records

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-RestoreTime

The point in time you want to restore to

Alias
Required False
Pipeline false
Default Value (Get-Date).addmonths(1)
-IgnoreLogs

This switch will cause Log Backups to be ignored. So will restore to the last Full or Diff backup only

Alias
Required False
Pipeline false
Default Value False
-IgnoreDiffs

This switch will cause Differential backups to be ignored. Unless IgnoreLogs is specified, restore to point in time will still occur, just using all available log backups

Alias
Required False
Pipeline false
Default Value False
-DatabaseName

A string array of Database Names that you want to filter to

Alias
Required False
Pipeline false
Default Value
-ServerName

A string array of Server Names that you want to filter

Alias
Required False
Pipeline false
Default Value
-ContinuePoints

The Output of Get-RestoreContinuableDatabase while provides 'Database',redo_start_lsn,'FirstRecoveryForkID' values. Used to filter backups to continue a restore on a database
Sets IgnoreDiffs, and also filters databases to only those within the ContinuePoints object, or the ContinuePoints object AND DatabaseName if both specified

Alias
Required False
Pipeline false
Default Value
-LastRestoreType

The Output of Get-DbaDbRestoreHistory -last
This is used to check the last type of backup to a database to see if a differential backup can be restored

Alias
Required False
Pipeline false
Default Value
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False