commands

^

Remove-DbaDbBackupRestoreHistory

Author IJeb Reitsma
Availability Windows, Linux, macOS

 

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

Synopsis

Reduces the size of the backup and restore history tables by deleting old entries for backup sets.

Description

Reduces the size of the backup and restore history tables by deleting the entries for backup sets.

Can be used at server level, in this case a retention period -KeepDays can be set (default is 30 days).
Can also be used at database level, in this case the complete history for the database(s) is deleted.

The backup and restore history tables reside in the msdb database.

To periodically remove old data from backup and restore history tables it is recommended to schedule the agent job sp_delete_backuphistory from the
SQL Server Maintenance Solution created by Ola Hallengren (https://ola.hallengren.com).

Syntax

Remove-DbaDbBackupRestoreHistory
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-KeepDays] <Int32>]
    [[-Database] <String[]>]
    [[-InputObject] <Database[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Remove-DbaDbBackupRestoreHistory -SqlInstance sql2016

Prompts for confirmation then deletes backup and restore history on SQL Server sql2016 older than 30 days (default period)

Example: 2
PS C:\> Remove-DbaDbBackupRestoreHistory -SqlInstance sql2016 -KeepDays 100 -Confirm:$false

Remove backup and restore history on SQL Server sql2016 older than 100 days. Does not prompt for confirmation.

Example: 3
PS C:\> Remove-DbaDbBackupRestoreHistory -SqlInstance sql2016 -Database db1

Prompts for confirmation then deletes all backup and restore history for database db1 on SQL Server sql2016

Example: 4
PS C:\> Get-DbaDatabase -SqlInstance sql2016 | Remove-DbaDbBackupRestoreHistory -WhatIf

Remove complete backup and restore history for all databases on SQL Server sql2016

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or higher.

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

The number of days of history to keep. Defaults to 30 days.

Alias
Required False
Pipeline false
Default Value 0
-Database

The database(s) to process. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-InputObject

Enables piped input from Get-DbaDatabase

Alias
Required False
Pipeline true (ByValue)
Default Value
-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
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

Alias cf
Required False
Pipeline false
Default Value