I'm a beginner with powershell, but i have searched for usefull scripts and information and i have created a script for our environment. It's working very good, and it's very basic in powershell, so i can read / modify it by myself.
The script is for running veeam backup jobs, then according to the day it's running several backup exec jobs.
Everything is running after each other, so that i don't have to think about complex schedules.
Now the problem:.This weekend, the target for veeam was shutdown unexpectly. So the veeam backups are failed, then automatically the backup exec jobs where also started (because the script goes further).
All of the properties for the veeam backup jobs are set within the gui. So the script is doing not more than only starting it. But i need some more intelligence to it.
Can someone help me with the following modification inside my own script:
1. Only go further with the script if the veeam jobs are finished succesfull (maybe with a warning), but status failed is wrong! (something with get-VBRstatus).
2. A retry job could fixed my issue with the unexpected shutdown of target i think, because some minutes later the target was available (but job was failed in the middle of process). So adding a retry to the scripts will be very cool.
3. As i said before i now start only the job from the script, while the job- settings are done with the gui. So M-F = forward incrementals and on Satruday = Synthetic Full. Is that a good way?
Here is my script:
Code: Select all
# Register Veeam Powershell snapins to use Veeam specific powershell commands in Windows powershell.
Add-PSSnapin VeeamPSSnapIn
#ALLDAY SECTION
# Place each existing job in a variable and start each job after each other (powershell will wait for finishing job).
$job1 = Get-VBRJob -name “Backup WDM-VM Linux”
Start-VBRJob –Job ($job1)
$job2 = Get-VBRJob -name “Backup WDM-VM OES”
Start-VBRJob –Job ($job2)
$job3 = Get-VBRJob -name “Backup WDM-VM Windows 2008”
Start-VBRJob –Job ($job3)
$job4 = Get-VBRJob -name “Backup WDM-VM Windows 2003”
Start-VBRJob –Job ($job4)
#DAY SPECIFIC SECTION
#In order to know if whe need to run backup exec jobs for M-F or the weekend, we need to identify that start time rather than the end time
#So run a query that will check the last starttime of each job.
$Date1 = $job1.FindLastSession().progress.starttime
$Date2 = $job2.FindLastSession().progress.starttime
$Date3 = $job3.FindLastSession().progress.starttime
$Date4 = $job4.FindLastSession().progress.starttime
if($Date1.DayofWeek -eq "Saturday")
{
# Launch a backup exec Job that will perform a FULL File-Level backup from WFS1,WFS2,WGB1 to WQNAP1\Symantec.
& "C:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o01 -jBackup_Exec_File_Level_OES_NSS_Physical_Vrij_Full
# Wait 4,5 hours before going further, so the previous backup job will be finished. Extend this time if needed.
Start-Sleep -s 16200
# Launch a backup exec job that will perform a File-Level backup of all Veeam backups (Synthetic Full and Config) on WQNAP1\Veeam\*.vib,*.vbm to tape.
& "C:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o01 -jVeeam_Results_To_Tape_Vrij
}
else
{
# Launch a backup exec Job that will perform a DIFFERENTIAL File-Level backup from WFS1,WFS2,WGB1 to WQNAP1\Symantec.
& "C:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o01 -jBackup_Exec_File_Level_OES_NSS_Physical_Ma_Do_Differential
# Wait 1 hour before going further, so the previous backup job will be finished. Extend this time if needed.
Start-Sleep -s 3600
# Remove all archive attributes from the WQNAP1\Veeam directory, so the folowwing backup exec job will not backup too much.
& "c:\windows\system32\attrib.exe" -A /S B:\Backup\Veeam\*.*
# Launch a backup exec job that will perform a File-Level backup of all Veeam backups (Forward-Incremental and Config) on WQNAP1\Veeam\*.vib,*.vbm to tape.
& "C:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o01 -jVeeam_Results_To_Tape_Ma_Do
}
# Possible second ALLDAY Section:
# END
Thanks.
Tristan.