commands

^

Test-DbaDbRecoveryModel

Author Claudio Silva (@ClaudioESSilva)
Availability Windows, Linux, macOS

 

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

Synopsis

Find if database is really a specific recovery model or not.

Description

When you switch a database into FULL recovery model, it will behave like a SIMPLE recovery model until a full backup is taken in order to begin a log backup chain.

However, you may also desire to validate if a database is SIMPLE or BULK LOGGED on an instance.

Inspired by Paul Randal's post (http://www.sqlskills.com/blogs/paul/new-script-is-that-database-really-in-the-full-recovery-mode/)

Syntax

Test-DbaDbRecoveryModel
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-SqlCredential] <PSCredential>]
    [[-RecoveryModel] <Object>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Test-DbaDbRecoveryModel -SqlInstance sql2005

Shows all databases where the configured recovery model is FULL and indicates whether or not they are really in FULL recovery model.

Example: 2
PS C:\> Test-DbaDbRecoveryModel -SqlInstance . | Where-Object {$_.ActualRecoveryModel -ne "FULL"}

Only shows the databases that are functionally in 'simple' mode.

Example: 3
PS C:\> Test-DbaDbRecoveryModel -SqlInstance sql2008 -RecoveryModel Bulk_Logged | Sort-Object Server  -Descending

Shows all databases where the configured recovery model is BULK_LOGGED and sort them by server name descending

Example: 4
PS C:\> Test-DbaDbRecoveryModel -SqlInstance localhost | Select-Object -Property *

Shows all of the properties for the databases that have Full Recovery Model

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-Database

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
-ExcludeDatabase

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
-SqlCredential

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
-RecoveryModel

Specifies the type of recovery model you wish to test. By default it will test for FULL Recovery Model.

Alias
Required False
Pipeline false
Default Value
Accepted Values Full,Simple,Bulk_Logged
-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