< Back

Remove-DbaDbBackupRestoreHistory

Mon Jan 13, 2020 1:17 pm

NAME Remove-DbaDbBackupRestoreHistory



SYNOPSIS

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





SYNTAX

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

[[-SqlCredential] <Pscredential>] [[-KeepDays] <Int>] [[-Database] <System.String[]>] [[-InputObject]

<Microsoft.SqlServer.Management.Smo.Database[]>] [-EnableException <Switch>] [<CommonParameters>]





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).





PARAMETERS

-Database [<System.String[]>]

The database(s) to process. 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



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

Enables piped input from Get-DbaDatabase



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-KeepDays [<Int>]

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



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. You must have sysadmin access and server version must be SQL

Server version 2000 or higher.



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: Delete

Author: IJeb Reitsma



Website: https://dbatools.io

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

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



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



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.



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



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



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



RELATED LINKS

https://dbatools.io/Remove-DbaDbBackupRestoreHistory