< Back

Set-DbaDbRecoveryModel

Mon Jan 13, 2020 5:36 pm

NAME Set-DbaDbRecoveryModel



SYNOPSIS

Set-DbaDbRecoveryModel sets the Recovery Model.





SYNTAX

Set-DbaDbRecoveryModel [-SqlCredential <Pscredential>] -RecoveryModel <String> [-Database <System.Object[]>]

[-ExcludeDatabase <System.Object[]>] [-AllDatabases <Switch>] [-EnableException <Switch>] [<CommonParameters>]



Set-DbaDbRecoveryModel -SqlInstance <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [-SqlCredential

<Pscredential>] -RecoveryModel <String> [-Database <System.Object[]>] [-ExcludeDatabase <System.Object[]>]

[-AllDatabases <Switch>] [-EnableException <Switch>] [<CommonParameters>]



Set-DbaDbRecoveryModel [-SqlCredential <Pscredential>] -RecoveryModel <String> [-Database <System.Object[]>]

[-ExcludeDatabase <System.Object[]>] [-AllDatabases <Switch>] [-EnableException <Switch>] -InputObject

<Microsoft.SqlServer.Management.Smo.Database[]> [<CommonParameters>]





DESCRIPTION

Set-DbaDbRecoveryModel sets the Recovery Model for user databases.





PARAMETERS

-AllDatabases [<Switch>]

This is a parameter that was included for safety, so you don't accidentally set options on all databases

without specifying



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Database [<System.Object[]>]

The database(s) to process - this list is auto-populated from the server. if unspecified, all databases will

be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeDatabase [<System.Object[]>]

The database(s) to exclude - this list is auto-populated from the server



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]

A collection of databases (such as returned by Get-DbaDatabase)



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RecoveryModel [<String>]

Recovery Model to be set. Valid options are 'Simple', 'Full', 'BulkLogged'



Details about the recovery models can be found here:

https://docs.microsoft.com/en-us/sql/re ... sql-server



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: RecoveryModel, Database

Author: Viorel Ciucu (@viorelciucu), https://www.cviorel.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Set-DbaDbRecoveryModel -SqlInstance sql2014 -RecoveryModel BulkLogged -Database model -Confirm:$true

-Verbose



Sets the Recovery Model to BulkLogged for database [model] on SQL Server instance sql2014. User is requested to

confirm the action.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-DbaDatabase -SqlInstance sql2014 -Database TestDB | Set-DbaDbRecoveryModel -RecoveryModel Simple

-Confirm:$false



Sets the Recovery Model to Simple for database [TestDB] on SQL Server instance sql2014. Confirmation is not

required.

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Set-DbaDbRecoveryModel -SqlInstance sql2014 -RecoveryModel Simple -Database TestDB -Confirm:$false



Sets the Recovery Model to Simple for database [TestDB] on SQL Server instance sql2014. Confirmation is not

required.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Set-DbaDbRecoveryModel -SqlInstance sql2014 -RecoveryModel Simple -AllDatabases -Confirm:$false



Sets the Recovery Model to Simple for ALL uses databases MODEL database on SQL Server instance sql2014. Runs

without asking for confirmation.

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>Set-DbaDbRecoveryModel -SqlInstance sql2014 -RecoveryModel BulkLogged -Database TestDB1, TestDB2

-Confirm:$false -Verbose



Sets the Recovery Model to BulkLogged for [TestDB1] and [TestDB2] databases on SQL Server instance sql2014. Runs

without asking for confirmation.



RELATED LINKS

https://dbatools.io/Set-DbaDbRecoveryModel