Standalone backup agents for Linux, Mac, AIX & Solaris workloads on-premises or in the public cloud
Post Reply
Janarxd
Influencer
Posts: 15
Liked: 1 time
Joined: Mar 18, 2021 3:28 pm
Full Name: janar xd
Contact:

Veeam e-mail notification

Post by Janarxd »

Hey everyone! I recently got Veeam Agent backup working. Now I'd like to try out e-mail notifications. I'm using Ubuntu 20.04.
So I found this script from an older forum (veeam-agents-for-linux-mac-aix-solaris- ... 36789.html.

So the code is:

Code: Select all

#!/bin/bash
# Script to run vm_backup and email job status

JOBNAME=vm_backup
SCRIPT_DIR=/etc/veeam/scripts
LOG_DIR=/var/log/veeam/Backup/$JOBNAME
JOB_INFO=`veeamconfig job info --name $JOBNAME`

#start backup job
veeamconfig job start --name $JOBNAME 1> /etc/veeam/scripts/$JOBNAME.tmp 2> /etc/veeam/scripts/$JOBNAME.err

SESSION_ID=`grep ID $SCRIPT_DIR/$JOBNAME.tmp | awk  '{print $3}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
SESSION_LOG_DIR=`grep log $SCRIPT_DIR/$JOBNAME.tmp | awk  '{print $4}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
LOGFILE=$SESSION_LOG_DIR/Job.log
SESSION_INFO=`veeamconfig session info --id $SESSION_ID | grep -v UUID`

# check if another job is running
if [ -s $JOBNAME.err ]
then
     ERROR_MSG=`grep Error $SCRIPT_DIR/$JOBNAME.err`
     echo "$ERROR_MSG" | mailx -s "VAL Job $JOBNAME Error" -r VeeamLinuxAgent@email.local  recipient@email.com
fi

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

#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 Job $JOBNAME $STATUS" -r VeeamLinuxAgent@email.local  recipient@email.com
fi

if [ $STATUS = 'Failed' ]
then
     echo -e "Job $JOBNAME $STATUS. See attached logfile for error details.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "VAL Job $JOBNAME $STATUS" -a $LOGFILE -r VeeamLinuxAgent@email.local  recipient@email.com
fi

if [ $STATUS = 'Success' ]
then
     echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "VAL Job $JOBNAME $STATUS" -r VeeamLinuxAgent@labinf.local davide.depaoli@labinf.it
fi

rm -f $SCRIPT_DIR/$JOBNAME.tmp $SCRIPT_DIR/$JOBNAME.err
Veeam's jobname is "vm_backup".
Script is located in /etc/veeam/scripts/vm_backup Do I have to change anything about the script's name?
I created a folder /var/log/veeam/Backup
My problem is that I always have to type sudo before every command so this script won't work for me, I'll get "No permission" error.
1> and 2> at the start, are these 2 files created automatically?

How should I change the code to work with sudo before every command?

Thanks

Janarxd
Influencer
Posts: 15
Liked: 1 time
Joined: Mar 18, 2021 3:28 pm
Full Name: janar xd
Contact:

Re: Veeam e-mail notification

Post by Janarxd »

Tried running the script with my configuration. It works nicely.

Janarxd
Influencer
Posts: 15
Liked: 1 time
Joined: Mar 18, 2021 3:28 pm
Full Name: janar xd
Contact:

Re: Veeam e-mail notification

Post by Janarxd »

I actually have a problem now. I can only run the script as sudo. How can I make it so I can run my scripts with "/etc/veeam/scripts/vm_backup" instead of "sudo /etc/veeam/scripts/vm_backup"?

Janarxd
Influencer
Posts: 15
Liked: 1 time
Joined: Mar 18, 2021 3:28 pm
Full Name: janar xd
Contact:

Re: Veeam e-mail notification

Post by Janarxd »

This is the output when I run the script without sudo.

Code: Select all

/etc/veeam/scripts/vm_backup: line 7: /usr/bin/veeamconfig: Permission denied
/etc/veeam/scripts/vm_backup: line 10: /etc/veeam/scripts/vm_backup.tmp: Permission denied
grep: /etc/veeam/scripts/vm_backup.tmp: No such file or directory
grep: /etc/veeam/scripts/vm_backup.tmp: No such file or directory
/etc/veeam/scripts/vm_backup: line 15: /usr/bin/veeamconfig: Permission denied
/etc/veeam/scripts/vm_backup: line 31: /usr/bin/veeamconfig: Permission denied
/etc/veeam/scripts/vm_backup: line 33: [: =: unary operator expected
/etc/veeam/scripts/vm_backup: line 39: [: =: unary operator expected
/etc/veeam/scripts/vm_backup: line 44: [: =: unary operator expected
By the looks of it I can't start the backup, can't create the files etc...

Janarxd
Influencer
Posts: 15
Liked: 1 time
Joined: Mar 18, 2021 3:28 pm
Full Name: janar xd
Contact:

Re: Veeam e-mail notification

Post by Janarxd »

I started using cron, didn't know that all the commands are ran as root user. Problem solved!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests