1
\$\begingroup\$

I created a simple script to monitor the backup process for veeam, script accept only drives that should be on current days (to avoid override of data), monitor 2 backup jobs. Definitely could be done better, please suggest something to improve performance or tip with good practices.

    #Mon  Z1Z2E34C
#Teu  WD-WCC5D2TSV3P1
#We   WD-WCC132VE1XAN
#Thu  WD-WCC4E1615112
#week WD-WCC131092470
$disks = @('Z1Z2E34C', 'WD-WCC5D2TSV3P1', 'WD-WCC132VE1XAN', 'WD-WCC4E1615112', 'weekly')
$day = @("Monday", "Tuesday", "Wendsday", "Thursday", "Weekly")
$jobname = "Copy Job - Backup_Job_RITZ-CFS01 Removable"
$jobname2 = "Copy Job - Data Stores - Daily - Removable"
$job = get-vbrjob -name $jobname
$job2 = get-vbrjob -name $jobname2
function Progress {
    #cls
    Do {
        $JobStatus1 = ($job.GetLastState())
        $JobStatus2 = ($job2.GetLastState())
        Write-Host 'waiting for Veem to start backup'
        Start-Sleep 4
        Clear-Host
    } Until($JobStatus1 -eq 'Starting' -or $JobStatus1 -eq 'Working')
    Do {
        $i = $job.FindLastSession().BaseProgress
        $JobStatus1 = ($job.GetLastState())
        $text = "Running Job:  $job Status: $JobStatus1"
        Write-Progress -Activity $text -Status "$i% Complete:" -PercentComplete $i -Id 1
        $i2 = $job2.FindLastSession().BaseProgress
        $JobStatus2 = ($job2.GetLastState())
        $text2 = "Running Job:  $job2 Status: $JobStatus2"
        Write-Progress -Activity $text2 -Status "$i2% Complete:" -PercentComplete $i2 -Id 2
    }Until (($i -eq 100 -and $JobStatus1 -eq "Idle") -and ($i2 -eq 100 -and $JobStatus2 -eq "Idle"))
}
function FormatDisk {
    $x = Get-Disk | Where-Object SerialNumber -match $currentDisk | Select-Object Number -ExpandProperty Number
    Initialize-Disk -Number $x
    Clear-Disk -Number $x -RemoveData -Confirm:$false
    Initialize-Disk -Number $x
    New-Partition –DiskNumber $x –UseMaximumSize -DriveLetter E
    Format-Volume -DriveLetter E -FileSystem NTFS -AllocationUnitSize 65536 -NewFileSystemLabel $timestamp
    New-Item -Path "E:\" -Name "VeeamExtract" -ItemType "directory"
    New-Item -Path "E:\" -Name "VeeamBackups" -ItemType "directory"
    cmd /c "Net Share RemovableDrive=E:\ /grant:Everyone,Full"
    Copy-Item "C:\Program Files\Veeam\Backup and Replication\Backup\Extract.exe" -Destination "E:\VeeamExtract"
    Copy-Item "C:\Program Files\Veeam\Backup and Replication\Backup\Veeam.Backup.Extractor.exe" -Destination "E:\VeeamExtract"
}
While ($true) {
    foreach ($disk in $disks) {
        $currentDisk = $disk
        $currentDay = $day.item($disks.IndexOf($disk))
        if ( $disks.IndexOf($disk) -eq $disks.Count - 1) {
            $nextDisk = $disks[0]
            $nextDay = $day[0]
        }
        else {
            $nextDisk = $disks.Item($disks.IndexOf($disk) + 1)
            $nextDay = $day.Item($disks.IndexOf($disk) + 1)
        }
        Do {
            $disksUID = @(Get-Disk | Select-Object SerialNumber)
            $timestamp = Get-Date -UFormat "%d/%m/%Y"
            Clear-Host
            Write-Host 'waiting for disk ' $currentDisk '('$currentDay')'
            Start-Sleep 5
        } Until (($disksUID -match $disk) -or ($disk -eq "weekly"))
        #cls
        Write-Host 'Current disk ID: '$currentDisk '('$currentDay')'
        Write-Host 'next disk ID: '$nextDisk '('$nextDay')'
        FormatDisk
        Progress
        cls
        Write-Host $x
        Set-Disk -Number $x -IsOffline $True
    }
}
\$\endgroup\$
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.