Scripting

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

Re: Scripting

Veeam Logoby davide.depaoli » Thu Sep 08, 2016 1:08 pm 1 person likes this post

A new attempt to improve the script.
Fixed some cosmetics issues in email body.
Added some veeamconfig commands as variables.
changed the way to catch warning messages for the warning job status.
Added Job Info in the body of email.

Code: Select all
#!/bin/bash
# Script to run Veeam VAL backup and email job status

JOBNAME=Backup_to_LocalRepo
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


I'm hoping that my work is useful to someone.
Davide
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 97
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Scripting

Veeam Logoby PTide » Thu Sep 08, 2016 2:34 pm

Sure it is useful, so many people just want to setup and forget instead of diving into bash scripting that they have never done before.

Thanks for your update!
PTide
Veeam Software
 
Posts: 3022
Liked: 247 times
Joined: Tue May 19, 2015 1:46 pm

[MERGED] job report by email

Veeam Logoby boudjel38 » Thu Jun 15, 2017 12:52 pm

hi,

i installed veeam agent for linux on rhel6
backup and restore works great !
i was wondering how can i setup job email reporting ?

i usually setup email report using gmail admin account

much appreciated for your help...

thanks
boudjel
boudjel38
Novice
 
Posts: 5
Liked: never
Joined: Tue Jan 24, 2017 3:44 pm
Full Name: boudjel boudissa

Re: Scripting

Veeam Logoby davide.depaoli » Wed Jun 21, 2017 6:54 am

Hi boudjel38,
you can configure cron to execute the script I wrote (you can see, copy and customize it here).
For example:

0 7 * * * /etc/veeam/scripts/BackupToVBR.sh

is the script pointing backup to VBR server
------------------------------
H.M.S. Sipac SpA
Veeam Gold ProPartner
davide.depaoli
Veeam ProPartner
 
Posts: 97
Liked: 16 times
Joined: Sun Oct 28, 2012 6:06 pm
Location: Santhia' (VC) - Italy
Full Name: Davide Depaoli

Re: Scripting

Veeam Logoby boudjel38 » Thu Jun 22, 2017 7:59 am

hi,

yes i am using veeam B&R
actually it works using the email settings within the B&R console
so i prefer to use this integration rather than your script

much appreciated for your help anyway
i would appreciate in the near futur to have this fonctionnality built in with the agent like it is with the windows agent

all the best
boudjel
boudjel38
Novice
 
Posts: 5
Liked: never
Joined: Tue Jan 24, 2017 3:44 pm
Full Name: boudjel boudissa

Previous

Return to Veeam Agent for Linux



Who is online

Users browsing this forum: No registered users and 3 guests