Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Startet ein Veeam VBR Job
- .DESCRIPTION
- Startet einen VBR Job basierend auf den Job-Namen.
- Ursprünglicher Zweck war einen Job (z.B. als Pre-Execution Skript) mit anderen Jobs zu verketten.
- .PARAMETER JobName
- Eingabe des Jobs als Namen
- .PARAMETER JobType
- Typ des Backup Jobs
- Erlaubte Typen: VAW, VAL, VMware,
- Nicht erlaubte: Typen: HyperV, PVE
- Backup Typ Pretty Name Verbose Typ im Skript Notizen
- ########################################################################################################
- Backup Copy Job Backup Copy SimpleBackupCopyPolicy / /
- VAW Managed SRV Windows Agent Backup EpAgentBackup VAW CMDlet deprecated for Agent backups
- VAW Managed PC Windows Agent Policy EpAgentPolicy VAW CMDlet deprecated for Agent backups
- VAL Managed SRV Linux Agent Backup EpAgentBackup VAL CMDlet deprecated for Agent backups
- VAL Managed PC Linux Agent Policy EpAgentPolicy VAL CMDlet (probably) deprecated for Agent backups # UNGETESTET WERTE!
- Proxmox VE Proxmox Backup VmbApiPolicyTempJob PVE Aktuell nicht nutzbar mit Powershell via Start-VBRJob
- VMware VMware Backup Backup Backup VMware
- Hyper-V
- .EXAMPLE
- .\Start-VeeamJob.ps1 -JobName "L1 Backup SERVER" -JobType "VMware"
- Übergibt die Werte "L1 Backup SERVER" und "VMware" an das Skript
- .NOTES
- Author : Appoxo
- Version : 2.4
- Anmerkungen: Im Veeam Forum wird von Jobs verketten abgeraten -> https://forums.veeam.com/kvm-rhv-olvm-proxmox-f62/proxmox-issues-t95239.html#p526738
- Job-Type und Job-ID auslesen: Get-VBRBackup | Select-Object -Property Name,TypeToString,JobType,Jobid,id,uid | Format-Table -AutoSize
- .LINK
- -
- #>
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory = $true,
- HelpMessage = "Enter Job-Name of the VBR-Job")]
- [String]
- $JobName,
- [Parameter(Mandatory = $true,
- HelpMessage = "Art des VBR-Jobs. Die Bezichnung ist NICHT canse-sensitiv!")]
- [ValidateSet("VAW","VAL","VMware")] #Tab Vervollständigung der möglichen Werte
- [string[]]
- $JobType
- )
- Begin {
- Write-Host "Script started successfully"
- $ExitCode = 0
- #TimeStamp Logging:
- function Get-TimeStamp {"{0:yyyy-MM-dd} {0:HH:mm:ss}" -f (Get-Date)}
- <#
- #Debug Values:
- $JobName = "L1 Backup Appoxo-PC2 (Games)"
- $JobType = "VAW"
- #>
- # Variablen
- $workingDir = "C:\Skripte\SkriptLogs"
- $log = "$($workingDir)\Log-StartVeeamJob.log"
- $JobDetails = Get-VBRBackup -Name $JobName
- $timeout = 9
- # Vorbereitung
- if ($JobType -in @("VAW","VAL","VMware")){
- Write-Host "Valid backup type selected"
- $JobTypUnbestimmt = 0
- }
- else {
- Write-Host "Invalid backup type selected. Please choose something else :)"
- $ExitCode = 1
- exit $ExitCode
- }
- if (Test-Path -Path $workingDir) {
- } else {
- New-Item -ItemType Directory -Path "$workingDir"
- }
- if (-not (Test-Path -Path $log -PathType Leaf)) {
- New-Item -ItemType file -Path $log
- Add-Content -Path $log "Log zur Überprüfung der Start von VBR-Jobs"
- }
- }
- Process {
- Write-Host "You passed the following information:"
- $data = @([PSCustomObject]@{"Selected Job Type"="$($JobType)";"Job Details"="$($JobDetails.Name)"})
- $data | Format-Table -AutoSize
- Write-Host "The following Job-ID was found for this job: $($JobDetails.JobId)"
- Write-Host "If there is an error please abort NOW."
- while ($timeout -gt 0) {
- Write-Host -NoNewline "`rThe backup starts in $($timeout)"
- Start-Sleep -Seconds 1
- $timeout--
- }
- Write-Host "`nStarting backup now!"
- Write-Output "$(Get-TimeStamp) Start des Backup Job Skripts. Für den Job '$($JobDetails.Name)' wurde die Job-ID $($JobDetails.JobId) gefunden!" | Add-Content -Path $log
- try{
- $startTime = Get-Date
- Write-Host "Validating input... This may take a while"
- if((($JobType -in @("VAW","VAL"))) -AND (($JobDetails.JobType -in @("EpAgentBackup","EpAgentPolicy")))) {
- Write-Host "Valid backup type '$($JobDetails.TypeToString)' was found. Starting now!"
- Start-VBRComputerBackupJob -Job $JobName | Select-Object -OutVariable JobResult
- }
- elseif (($JobType -in @("VMware")) -AND (($JobDetails.JobType -in @("Backup")))) {
- Write-Host "Valid backup type '$($JobDetails.TypeToString)' was found. Starting now!"
- Start-VBRJob -Job $JobName | Select-Object -OutVariable JobResult
- }
- elseif (($JobType -in @("PVE")) -AND (($JobDetails.JobType -in @("VmbApiPolicyTempJob")))) {
- Write-Host "Der Job des Typs $JobType ist aktuell nicht implementiert"
- $ExitCode = 1
- exit $ExitCode
- <#
- Write-Host "Valid backup type '$($JobDetails.TypeToString)' was found. Starting now!"
- Start-VBRJob -Job $JobName | Select-Object -OutVariable JobResult
- #>
- }
- else {
- Write-Host "Invalid backup type '$($JobDetails.TypeToString)' was found. Please restart the script!"
- Write-Output "$(Get-TimeStamp) Bestimmung des Typs für den Job '$($JobDetails.Name)' nicht erfolgreich. Angegeben wurde '$($JobType)'" | Add-Content -Path $log
- $ExitCode = 1
- $JobTypUnbestimmt = 1
- }
- # Job Result report
- if(($JobTypUnbestimmt -EQ 0) -AND ($JobResult.State -EQ "Stopped") -AND ($JobResult.Result -EQ "Success")){
- Write-Host "Execution of the Job '$($JobName) was successful"
- Write-Output "$(Get-TimeStamp) Backup Job $($JobDetails.Name) erfolgreich ausgeführt" | Add-Content -Path $log
- $ExitCode = 0
- } else{
- Write-Host "Execution of the Job '$($JobName) encountered an error. Please check the VBR-Console for more information"
- Write-Output "$(Get-TimeStamp) Fehler beim ausführen vom Backup Job '$($JobDetails.Name)'" | Add-Content -Path $log
- $ExitCode = 1
- }
- #Stats
- $endTime = Get-Date
- $executionTime = $endTime - $startTime
- } catch {
- Write-Host "Something went wrong during execution"
- Write-Host $_ # This prints the actual error
- Write-Output "$(Get-TimeStamp) Error: $($_)" | Add-Content -Path $log
- $ExitCode = 1
- }
- }
- End {
- Write-Output "$(Get-TimeStamp) Skript abgeschlossen für $($JobDetails.Name) Job-ID $($JobDetails.Id)" | Add-Content -Path $log
- Write-Host "Script ended."
- 'Time for stats! The script took {0:N2} seconds or {1:N2} minutes)' -f $executionTime.TotalSeconds, ($executionTime.TotalSeconds / 60) | Write-Host #Suggestion from: https://www.reddit.com/r/PowerShell/comments/1gi6a2g/comment/lv3wcoa
- exit $ExitCode
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement