commands

^

Get-DbaDbBackupHistory

Author Chrissy LeMaire (@cl) , Stuart Moore (@napalmgram)
Availability Windows, Linux, macOS

 

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

Synopsis

Returns backup history details for databases on a SQL Server.

Description

Returns backup history details for some or all databases on a SQL Server.

You can even get detailed information (including file path) for latest full, differential and log files.

Backups taken with the CopyOnly option will NOT be returned, unless the IncludeCopyOnly switch is present.

Reference: http://www.sqlhub.com/2011/07/find-your-backup-history-in-sql-server.html

Syntax

Get-DbaDbBackupHistory -SqlInstance <DbaInstanceParameter[]>
    [-SqlCredential <PSCredential>]
    [-Database <Object[]>]
    [-ExcludeDatabase <Object[]>]
    [-IncludeCopyOnly]
    [-Since <PSObject>]
    [-RecoveryFork <String>]
    [-Last]
    [-LastFull]
    [-LastDiff]
    [-LastLog]
    [-DeviceType <String[]>]
    [-Raw]
    [-LastLsn <BigInteger>]
    [-IncludeMirror]
    [-Type <String[]>]
    [-AgCheck]
    [-IgnoreDiffBackup]
    [-LsnSort <String>]
    [-EnableException]
    [<CommonParameters>]

Get-DbaDbBackupHistory -SqlInstance <DbaInstanceParameter[]>
    [-SqlCredential <PSCredential>]
    [-Database <Object[]>]
    [-ExcludeDatabase <Object[]>]
    [-IncludeCopyOnly]
    [-Force]
    [-Since <PSObject>]
    [-RecoveryFork <String>]
    [-Last]
    [-LastFull]
    [-LastDiff]
    [-LastLog]
    [-DeviceType <String[]>]
    [-Raw]
    [-LastLsn <BigInteger>]
    [-IncludeMirror]
    [-Type <String[]>]
    [-AgCheck]
    [-IgnoreDiffBackup]
    [-LsnSort <String>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaDbBackupHistory -SqlInstance SqlInstance2014a

Returns server name, database, username, backup type, date for all database backups still in msdb history on SqlInstance2014a. This may return many rows; consider using filters that are included in
other examples.

Example: 2
PS C:\> $cred = Get-Credential sqladmin

Get-DbaDbBackupHistory -SqlInstance SqlInstance2014a -SqlCredential $cred
Does the same as above but connect to SqlInstance2014a as SQL user "sqladmin"

Example: 3
PS C:\> Get-DbaDbBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since '2016-07-01 10:47:00'

Returns backup information only for databases db1 and db2 on SqlInstance2014a since July 1, 2016 at 10:47 AM.

Example: 4
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force | Format-Table

Returns information only for AdventureWorks2014 and pubs and formats the results as a table.

Example: 5
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last

Returns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014.

Example: 6
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType Disk

Returns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but only for backups to disk.

Example: 7
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType 148,107

Returns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but only for backups with device_type 148 and 107.

Example: 8
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -LastFull

Returns information about the most recent full backup for AdventureWorks2014 on sql2014.

Example: 9
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Type Full

Returns information about all Full backups for AdventureWorks2014 on sql2014.

Example: 10
PS C:\> Get-DbaRegServer -SqlInstance sql2016 | Get-DbaDbBackupHistory

Returns database backup information for every database on every server listed in the Central Management Server on sql2016.

Example: 11
PS C:\> Get-DbaDbBackupHistory -SqlInstance SqlInstance2014a, sql2016 -Force

Returns detailed backup history for all databases on SqlInstance2014a and sql2016.

Example: 12
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2016 -Database db1 -RecoveryFork 38e5e84a-3557-4643-a5d5-eed607bef9c6 -Last

If db1 has multiple recovery forks, specifying the RecoveryFork GUID will restrict the search to that fork.

Required Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

Credential object used to connect to the SQL Server instance as a different user. This can be a Windows or SQL Server account. Windows users are determined by the existence of a backslash, so if you are intending to use an alternative Windows connection instead of a SQL login, ensure it contains a backslash.

Alias
Required False
Pipeline false
Default Value
-Database

Specifies one or more database(s) to process. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

Specifies one or more database(s) to exclude from processing.

Alias
Required False
Pipeline false
Default Value
-IncludeCopyOnly

By default Get-DbaDbBackupHistory will ignore backups taken with the CopyOnly option. This switch will include them.

Alias
Required False
Pipeline false
Default Value False
-Force

If this switch is enabled, a large amount of information is returned, similar to what SQL Server itself returns.

Alias
Required False
Pipeline false
Default Value False
-Since

Specifies a starting point for the search for backups. If a DateTime object is passed, that will be used. If a TimeSpan object is passed, that will be added to Get-Date and the resulting value will be used.

Alias
Required False
Pipeline false
Default Value (Get-Date '01/01/1970')
-RecoveryFork

Specifies the Recovery Fork you want backup history for.

Alias
Required False
Pipeline false
Default Value
-Last

If this switch is enabled, the most recent full chain of full, diff and log backup sets is returned.

Alias
Required False
Pipeline false
Default Value False
-LastFull

If this switch is enabled, the most recent full backup set is returned.

Alias
Required False
Pipeline false
Default Value False
-LastDiff

If this switch is enabled, the most recent differential backup set is returned.

Alias
Required False
Pipeline false
Default Value False
-LastLog

If this switch is enabled, the most recent log backup is returned.

Alias
Required False
Pipeline false
Default Value False
-DeviceType

Specifies a filter for backup sets based on DeviceType. Valid options are 'Disk','Permanent Disk Device', 'Tape', 'Permanent Tape Device','Pipe','Permanent Pipe Device','Virtual Device','URL', in addition to custom integers for your own DeviceType.

Alias
Required False
Pipeline false
Default Value
-Raw

If this switch is enabled, one object per backup file is returned. Otherwise, media sets (striped backups across multiple files) will be grouped into a single return object.

Alias
Required False
Pipeline false
Default Value False
-LastLsn

Specifies a minimum LSN to use in filtering backup history. Only backups with an LSN greater than this value will be returned, which helps speed the retrieval process.

Alias
Required False
Pipeline false
Default Value
-IncludeMirror

By default mirrors of backups are not returned, this switch will cause them to be returned.

Alias
Required False
Pipeline false
Default Value False
-Type

Specifies one or more types of backups to return. Valid options are 'Full', 'Log', 'Differential', 'File', 'Differential File', 'Partial Full', and 'Partial Differential'. Otherwise, all types of backups will be returned unless one of the -Last* switches is enabled.

Alias
Required False
Pipeline false
Default Value
Accepted Values Full,Log,Differential,File,Differential File,Partial Full,Partial Differential
-AgCheck

Deprecated. The functionality to also get the history from all replicas if SqlInstance is part on an availability group has been moved to Get-DbaAgBackupHistory.

Alias
Required False
Pipeline false
Default Value False
-IgnoreDiffBackup

When this switch is enabled, Differential backups will be ignored.

Alias
Required False
Pipeline false
Default Value False
-LsnSort

Specifies which of the returned LSN values you would like to use for sorting when using the LastFull, LastDiff and LastLog parameters.

Alias
Required False
Pipeline false
Default Value LastLsn
Accepted Values FirstLsn,DatabaseBackupLsn,LastLsn
-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