Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaDbRestoreHistory on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaDbRestoreHistory.
Returns restore history details for databases on a SQL Server.
By default, this command will return the server name, database, username, restore type, date, from file and to files.
Thanks to https://www.mssqltips.com/SqlInstancetip/1724/when-was-the-last-time-your-sql-server-database-was-restored/ for the query and https://sqlstudies.com/2016/07/27/when-was-this-database-restored/ for the idea.
Get-DbaDbRestoreHistory
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <Object[]>]
[[-ExcludeDatabase] <Object[]>]
[[-Since] <DateTime>]
[-Force]
[-Last]
[[-RestoreType] <String>]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-DbaDbRestoreHistory -SqlInstance sql2016
Returns server name, database, username, restore type, date for all restored databases on sql2016.
PS C:\> Get-DbaDbRestoreHistory -SqlInstance sql2016 -Database db1, db2 -Since '2016-07-01 10:47:00'
Returns restore information only for databases db1 and db2 on sql2016 since July 1, 2016 at 10:47 AM.
PS C:\> Get-DbaDbRestoreHistory -SqlInstance sql2014, sql2016 -Exclude db1
Returns restore information for all databases except db1 on sql2014 and sql2016.
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Get-DbaDbRestoreHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -SqlCredential $cred | Format-Table
Returns database restore information for AdventureWorks2014 and pubs database on sql2014, connects using SQL Authentication via sqladmin account. Formats the data as a table.
PS C:\> Get-DbaRegServer -SqlInstance sql2016 | Get-DbaDbRestoreHistory
Returns database restore information for every database on every server listed in the Central Management Server on sql2016.
PS C:\> Get-DbaDbRestoreHistory -SqlInstance sql2016 -RestoreType Log
Returns log restore information for every database on the sql2016 instance.
Specifies the SQL Server instance(s) to operate on. Requires SQL Server 2005 or higher.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the database(s) to process. Options for this list are auto-populated from the server. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the database(s) to exclude from processing. Options for this list are auto-populated from the server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies a datetime to use as the starting point for searching backup history.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Deprecated.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, the last restore action performed on each database is returned.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Return the history for a specific type of restore. The possible values are 'Database', 'File', 'Filegroup', 'Differential', 'Log', 'Verifyonly', 'Revert'. This is an optional parameter so there is no
default value.
Alias | |
Required | False |
Pipeline | false |
Default Value | |
Accepted Values | Database,File,Filegroup,Differential,Log,Verifyonly,Revert |
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 |