< Back
Find-DbaBackup
Post
NAME Find-DbaBackup
SYNOPSIS
Finds SQL Server backups on disk.
SYNTAX
Find-DbaBackup [-Path] <String> [-BackupFileExtension] <String> [-RetentionPeriod] <String> [-CheckArchiveBit
<Switch>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Provides all of the same functionality for finding SQL backups to remove from disk as a standard maintenance plan
would.
As an addition you have the ability to check the Archive bit on files before deletion. This will allow you to
ensure backups have been archived to your archive location before removal.
PARAMETERS
-BackupFileExtension [<String>]
Specifies the filename extension of the backup files you wish to find (typically 'bak', 'trn' or 'log'). Do
not include the period.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CheckArchiveBit [<Switch>]
If this switch is enabled, the filesystem Archive bit is checked.
If this bit is set (which translates to "it has not been backed up to another location yet"), the file won't
be included.
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
-Path [<String>]
Specifies the name of the base level folder to search for backup files.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetentionPeriod [<String>]
Specifies the retention period for backup files. Correct format is ##U.
## is the retention value and must be an integer value
U signifies the units where the valid units are:
h = hours
d = days
w = weeks
m = months
Formatting Examples:
'48h' = 48 hours
'7d' = 7 days
'4w' = 4 weeks
'1m' = 1 month
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: Backup
Author: Chris Sommer (@cjsommer), www.cjsommer.com
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Find-DbaBackup -Path 'C:\\MSSQL\\SQL Backup\\' -BackupFileExtension trn -RetentionPeriod 48h
Searches for all trn files in C:\\MSSQL\\SQL Backup\\ and all subdirectories that are more than 48 hours old will be
included.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Find-DbaBackup -Path 'C:\\MSSQL\\Backup\\' -BackupFileExtension bak -RetentionPeriod 7d -CheckArchiveBit
Searches for all bak files in C:\\MSSQL\\Backup\\ and all subdirectories that are more than 7 days old will be
included, but only if the files have been backed up to another location as verified by checking the Archive bit.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Find-DbaBackup -Path '\\\\SQL2014\\Backup\\' -BackupFileExtension bak -RetentionPeriod 24h | Remove-Item
-Verbose
Searches for all bak files in \\\\SQL2014\\Backup\\ and all subdirectories that are more than 24 hours old and deletes
only those files with verbose message.
RELATED LINKS
https://dbatools.io/Find-DbaBackup
SYNOPSIS
Finds SQL Server backups on disk.
SYNTAX
Find-DbaBackup [-Path] <String> [-BackupFileExtension] <String> [-RetentionPeriod] <String> [-CheckArchiveBit
<Switch>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Provides all of the same functionality for finding SQL backups to remove from disk as a standard maintenance plan
would.
As an addition you have the ability to check the Archive bit on files before deletion. This will allow you to
ensure backups have been archived to your archive location before removal.
PARAMETERS
-BackupFileExtension [<String>]
Specifies the filename extension of the backup files you wish to find (typically 'bak', 'trn' or 'log'). Do
not include the period.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CheckArchiveBit [<Switch>]
If this switch is enabled, the filesystem Archive bit is checked.
If this bit is set (which translates to "it has not been backed up to another location yet"), the file won't
be included.
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
-Path [<String>]
Specifies the name of the base level folder to search for backup files.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-RetentionPeriod [<String>]
Specifies the retention period for backup files. Correct format is ##U.
## is the retention value and must be an integer value
U signifies the units where the valid units are:
h = hours
d = days
w = weeks
m = months
Formatting Examples:
'48h' = 48 hours
'7d' = 7 days
'4w' = 4 weeks
'1m' = 1 month
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: Backup
Author: Chris Sommer (@cjsommer), www.cjsommer.com
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Find-DbaBackup -Path 'C:\\MSSQL\\SQL Backup\\' -BackupFileExtension trn -RetentionPeriod 48h
Searches for all trn files in C:\\MSSQL\\SQL Backup\\ and all subdirectories that are more than 48 hours old will be
included.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Find-DbaBackup -Path 'C:\\MSSQL\\Backup\\' -BackupFileExtension bak -RetentionPeriod 7d -CheckArchiveBit
Searches for all bak files in C:\\MSSQL\\Backup\\ and all subdirectories that are more than 7 days old will be
included, but only if the files have been backed up to another location as verified by checking the Archive bit.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Find-DbaBackup -Path '\\\\SQL2014\\Backup\\' -BackupFileExtension bak -RetentionPeriod 24h | Remove-Item
-Verbose
Searches for all bak files in \\\\SQL2014\\Backup\\ and all subdirectories that are more than 24 hours old and deletes
only those files with verbose message.
RELATED LINKS
https://dbatools.io/Find-DbaBackup