Exit codes of backup job (for email script purpose)

Backup agent for Linux servers and workstations on-premises or in the public cloud

Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 10:40 am

I'm trying to extract job result from logfile (/var/log/veeam/Bakup/JOBNAME) but I'm not able to find nothing (like Job successfull, or job failed), in order to create a script to email the job result.
Is there any string in the log or any other way to know the job status ?

tnx
Davide
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 11:22 am

Have seen that only failure is logged in Job.log
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby PTide » Thu Jul 14, 2016 12:50 pm

Hi,

We are going to format logs so they get more informative in future version. For now I can assure you that if there is no "Job has failed" string in Job.log then the backup ended successfully. I assume that you're going to send emails directly from the host, may I ask you what email client you've chosen to use and why?

Thanks
PTide
Veeam Software
 
Posts: 2886
Liked: 236 times
Joined: Tue May 19, 2015 1:46 pm

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby vmniels » Thu Jul 14, 2016 12:54 pm

You can add a script that will send an e-mail with the result on the job (post job script).
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1444
Liked: 319 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby PTide » Thu Jul 14, 2016 1:07 pm

Currently only pre/post freeze/thaw scripts are available, there is no post-job script option in Beta.
PTide
Veeam Software
 
Posts: 2886
Liked: 236 times
Joined: Tue May 19, 2015 1:46 pm

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 1:37 pm

PTide wrote:Hi,

We are going to format logs so they get more informative in future version. For now I can assure you that if there is no "Job has failed" string in Job.log then the backup ended successfully. I assume that you're going to send emails directly from the host, may I ask you what email client you've chosen to use and why?

Thanks



I'm just playing with a test centos vm, and I was planning to take out the string from the logfile and pass it to the mail command of linux (mailx)
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 2:18 pm 1 person likes this post

For example:
veeamconfig session list | grep Failed
TestNFS Backup {187c8d92-7bc5-4300-9a6b-03482a544b98} Failed 2016-07-14 11:33 2016-07-14 11:35

formatting in some way the output and pass it to mailx command
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby PTide » Thu Jul 14, 2016 2:29 pm

If you'd like to do some advanced text formatting then I recommend you to use sed, cut, and awk utilities. Mailx also accept pipeline input, for example:

Code: Select all
veeamconfig session list | grep Failed | mailx -s "Failed jobs" root@localhost


awk example:

Code: Select all
veeamconfig session list | grep Failed | awk '{print $1,$4,$7,$8}' | mailx -s "Failed jobs" root@localhost
PTide
Veeam Software
 
Posts: 2886
Liked: 236 times
Joined: Tue May 19, 2015 1:46 pm

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 2:48 pm

I'm trying with grep, because have very very old and rusty memories of shell scripting (my latest script dates back to about 20 years ago !).

My simple script I'm trying now is:

veeamconfig session list | grep UUID > body.txt
veeamconfig session list | grep Failed >> body.txt
cat body.txt | mailx -s "VAL session Failed" my@email.it
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby dellock6 » Thu Jul 14, 2016 3:29 pm 2 people like this post

As a lover of one-liners, you can improve your code like this:

Code: Select all
veeamconfig session list | grep -e UUID -e Failed | mailx -s "VAL session Failed" my@email.it


No need for a temp txt file ;)
Luca Dell'Oca
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 4934
Liked: 1293 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Thu Jul 14, 2016 3:41 pm

Added a $TODAY variable to avoid sending emails with old Failed session

TODAY=$(date +"%Y-%m-%d %H:%M")
veeamconfig session list | grep -e UUID -e Failed | grep $TODAY | mailx -s "VAL session Failed" my@email.it
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Fri Jul 15, 2016 1:06 pm 1 person likes this post

Right TODAY variable format is without %H:%M.

TODAY=$(date +"%Y-%m-%d")
veeamconfig session list | grep -e UUID -e Failed | grep $TODAY | mailx -s "VAL session Failed" my@email.it

In this way the script is working as espected (by me) and report only today failed sessions.

I've seen my post forwarded to another user requesting email feature. I want royalties or special mention by veeam (I'm joking, of course :wink: )
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Exit codes of backup job (for email script purpose)

Veeam Logoby davide.depaoli » Wed Jul 20, 2016 10:51 am

I have implemented some controls to my script:

#1 - starting the job
#2 - checking and waiting until job is finished
#3 - test the exit result of the job (Failed or Success)
# - 4 send email in both cases, if job is failed or successful.

Code: Select all
#!/bin/bash
#
# Script to run Veeam backup and email job status (BackupJob3)
veeamconfig job start --id {ba6434ea-55cc-4529-a9d3-69ec868769e9}

JOBNAME=BackupJob3
export JOBNAME
TODAY=$(date +"%Y-%m-%d")
export TODAY
#VEEAM_PID=`pgrep veeamjobman`
#export VEEAM_PID

until [ -z `pgrep veeamjobman` ]
do
echo "job is running" > /dev/null
done

FAILED=`veeamconfig session list | grep -e Failed | grep $JOBNAME | grep $TODAY`
export FAILED
if [ -z "$FAILED" ]
then
        echo "Job $JOBNAME Successfull" | mailx -s "VAL session $JOBNAME Successfull" my@email.com
else
        echo "Job $JOBNAME Failed" | mailx -s "VAL session $JOBNAME Failed" my@email.com
fi
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 96
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli


Return to Veeam Agent for Linux



Who is online

Users browsing this forum: No registered users and 4 guests