Below script is from “buwprof”, is there a way to modify so script would wait for one successful backup copy (if fail retry) and then disables the job?
Reason is to stop the job running more than once during a backup cycle when tape job spans more than 24 hrs. By default job stays disabled and this script will trigger the backup.
Thanks.
Code: Select all
------------------------------------------------------------------------------------------------------------------------------------------------
# Get Parameters
param( $job )
# Import Veeam Snapin and we do not want Errors
asnp -Name VeeamPSSnapin -ErrorAction SilentlyContinue
# If we have a JobName then we go further
if ( $job ) {
# JobName here
$jobName = $job
# Get Backup Specs
$backup = Get-VBRBackup -Name $jobName
if ( $backup.JobName ) {
# Get FilePath
$backupfilepath = ( $backup.GetStorages() | ?{$_.GetStorageType() -eq "vbk"} ).FilePath
# Get Directory for deleting
$backupdirpath = ( $backup.GetStorages() | ?{$_.GetStorageType() -eq "vbk"} ).DirPath
# If current active VBK is found on media then media has not been rotated
if ( -not( Test-Path "$backupfilepath" ) ) {
# Current active VBK was not found indicating media has been changed
# First DisableScheduler, If not then the Copy Job will Create a new Directory like $Jobname_1
# Get-Job Object
$CopyJob = Get-VBRJob -Name $jobName
# Disbale Scheduler
$CopyJob.DisableScheduler()
# then Wait until Job is Stopped (and is not running anymore)
while ( -not( $CopyJob.IsStopped() ) ) {
# Do Nothing
}
# If stopped then Delete from VeeamGUI
$backup.Delete()
# Remove Backup Files from Media
if ( Test-Path "$backupdirpath" ) {
# Remove whole Directory
Remove-Item -Path "$backupdirpath" -Recurse
}
# Enable Scheduler
$CopyJob.EnableScheduler()
}
} # UPPS NOT CORRECT JOBNAME - BUT WE ARE SILENT
} # NO JOBNAME given - WE ARE SILENT