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))){
 $fileName=$file.fullname
 $fileModify=$file.lastwritetime
 $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))){
 $fileName=$file.fullname
 $fileModify=$file.lastwritetime
 $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.

Backup Exec 2012 – Removing bkf files from failed jobs

26.01.2013

I have created simple script which finds failed/error backup jobs (Backup Exec 2012) and removes related bkf files from disk (because the files are not valid for restore anymore). The scripts needs to be modified based on your environment. The script also creates basic log (list of failed jobs and removed files) in specified directory. Useful thing could be variable $TimeStamp which give us power to modify time how long we want to go back in BEJobHistory.

Note: The script can be scheduled in Task Scheduler with action Start a Program –  “Program/script:” PowerShell.exe and “Add arguments (optional):”  script file path (e.g. D:\RemovedFiles\RemovingFailedJobFiles.ps1) because of using Import-Module -Name BEMCLI inside.

Download:RemovingFailedJobFiles.ps1

Log example: 26-01-2013-0120-Log.txt

Backup Exec 2012 – Error – (0xE000FED1): A failure occurred querying the Writer status.

26.01.2013

I solved an error and subsequently failed backup jobs in Backup Exec 2012. It occurred only sometimes and for few jobs at once.

Error from BE JobLog:

Job ended: Friday, January 25, 2013 at 4:49:06 PM
Completed status: Failed
Final error: 0xe000fed1 - A failure occurred querying the Writer status.
Final error category: Resource Errors
Snapshot technology error (0xE000FED1): A failure occurred querying the Writer status.

Errors in Windows AppLog:

Log Name: Application
Source: MSExchangeRepl
Date: 1/25/2013 5:29:24 PM
Event ID: 2024
Task Category: Exchange VSS Writer
Level: Error
Keywords: Classic
User: N/A
Description:
The Microsoft Exchange Replication service VSS Writer c59fb6d1-d04f-3c94c3e3fb87 failed with error 80070020 when preparing for a backup.

Log Name: Application
Source: MSExchangeRepl
Date: 1/25/2013 5:29:24 PM
Event ID: 2112
Task Category: Exchange VSS Writer
Level: Error
Keywords: Classic
User: N/A
Description:
The Microsoft Exchange Replication service VSS Writer instance c59fb6d1-d04f-3c94c3e3fb87 failed with error code 80070020 when preparing for a backup of database 'DB02'.

The error was caused by wrong Backup Selection. We had created new mailbox database and BE seemed to automatically added it into already configured selections. Well we took the backup of this database in all backup jobs. Some of those jobs was scheduled at the same time and due to this reason occurred long querying for VSS writer. When I removed the database from the selections the problem was solved.

Backup Exec 2012 – Get-BEJobLog and Get-BEJobLogFiles

26.01.2013

I wanted to get names of bkf files (media) from Get-BEJobLog in Backup Exec 2012. Unfortunately Get-BEJobHistory | Get-BEJobLog outputs only log in string value. Due to this reason I created simple function for obtaining the names for particular media.

  • You cannot use the function for deduplication type of job because of image folder structure.
  • If you want to import  “Backup Exec Management Command Line Interface” into PowerShell session, you need to use  cmdlet Import-Module -Name BEMCLI.

Function Get-BEJobLogFiles

function Get-BEJobLogFiles{
 param ( 
 [Parameter(Mandatory=$True,ValueFromPipeline=$true)]
 [String]$BEJobLog
 )
 $Files = @()
 foreach($Str in $BEJobLog){
 $SplitString = ""
 $SplitString = $Str.Split("`n") | Select-String -Pattern "B2D" -SimpleMatch |sort -Unique
 foreach($Line in $SplitString){
 $StrFile = ""
 $StrFile = $Line.toString()
 $StrFile = $StrFile.Substring($StrFile.indexof(":")+2)
 if($StrFile -ne $null){
 $Files += $StrFile
 }
 } 
 }
 return $Files
}

Download: Get-BEJobLogFiles

If you expect more that one logs (i.e. caused by more Get-BEJobHistory)  you will need to use:

Get-BEJobHistory | Get-BEJobLog | %{ $_ | Get-BEJobLogFiles }

Example:

PS C:\> Get-BEJobHistory | Where-Object {(($_.name -like "*Monthly Full*") -and ($_.JobStatus -like "Succeeded") -and ($
_.StartTime -gt (get-date).adddays(-2)))} | Get-BEJobLog | %{ $_ | Get-BEJobLogFiles }
B2D002673
B2D002675
B2D002677
B2D002679
B2D002683
B2D002684
B2D002685
B2D002686
B2D002688
B2D002690
B2D002692
B2D002694
B2D002695
B2D002696
B2D002697
B2D002708
B2D002709
B2D002710
B2D002713
B2D002711
B2D002715
B2D002717
B2D002719
B2D002712
B2D002714
B2D002716
B2D002718

How to find related media on disk? Example below could help you. Please ignore related names for variables because it is used from different script:

# Retention period 
$Retention = -8

# Backup Exec Storages
$DiskE = "E:\BEData"
$DiskG = "G:\BEData"
$DiskH = "H:\BEData"

# Backup Selection (Error Job)
$ErrorJobsMedia = Get-BEJobHistory | Where-Object {(($_.name -like "*Monthly Full*") -and ($_.JobStatus -like "Succeeded") -and ($_.StartTime -gt (get-date).adddays(-2)))} | Get-BEJobLog | %{ $_ | Get-BEJobLogFiles }

# File Selection
$BackupStorages = @()
$BackupStorages += Get-ChildItem -path $DiskE | where-object {$_.Name -like "*.bkf"}
$BackupStorages += Get-ChildItem -path $DiskG | where-object {$_.Name -like "*.bkf"}
$BackupStorages += Get-ChildItem -path $DiskH | where-object {$_.Name -like "*.bkf"}

# Backup files determination
$BackupFiles = @()
foreach ($ErrorJobsMed in $ErrorJobsMedia){
 foreach ($BckFile in $BackupStorages){
 $BckFileTemp = ($BckFile.name).toString()
 $BckFileTemp = $BckFileTemp.substring(0,$BckFileTemp.indexof("."))
 if($ErrorJobsMed -match $BckFileTemp){
 $BackupFiles += $BckFile
 } 
 }
}
PS C:\> $BackupFiles | select fullname

FullName
--------
H:\BEData\B2D002673.bkf
H:\BEData\B2D002675.bkf
H:\BEData\B2D002677.bkf
H:\BEData\B2D002679.bkf
H:\BEData\B2D002683.bkf
H:\BEData\B2D002684.bkf
G:\BEData\B2D002685.bkf
G:\BEData\B2D002686.bkf
G:\BEData\B2D002688.bkf
G:\BEData\B2D002690.bkf
G:\BEData\B2D002692.bkf
G:\BEData\B2D002694.bkf
G:\BEData\B2D002695.bkf
G:\BEData\B2D002696.bkf
G:\BEData\B2D002697.bkf
E:\BEData\B2D002708.bkf
E:\BEData\B2D002709.bkf
E:\BEData\B2D002710.bkf
E:\BEData\B2D002713.bkf
H:\BEData\B2D002711.bkf
H:\BEData\B2D002715.bkf
H:\BEData\B2D002717.bkf
H:\BEData\B2D002719.bkf
G:\BEData\B2D002712.bkf
G:\BEData\B2D002714.bkf
G:\BEData\B2D002716.bkf
G:\BEData\B2D002718.bkf