Standalone backup agents for Linux and Unix workloads on-premises or in the public cloud
Post Reply
matimoto
Novice
Posts: 3
Liked: 1 time
Joined: Jan 08, 2018 8:43 am
Full Name: Mateusz Kilinski
Contact:

Post-job doesn't work

Post by matimoto » 1 person likes this post

Hello there. I have a little issue with my post-job script which is sending an email after backup. When I run it manually, everything works great - email is sent. But if the script path is set in job config, nothing happends, email is not sended. Here is a code:

Code: Select all

#!/bin/bash

# version 0.3
EMAILTO="xyz"
EMAILFROM="abc"
HTMLTEMPLATE="/usr/local/sbin/veeam_mail_template.html"

VC=$(which veeamconfig)
if [ ! "$VC" ]; then
 echo "No Veeam Agent for Linux installed!"
 exit
fi

SQLITE=$(which sqlite3)
if [ "$SQLITE" != "/usr/bin/sqlite3" ]; then
 apt-get install -y sqlite3
fi

BC=$(which bc)
if [ "$BC" != "/usr/bin/bc" ]; then
 apt-get install -y bc
fi

AGENT=$($VC -v)
# get last session id
SESSID=$($VC session list|grep -v "Total amount"|tail -1|awk '{print $3}')
SESSID=${SESSID:1:${#SESSID}-2}

# state 1=Running, 6=Success, 7=Failed, 9=Warning
# get data from sqlite db
SESSDATA=$(sqlite3 /var/lib/veeam/veeam_db.sqlite  "select start_time, end_time, state, progress_details from JobSessions order by start_time DESC limit 1;")
STARTTIME=$(echo $SESSDATA|awk -F'|' '{print $1}')
ENDTIME=$(echo $SESSDATA|awk -F'|' '{print $2}')
STATE=$(echo $SESSDATA|awk -F'|' '{print $3}')
DETAILS=$(echo $SESSDATA|awk -F'|' '{print $4}')

if [ "$STATE" == "1" ]; then exit; fi
if [ "$STATE" == "6" ]; then SUCCESS=1; BGCOLOR="#00B050"; STAT="Success"; else SUCCESS=0; fi
if [ "$STATE" == "7" ]; then ERROR=1; BGCOLOR="#fb9895"; STAT="Failed"; else ERROR=0; fi
if [ "$STATE" == "9" ]; then WARNING=1; BGCOLOR="#fbcb95"; STAT="Warning"; else WARNING=0; fi

PROCESSED=$(echo $DETAILS|awk -F'processed_data_size_bytes="' '{print $2}'|awk -F'"' '{print $1}')
PROCESSED=$($BC <<< "scale=1; $PROCESSED/1024/1024/1024")" GB"
READ=$(echo $DETAILS|awk -F'read_data_size_bytes="' '{print $2}'|awk -F'"' '{print $1}')
READ=$($BC <<< "scale=1; $READ/1024/1024/1024")" GB"
TRANSFERRED=$(echo $DETAILS|awk -F'transferred_data_size_bytes="' '{print $2}'|awk -F'"' '{print $1}')
if [ $TRANSFERRED -gt 1073741824 ]; then
 TRANSFERRED=$($BC <<< "scale=1; $TRANSFERRED/1024/1024/1024")" GB"
else
 TRANSFERRED=$($BC <<< "scale=0; $TRANSFERRED/1024/1024")" MB"
fi
SPEED=$(echo $DETAILS|awk -F'processing_speed="' '{print $2}'|awk -F'"' '{print $1}')
SPEED=$($BC <<< "scale=1; $SPEED/1024/1024")
SOURCELOAD=$(echo $DETAILS|awk -F'source_read_load="' '{print $2}'|awk -F'"' '{print $1}')
SOURCEPLOAD=$(echo $DETAILS|awk -F'source_processing_load="' '{print $2}'|awk -F'"' '{print $1}')
NETLOAD=$(echo $DETAILS|awk -F'network_load="' '{print $2}'|awk -F'"' '{print $1}')
TARGETLOAD=$(echo $DETAILS|awk -F'target_write_load="' '{print $2}'|awk -F'"' '{print $1}')

if [ "$SOURCELOAD" -gt "$SOURCEPLOAD" ] && [ "$SOURCELOAD" -gt "$NETLOAD" ] && [ "$SOURCELOAD" -gt "$TARGETLOAD" ]; then
        BOTTLENECK="Source"
fi
if [ "$SOURCEPLOAD" -gt "$SOURCELOAD" ] && [ "$SOURCEPLOAD" -gt "$NETLOAD" ] && [ "$SOURCEPLOAD" -gt "$TARGETLOAD" ]; then
        BOTTLENECK="Source CPU"
fi
if [ "$NETLOAD" -gt "$SOURCELOAD" ] && [ "$NETLOAD" -gt "$SOURCEPLOAD" ] && [ "$NETLOAD" -gt "$TARGETLOAD" ]; then
        BOTTLENECK="Network"
fi
if [ "$TARGETLOAD" -gt "$SOURCELOAD" ] && [ "$TARGETLOAD" -gt "$SOURCEPLOAD" ] && [ "$TARGETLOAD" -gt "$NETLOAD" ]; then
        BOTTLENECK="Target"
fi

DURATION=$(date -d "0 $ENDTIME sec - $STARTTIME sec" +"%H:%M:%S")
START=$(date -d "@$STARTTIME" +"%A, %d %B %Y %H:%M:%S")
END=$(date -d "@$ENDTIME" +"%A, %d.%m.%Y %H:%M:%S")
STIME=$(date -d "@$STARTTIME" +"%H:%M:%S")
ETIME=$(date -d "@$ENDTIME" +"%H:%M:%S")

# get session error
ERRLOG=$($VC session log --id $SESSID|egrep 'error|warn'|sed ':a;N;$!ba;s/\n/<br>/g'|sed -e "s/ /\&nbsp;/g")
ERRLOG=$(printf "%q" $ERRLOG)

# create temp file for mail
TEMPFILE=/tmp/template.html

# uppercase hostname
HN=${HOSTNAME^^}

# debug output
#echo -e -n "HN: $HN\nSTAT: $STAT\nBGCOLOR: $BGCOLOR\nSTART: $START\nSUCCESS: $SUCCESS\nERROR: $ERROR\nWARNING: $WARNING\nSTIME: $STIME\nETIME: $ETIME\nREAD: $READ\nTRANSFERRED: $TRANSFERRED\nDURATION: $DURATION\nPROCESSED: $PROCESSED\nBOTTLENECK: $BOTTLENECK\nERRLOG: $ERRLOG\nSPEED: $SPEED\n"

sed -e "s/XXXHOSTNAMEXXX/$HN/g" -e "s/XXXSTATXXX/$STAT/g" -e "s/XXXBGCOLORXXX/$BGCOLOR/g" -e "s/XXXBACKUPDATETIMEXXX/$START/g" -e "s/XXXSUCCESSXXX/$SUCCESS/g" -e "s/XXXERRORXXX/$ERROR/g" -e "s/XXXWARNINGXXX/$WARNING/g" -e "s/XXXSTARTXXX/$STIME/g" -e "s/XXXENDXXX/$ETIME/g" -e "s/XXXDATAREADXXX/$READ/g" -e "s/XXXREADXXX/$READ/g" -e "s/XXXTRANSFERREDXXX/$TRANSFERRED/g" -e "s/XXXDURATIONXXX/$DURATION/g" -e "s/XXXSTATUSXXX/$STAT/g" -e "s/XXXTOTALSIZEXXX/$PROCESSED/g" -e "s/XXXBOTTLENECKXXX/$BOTTLENECK/g" -e "s/XXXDETAILSXXX/$ERRLOG/g" -e "s/XXXRATEXXX/$SPEED MB\/s/g" -e "s/XXXBACKUPSIZEXXX/$TRANSFERRED/g" -e "s/XXXAGENTXXX/$AGENT/g" $HTMLTEMPLATE > $TEMPFILE

# send email
mailx -A zenbox -s "[$STAT] $HN - $START  $(echo -e "\nContent-Type: text/html; charset=UTF-8")" $EMAILTO < $TEMPFILE

exit
Here is a config job:
Image

And Job Log: https://drive.google.com/open?id=1yYv9T ... vn_z8M07If

How can I turn this emails on?

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

Re: Post-job doesn't work

Post by PTide »

Hi,

Do you see any mention of the script in the session log in UI, any warnings? Also, please double-check if the path is correct. For better troubleshooting please add some sort of basic logging in your script please. For example, make it to write some info about the progress to some file after each operation so it would be possible to track at what stage the script fails.

Thanks

matimoto
Novice
Posts: 3
Liked: 1 time
Joined: Jan 08, 2018 8:43 am
Full Name: Mateusz Kilinski
Contact:

Re: Post-job doesn't work

Post by matimoto »

There are no errors, no warnings and other info things for any debugging. The path is correct - I’ve chosen it using [Browse] button. Also I’be tried to make a simple debug scrip - simple echo actual date and time to end of specific file (echo $(date...) >> file.txt) and after doing backup, the file is empty.

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

Re: Post-job doesn't work

Post by PTide »

Would you mind adding another echo in the beginning, plus a couple of additional echoes inbetween start and end of the script?

Thanks

matimoto
Novice
Posts: 3
Liked: 1 time
Joined: Jan 08, 2018 8:43 am
Full Name: Mateusz Kilinski
Contact:

Re: Post-job doesn't work

Post by matimoto »

PTide wrote:Would you mind adding another echo in the beginning, plus a couple of additional echoes inbetween start and end of the script?
Can you explain what for? This is simple situation - the post-job is launching a script file or not. If the script with one echo doesn't work, adding another echo will not provide of success.

Here is a screen of the last backup:
Image

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

Re: Post-job doesn't work

Post by PTide »

In my opinion there might be more than one reason for the observed behaviour:

A) UI glitch + problem with the script: script actually was started but, for some reason, it didn't make it to the very end where 'echo' statement resides.
B) UI is fine, the script wasn't started at all.

If you are 100% sure "B" is the correct answer, then please open a case with our support team and post your case ID here.

Thank you.

techcat
Influencer
Posts: 10
Liked: never
Joined: Dec 04, 2017 10:46 am
Contact:

Re: Post-job doesn't work

Post by techcat »

Same issue here, so I'm confident this actually is a technical issue. I opened a case.

johan.finn
Novice
Posts: 4
Liked: never
Joined: Feb 02, 2018 9:45 am
Full Name: johan finn
Contact:

Re: Post-job doesn't work

Post by johan.finn »

Exactly the same for us, on all servers. Post job that should send mail after backup is finnished, stopped working after last update of the client. Works if you do it the "commanline" way, but not from the veeam agent client gui.
Any news on this?
./Johan

techcat
Influencer
Posts: 10
Liked: never
Joined: Dec 04, 2017 10:46 am
Contact:

Re: Post-job doesn't work

Post by techcat »

There is a bug that causes post-job scripts not to be executed if the is no pre-job script.

Workaround: create a pre-script that doesn't do anything:

Code: Select all

#!/usr/bin/env bash
exit 0

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

Re: Post-job doesn't work

Post by PTide »

Hi,

Yes, it's been confirmed to be a bug., will be fixed in the next version.

Thanks

nehuen
Lurker
Posts: 2
Liked: 1 time
Joined: Feb 02, 2018 6:05 pm
Full Name: Nehuen Natero
Contact:

Re: Post-job doesn't work

Post by nehuen »

techcat wrote:There is a bug that causes post-job scripts not to be executed if the is no pre-job script.

Workaround: create a pre-script that doesn't do anything:

Code: Select all

#!/usr/bin/env bash
exit 0
Hello, i have the same issue but it is not solved by adding an empry script with exit code 0 as a pre-job script. My veeam configuration is the following:

Pre-job script:

Code: Select all

#!/usr/bin/env bash
exit 0
Post-job script:

Code: Select all

#get session id of last job
SESSION_ID=`veeamconfig session list | grep BackupJob1 | awk '{print $3}' | awk 'END{print}' | sed 's/[{}]//g'`

#check and set the exit status of the job
STATUS=`veeamconfig session info --id $SESSION_ID | grep State | awk  '{print $2}'`

if [ $STATUS = 'Warning' ]
then
     WARN_MSG=`veeamconfig session log --id $SESSION_ID | grep warn | awk '{print $6,$7,$8,$9}'`
     echo -e "Job $JOBNAME Successful with following $STATUS:\n\n$WARN_MSG\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi

if [ $STATUS = 'Failed' ]
then
     echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi

if [ $STATUS = 'Success' ]
then
     echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi

exit 0
I left out the private information in the post-job script. Anything i can do to fix this?

Regards.

nehuen
Lurker
Posts: 2
Liked: 1 time
Joined: Feb 02, 2018 6:05 pm
Full Name: Nehuen Natero
Contact:

Re: Post-job doesn't work

Post by nehuen » 1 person likes this post

I found out the answer to my problem, the veeam job keeps a state of "Running" until the script finishes executing, so the mail was never sent. To fix this i made the mail sending part of the script a function and executed it in another process, this allowed the post script to finish and change its state while my function picks this up. Here is the code:

Code: Select all

progress(){
#obtenemos el id y el status del ultimo BKP job
SESSION_ID=`veeamconfig session list | grep $JOBNAME | awk '{print $3}' | awk 'END{print}' | sed 's/[{}]//g'`
STATUS=`veeamconfig session info --id $SESSION_ID | grep State | awk  '{print $2}'`

while [ $STATUS = 'Running' ]
do
#esperamos 30secs y volvemos a checkear el status del job hasta que deje de correr
sleep 30
STATUS=`veeamconfig session info --id $SESSION_ID | grep State | awk  '{print $2}'`
done

#mandamos mail segun el status del BKP
if [ $STATUS = 'Warning' ]
then
 WARN_MSG=`veeamconfig session log --id $SESSION_ID | grep warn | awk '{print $6,$7,$8,$9}'`
 echo -e "Job $JOBNAME Successful with following $STATUS:\n\n$WARN_MSG\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi

if [ $STATUS = 'Failed' ]
then
 echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi

if [ $STATUS = 'Success' ]
then
 echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "$VAL $STATUS" -r $EMAIL_FROM $EMAIL_TO
fi
}

progress &

exit 0
Regards.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests