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.
Returns backup history details for databases on a SQL Server.
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
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>]
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.
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"
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.
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.
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last
Returns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014.
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.
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.
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -LastFull
Returns information about the most recent full backup for AdventureWorks2014 on sql2014.
PS C:\> Get-DbaDbBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Type Full
Returns information about all Full backups for AdventureWorks2014 on sql2014.
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.
PS C:\> Get-DbaDbBackupHistory -SqlInstance SqlInstance2014a, sql2016 -Force
Returns detailed backup history for all databases on SqlInstance2014a and sql2016.
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.
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 |
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 |
Specifies one or more database(s) to process. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies one or more database(s) to exclude from processing.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
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 |
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') |
Specifies the Recovery Fork you want backup history for.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
If this switch is enabled, the most recent full backup set is returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, the most recent differential backup set is returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, the most recent log backup is returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
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 |
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 |
By default mirrors of backups are not returned, this switch will cause them to be returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
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 |
When this switch is enabled, Differential backups will be ignored.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
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 |
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 |