Get-SqlBackupHistory

Gets backup information about databases and returns SMO BackupSet objects for each Backup record found based on the parameters specified to this cmdlet.

Syntax

Get-SqlBackupHistory
   [-Since <SinceType>]
   [-StartTime <DateTime>]
   [-EndTime <DateTime>]
   [-BackupType <BackupSetType>]
   [-IncludeSnapshotBackups]
   [-TimeSpan <TimeSpan>]
   [-IgnoreProviderContext]
   [-SuppressProviderContextWarning]
   [[-Path] <String[]>]
   [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
   [<CommonParameters>]
Get-SqlBackupHistory
   [-Since <SinceType>]
   [-StartTime <DateTime>]
   [-EndTime <DateTime>]
   [-BackupType <BackupSetType>]
   [-IncludeSnapshotBackups]
   [-TimeSpan <TimeSpan>]
   [-IgnoreProviderContext]
   [-SuppressProviderContextWarning]
   [[-ServerInstance] <String[]>]
   [-Credential <PSCredential>]
   [-ConnectionTimeout <Int32>]
   [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
   [<CommonParameters>]
Get-SqlBackupHistory
   [-Since <SinceType>]
   [-StartTime <DateTime>]
   [-EndTime <DateTime>]
   [-BackupType <BackupSetType>]
   [-IncludeSnapshotBackups]
   [-TimeSpan <TimeSpan>]
   [-IgnoreProviderContext]
   [-SuppressProviderContextWarning]
   [-InputObject] <Server[]>
   [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
   [<CommonParameters>]

Description

This cmdlet searches the server instance and gets the backup records as SMO BackupSet objects for all the records found matching the specified parameters.

Examples

Example 1

PS C:\> Get-SqlBackupHistory -ServerInstance test-server -DatabaseName AdventureWorks2014

Name                                     Type               Backup Start Date         Backup Finish Date
----                                     ----               -----------------         ------------------
AdventureWorks2014-Full Database Backup  Database           2/21/2017 7:52:39 PM      2/21/2017 7:52:40 PM
AdventureWorks2014-Full Database Backup  Database           3/20/2017 2:41:39 PM      3/20/2017 2:41:39 PM
AdventureWorks2014-Full-2017-07-24T22:22 Database           7/24/2017 3:23:11 PM      7/24/2017 3:23:11 PM

This example gets records for all backup types for AdventureWorks2014 database on test-server SQL instance.

Parameters

-BackupType

The type of backup to filter on. If not specified then gets all backup types. Accepted values are defined below.

Type:BackupSetType
Accepted values:Database, Differential, Incremental, Log, FileOrFileGroup, FileOrFileGroupDifferential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ConnectionTimeout

The time to wait in seconds for a connection to be established and the dynamically generated -DatabaseName parameter to be populated.

Type:Int32
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Credential

The PSCredential object whose username and password fields are used to connect to the SQL instance.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DatabaseName

The names of the databases whose backup records are to be retrieved. This is a dynamically populated field and so provides auto-complete suggestions on database names.

Type:System.Collections.Generic.List`1[System.String]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-EndTime

The time before which all backup records to be retrieved should have completed.

Type:DateTime
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-IgnoreProviderContext

Indicates that this cmdlet does not use the current context to override the values of the ServerInstance, DatabaseName parameters. If you do not specify this parameter, the cmdlet ignores the values of these parameters, if possible, in favor of the context in which you run the cmdlet.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-IncludeSnapshotBackups

This switch will make the cmdlet obtain records for snapshot backups as well. By default such backups are not retrieved.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InputObject

Specifies SMO Server objects to get the backup records for.

Type:Server[]
Position:1
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Path

Specifies the SQL provider path to either a server instance or a database for this cmdlet to use to obtain BackupSets for. If not specified uses the current working location.

Type:String[]
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ServerInstance

The name of the server instances which this cmdlet will target.

Type:String[]
Position:1
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Since

Specifies an abbreviation that you can instead of the StartTime parameter.

It can be specified with the EndTime parameter.

You cannot use the StartTime parameter, if you use this parameter.

The acceptable values for this parameter are:

  • Midnight (gets all the job history information generated after midnight)
  • Yesterday (gets all the job history information generated in the last 24 hours)
  • LastWeek (gets all the job history information generated in the last week)
  • LastMonth (gets all the job history information generated in the last month)
Type:SinceType
Accepted values:Midnight, Yesterday, LastWeek, LastMonth
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-StartTime

Gets the backup records which started after this specified time.

Type:DateTime
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-SuppressProviderContextWarning

Suppresses the warning when the cmdlet is using the provider context.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-TimeSpan

If specified, it causes the cmdlet to filter records generated more than 'Timespan' ago.

Type:TimeSpan
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

System.String[]

Microsoft.SqlServer.Management.Smo.Server[]

Outputs

System.Object