So you’ve gone ahead and started to test out the new Veeam Agent for Linux beta in your environment – finally, a Veeam solution to those physical Linux servers that seem to always hang around in the datacenter! Wait, if you haven’t check my post on it here and sign up for the official beta here. Anways we can schedule our jobs – that’s great, but there is only one problem – we currently don’t have any way of reporting on the success of failure of the jobs.
Now this is only a beta and we don’t know what a full version of this will look like – so I don’t want to go ahead and say that this is something the application is lacking as it could be baked in with a future build – but for now let me show you my workaround – how I scripted the ability to report on success of my jobs.
First up, don’t schedule your backup jobs within the VAL gui – Leave the ‘Run the job automatically’ unchecked while you are setting up your job as we have below. Instead, we will write a script that will first kick off the job for us, then store the session id variable so we can later send an email on its success. We will create our own cron entry to handle this rather than using Veeam’s scheduler.
So how do we go about creating this script? Well, before getting to far into it I suggest you head over to Dmitry Kniazev’s blog and read his post on the Veeam Agent for Linux (Serious Mode) as it does a good job at explaining some of the cli commands such as veeamconfig that come with VAL.
As always let me post the full script first, then break it down line by line for you…. Before getting to far in though there are a few quirks! First off, you can see I dump some information and create some files – all of this is done in the /home/ubuntu/ directory – feel free to change this to whatever you like – I didn’t take the time to variabalize all of this – sorry! Secondly, the script uses sendmail – so be sure you have setup properly as well!!!! Anyways, the script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/bin/bash MYJOBNAME="BackupJob" EMAILTO="myemail@domain.com" EMAILFROM="myemail@domain.com" #start the veeam job sudo veeamconfig job start --name $MYJOBNAME > /home/ubuntu/sessionid #get sessionid from return text SESSID=$( grep -r "Session ID" /home/ubuntu/sessionid | cut -d " " -f3 ) SESSID=$( echo "${SESSID:1:${#SESSID}-3}") echo "Job has started - Session: $SESSID" #get current state (running/failed/success) STAT=$( sudo veeamconfig session info --id $SESSID | grep "State:" | cut -d ":" -f2 ) #wait for job to not be running while [ "$STAT" == " Running" ] do echo "Job still running..." STAT=$( sudo veeamconfig session info --id $SESSID | grep "State:" | cut -d ":" -f2 ) sleep 5 done echo "Job has completed in some sort of fashion - now what to do....." #get some information on the session veeamconfig session info --id $SESSID > /home/ubuntu/sessioninfo veeamconfig session log --id $SESSID > /home/ubuntu/sessionlog #extract some variables for email. BACKUP=$( cat /home/ubuntu/sessionlog | grep -o "Backed up.*" ) STARTDATE=$( cat sessioninfo | grep "Start time:" | sed 's/\sStart time:\s/\ /g' | cut -f2 | awk '{print $1}' ) STARTTIME=$( cat sessioninfo | grep "Start time:" | sed 's/\sStart time:\s/\ /g' | cut -f2 | awk '{print $2}' ) ENDDATE=$( cat sessioninfo | grep "End time:" | sed 's/\sEnd time:\s/\ /g' | cut -f2 | awk '{print $1}' ) ENDTIME=$( cat sessioninfo | grep "End time:" | sed 's/\sEnd time:\s/\ /g' | cut -f2 | awk '{print $2}' ) JOBNAME=$( cat sessioninfo | grep "Job name:" | sed 's/\sJob name:\s/\ /g' | cut -f2 | awk '{print $1}' ) #build email echo "From: $EMAILTO To: $EMAILFROM Subject: VAL Job ($JOBNAME) - $STAT MIME-Version: 1.0 Content-Type: text/html " > /home/ubuntu/email.htm echo " " >> /home/ubuntu/email.htm echo "" >> /home/ubuntu/email.htm echo " " >> /home/ubuntu/email.htm echo " " >> /home/ubuntu/email.htm echo " |
Veeam Agent for Linux job ($JOBNAME) completed with a status of $STAT | |||||
Start Time: | $STARTDATE – $STARTTIME | End Time: | $ENDDATE – $ENDTIME | $BACKUP |
” >> /home/ubuntu/email.htm
echo ”
1 2 3 4 5 6 |
" >> /home/ubuntu/email.htm #send email cat /home/ubuntu/email.htm | sendmail -t $EMAILTO exit |
Huh?!?!?!
Yeah, so as for how it all works let’s have a look!!!
Lines 3-6 simply declare some variables – change these to your prefered emails and most importantly, the name of your backup job!
Line 8 starts our backup job, redirecting text to a file
Line 11/12 gets the sessionID of the job we just started…
Lines 17 through 27 simply loop and wait until our backup job has actually completed running.
Line 30/31 dump some more information out about our backup, while lines 34 through 39 parse that information and hold it in some variables.
Line 41 through 77 build the email and send it!
And that’s it!!!!!
As far as scheduling grows channel your inner cronniness! For instance to have the job run say every Monday through Friday at 1 AM we can add a entry to our crontab as follows
1 |
<em><strong><code class=" language-bash"><span class="token number">0</span> <span class="token number">1</span> <span class="token operator">*</span> <span class="token operator">*</span> <span class="token number">1</span><span class="token operator">-</span><span class="token number">5</span> <span class="token operator">/home/ubuntu/StartJob</span></code></strong></em> |
Anyways – I didn’t spend a lot of time cleaning up this script – just wanted to throw something together to get some basic notifications going through within Veeam Agent for Linux! Feel free to report back with any awesome modifications or enhancements you would like to add! 🙂 Thanks for reading!
Thank you for a great post! You may want to run export NCURSES_NO_UTF8_ACS=1 for prettier screenshots 😉