Standalone backup agents for Linux, Mac, AIX & Solaris workloads on-premises or in the public cloud
Post Reply
davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

Exit codes of backup job (for email script purpose)

Post by davide.depaoli »

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
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli »

Have seen that only failure is logged in Job.log
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

PTide
Product Manager
Posts: 5800
Liked: 583 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by PTide »

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

nielsengelen
Veeam Software
Posts: 3975
Liked: 800 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

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

Post by nielsengelen »

You can add a script that will send an e-mail with the result on the job (post job script).
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen

PTide
Product Manager
Posts: 5800
Liked: 583 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by PTide »

Currently only pre/post freeze/thaw scripts are available, there is no post-job script option in Beta.

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli »

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)
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli » 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
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

PTide
Product Manager
Posts: 5800
Liked: 583 times
Joined: May 19, 2015 1:46 pm
Contact:

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

Post by PTide »

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

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli »

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
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

dellock6
Veeam Software
Posts: 5977
Liked: 1793 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

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

Post by dellock6 » 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
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2020
Veeam VMCE #1

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli »

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
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli » 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: )
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

davide.depaoli
Veeam ProPartner
Posts: 125
Liked: 28 times
Joined: Oct 28, 2012 6:06 pm
Full Name: Davide Depaoli
Location: Santhia' (VC) - Italy
Contact:

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

Post by davide.depaoli »

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
------------------------------
Labinf SpA (formerly H.M.S. Sipac SpA)
Veeam Silver ProPartner

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests