Backup Exec – Removing BKF Files By Script

Sometimes we need to remove bkf files from disk manually due to the media set “Keep Data Infinitely – Do Not Allow Overwrite” in Backup Exec. Zbynek has created a script for that purpose and here is my extended version.

# Variables for reporting
$date = get-date -format "dd-MM-yyyy-hhss"
$rep = "D:\RemovedBKFfiles\$date-Log.txt"

# Incremental variables (retention period and source folder)
$retentionIncremental = -7 #(it means seven days back)
$folderIncremental = "I:\BEData"

# WeeklyFull variables (retention period and source folder)
$retentionWeeklyFull = -27
$folderWeeklyFull = "J:\BEData"

# function RemoveBkfFiles
function RemoveBkfFiles ($folder,$retention,$report) {
 $files = @()
 $files = Get-Childitem -literalpath $folder | where-object {$_.Extension -like ".bkf"}
 Foreach ($file in $files) 
 if (($file -ne $null) -and ($file.lastwritetime -gt (get-date).AddDays($retention))){
 $text="$fileName modified $fileModify - Stays on drive."
 $text | out-file -filepath $report -append
 if (($file -ne $null) -and ($file.lastwritetime -lt (get-date).AddDays($retention))){
 $text="$fileName modified $fileModify - Will be deleted - retention is over." 
 $text | out-file -filepath $report -append
 get-item $file.fullname | Remove-Item -force # file is deleted here!!

# Calling the function
RemoveBkfFiles $folderIncremental $retentionIncremental $rep
RemoveBkfFiles $folderWeeklyFull $retentionWeeklyFull $rep

The function RemoveBkfFiles expect to get parameters: source folder (location for bkf files), retention period (how old the bkf file should be remove), destination file for txt report. So its calling could be also:

RemoveBkfFiles "I:\BEData" "-7" "D:\RemovedBKFfiles\Test-Log.txt"

Report looks like the following:

Removed-BKF_filesFeel free to update the script according to your needs and let us know if you have any question.