To fix this I spent a good chunk of time and wrote a Powershell script that should take care of these types of request automatically. Long story short... This will run a "quick backup" or a "full job", email you with the start results, and then email you again once the backup has finished. To automate this simply setup a scheduled task in taskmgr with the parameters and set a time to run. It will do the rest.
I am no expert in Powershell and I am sure there is a better way with some of my code so feel free to add to it if it can be improved. Just be sure to post so we all benifit.
Code: Select all
<#
.SYNOPSIS
This script is used with Windows Scheduled on the main VBR server to tasks to take "quick backups" of individual VMs and "whole job" at scheduled times
.DESCRIPTION
This was built to compensate for the lack of individual VM and one time scheduled job backups. This allows a "quick backup" or "whole job" to have a one time seperate run time other than when it normally runs.
Furthermore this sends notifications via email so you don't have to go to the console to check wither it started and wither it finished. Setup in scheduled task and its ready to go.
.PARAMETER VM
-VM
A single Computer or an array of computer names. Seperate with comma.
.PARAMETER Job
-job
This is for a whole job backup. Use quotes and comma for more than one
.PARAMETER TO
-to
This is the email address to send the notifications to. This is required as this is the only way the script alerts. There are not outputs when this script is run.
.EXAMPLE
Backup one VM
PS C:\> veeam_quick_backup.ps1 -vm "server1" -to email@address
Backing up several VMs
PS C:\> veeam_quick_backup.ps1 -vm "server1","server2" -to email@address
##For the scheduled task in windows it would be setup as such. See internet examples for setting up a details on setting up a powershell script for a scheduled task.##
<Command>powershell.exe</Command>
<Arguments>-file C:\scripts\test\Veeam_Quick_Backup_automate.ps1 -vm servername -to email@address</Arguments>
This will start the quick backup and send an email out stating wither it was successfull or not
.EXAMPLE
Backing up one full job
PS C:\> veeam_quick_backup.ps1 -job "Exchange servers" -to email@address
Backing several jobs
PS C:\> veeam_quick_backup.ps1 -job "Exchange servers","AD servers","SQL Servers" -to email@address
.NOTES
Author: Aaron Belisle
Email: PM me via forum
Date: 10AUG2018
PSVer: 2.0/3.0/4.0/5.0
Updated: 24AUG2018
V2 - Added logic for emailing results of the backup out to the user. This was accomplished with DO/Then statements
V2.1 - Added | ft -hidetableheaders to select states gathering objectIDs as it was adding a header for GUID
Even with -expandproperty option
V2.2 - Bug fixes and cleanup
1. Removed double IFs in job and VM section as elseif will handle the progression
2. For Job section, I added code to email if the name is not valid and then not progress with the script.
V3 -Rebuild job section fixing checks and cleaning up IFs. I also had to add foreach to pull the status for each job if there were multiples so it send one email with all job results.
Rewrote Job processing to help with efficientcy.
#>
#Parameters that are passed
Param
([parameter(ValueFromPipeLineByPropertyName = $true, Mandatory = $false)][string[]]$vm,
[parameter(ValueFromPipeLineByPropertyName = $true, Mandatory = $false)][string[]]$job,
[parameter(ValueFromPipeLineByPropertyName = $true, Mandatory = $true)][string[]]$to
)
#Variables for Script
#-----------------------
#server Info
$Veeam_Server = "VBR Server"
#email Info
$from = "Email@From.local"
$smtp_server = "SMTPserver"
#---------------------------------------
#start collection bucket for outputs going to email for the start of jobs and the status of the start
$output = @()
#----------------------------------------------------------------------------
#Loading Veeam Snapin Piece and Veeam Connection to the server - If it is not registered it tells you and stops the script. Once the Snappin is loaded it trys to connect to the VBR Server
If (!(Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue)) {
If (!(Add-PSSnapin -PassThru VeeamPSSnapIn)) {
$Output += "****Automated Scheduled VM backup failed. Unable to load Veeam snapin needed to run script***"
$body = $output |Out-String
Send-MailMessage -to $to -from $from -SmtpServer $smtp_server -Body $body -Subject "***Automated Scheduled VM backup was unsuccessful - See Below***"
Exit
}
}
#This trys a simple commmand to see if we are already connected to the VBR server. If it fails the commmand, then it tries to connect. Uses hashed creds
try {
((Get-VBRServer -name $Veeam_Server -ErrorAction SilentlyContinue) -eq $null)*>$null
}
catch {
(Connect-VBRServer -server $Veeam_Server -Credential $MyCredentials)
}
#--------------------------------------------------------------------------------
#This piece is where we check the server names given and ensure all is ok and run the script. It does this for each job.
#-------------------------
#Session ID capture bucket
#-------------------------
$SessionID = @()
#------------------------------
##VM Processing Section###
#------------------------------
foreach ($c in $vm) {
if ((Find-VBRViEntity -Name $c) -eq $null) {
$Output += write-output "***Automated Scheduled VM backup failed!!!! The following server name $c is not a valid server name. The following servers names below are a close match to what you might be looking for. Rerun script again with correct name or kick of backup via the VBR Console***"
($Output += Find-VBRviEntity -Name "*$c*" |Select-Object Name)
$body = $output |Out-String
Send-MailMessage -to $to -from $from -SmtpServer $smtp_server -Body $body -Subject "***Automated Scheduled VM backup was unsuccessful - See Below***"
Exit
}
elseif ((Find-VBRViEntity -Name $c |Start-VBRQuickBackup -ErrorAction SilentlyContinue) -eq $null) {
$Output += write-output "***Automated Scheduled VM backup failed!!! Backup Job with $c in it already running! Check VBR Console***"
$jobname = get-VBRBackupSession | Where-Object {$_.JobType -eq "backup" -and $_.Isworking -eq "True"} | Get-VBRTaskSession | Where-Object -Property name -EQ "$c" |Select-Object -ExpandProperty jobname
$SessionID += Get-VBRBackupSession | Where-Object {$_.Isworking -eq "True" -and $_.Jobtype -eq "Backup" -and $_.jobname -eq "$jobname"} | Select-Object -ExpandProperty Currentpointid
break
}
else {
$Output += write-output "***Automated Scheduled VM backup for $c has been started successfully. You will recieve a second email once the backup is completed successfully. ***"
start-sleep -Seconds 10
$jobname = get-VBRBackupSession | Where-Object {$_.JobType -eq "backup" -and $_.Isworking -eq "True"} | Get-VBRTaskSession | Where-Object -Property name -EQ "$c" |Select-Object -ExpandProperty jobname
$SessionID += Get-VBRBackupSession | Where-Object {$_.Isworking -eq "True" -and $_.Jobtype -eq "Backup" -and $_.jobname -eq "$jobname"} | Select-Object -ExpandProperty Currentpointid
}
}
#---------------------
##Whole Job Section##
#---------------------
foreach ($j in $job) {
try {
$Jobinfo = Get-VBRJob | Where-Object {$_.name -eq "$j"}
$JobpreStatuscheck = $Jobinfo.GetLastState()
}
catch {
$Output += "Job Name $j is not valid. These jobs below are a close match to what you might be looking for. Once you got the correct name run it again."
$Output += get-vbrjob -Name "*$j*" |Select-Object Name
$body = $output |Out-String
Send-MailMessage -to $to -from $from -SmtpServer $smtp_server -Body $body -Subject "***Automated Whole job backup was unsuccessful - See Below***"
Exit
}
if ($JobpreStatuscheck -EQ "Working") {
$Output += "Job already running grabbing Session ID and moving on. Will email once acitve job already in progress is complete"
$SessionID += Get-VBRBackupSession | Where-Object {$_.Isworking -eq "True" -and $_.Jobtype -eq "Backup" -and $_.jobname -eq "$j"} | Select-Object -ExpandProperty Currentpointid
break
}
else {
Start-VBRJob -RunAsync $j |Out-Null
$Output += "***Automated Whole job backup was successfully started for job **$j**. You will recieve a second email once the backup is completed successfully.***"
start-sleep -Seconds 10
#sleep is used to ensure job is started as if it is not started it will not pull and complete notification will not go out
$SessionID += Get-VBRBackupSession | Where-Object {$_.Isworking -eq "True" -and $_.Jobtype -eq "Backup" -and $_.jobname -eq "$j"} | Select-Object -ExpandProperty Currentpointid
}
}
#---------------------------------------------------------------
#This sends 1st email notification telling the status of the job
#---------------------------------------------------------------
$body = $output |Out-String
$MailMessage = @{
To = $to
From = $from
Subject = "Veeam Automated VM Backup Request"
Body = "$body"
Smtpserver = $smtp_server
ErrorAction = "SilentlyContinue"
}
Send-MailMessage @MailMessage
#---------------------------------------------------------------
#portion where we monitor for completion of the backups. The do prevents the script from moving on until all jobs are completed so only one email is sent.
#---------------------------------------------------------------
Foreach ($Session in $SessionID) {
do {
$bustatus = Get-VBRBackupSession | Where-Object {$_.Currentpointid -eq "$session" -and $_.Jobtype -eq "Backup" -and $_.iscompleted -eq "true"} | Select-Object -ExpandProperty iscompleted
}
until($bustatus -eq "true")
}
$output1 = @()
Foreach ($Session in $SessionID) {
$output1 += Get-VBRBackupSession | Where-Object {$_.Currentpointid -eq "$session" -and $_.Jobtype -eq "Backup"} | Select-Object jobname, baseprogress, iscompleted |Format-list
}
$body = $output1 |Out-String
$MailMessage = @{
To = $to
From = $from
Subject = "Veeam Automated VM Backup Request $job $VM - Completed "
Body = "See Results Below $body"
Smtpserver = $smtp_server
ErrorAction = "SilentlyContinue"
}
Send-MailMessage @MailMessage
exit