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 2 people like 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: 99
Liked: 19 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: 3502
Liked: 291 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: 99
Liked: 19 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

[MERGED] Email confirmations in Linux

Veeam Logoby patrickwilson82 » Fri Nov 17, 2017 8:34 pm

Is there a way to set Agent for Linux to email me a confirmation when a backup job completes, like with the Windows version? I've not had much luck yet in finding this info. Thanks!
patrickwilson82
Enthusiast
 
Posts: 44
Liked: 2 times
Joined: Wed Nov 08, 2017 2:00 pm
Full Name: Patrick Wilson

Re: Scripting

Veeam Logoby patrickwilson82 » Tue Nov 21, 2017 3:55 am 1 person likes this post

Thank you Davide for the script. That worked for me!
patrickwilson82
Enthusiast
 
Posts: 44
Liked: 2 times
Joined: Wed Nov 08, 2017 2:00 pm
Full Name: Patrick Wilson

Re: Scripting

Veeam Logoby patrickwilson82 » Mon Dec 11, 2017 9:27 pm

Hi Davide,

I previously had your script running successfully (after customizing it) on a server that is no longer up and running. I tried to run my saved copy on a different server and keep getting this output:

./valbackup2.sh: line 14: /etc/veeam/scripts/SystemBackup.tmp: No such file or directory
grep: /etc/veeam/scripts/SystemBackup.tmp: No such file or directory
grep: /etc/veeam/scripts/SystemBackup.tmp: No such file or directory
Error: Value for argument [--id] is required.

Do you have any suggestions? Your help would be greatly appreciated! Thanks!
patrickwilson82
Enthusiast
 
Posts: 44
Liked: 2 times
Joined: Wed Nov 08, 2017 2:00 pm
Full Name: Patrick Wilson

Re: Scripting

Veeam Logoby vmniels » Mon Dec 11, 2017 9:40 pm

Are you sure the path /etc/veeam/scripts exist as well as the SystemBackup.tmp file?
VCP-DCV
Veeam Certified Architect (VMCA)
http://foonet.be
vmniels
Veeam Software
 
Posts: 1727
Liked: 380 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Scripting

Veeam Logoby PTide » Tue Dec 12, 2017 10:10 am

Hi,

Niels is spot on - here are the lines that generate the error:
Code: Select all
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/\.//'`

As you can see after you start the job it should send its output to /etc/veeam/scripts/$JOBNAME.tmp, which is, apparently. SystemBackup.tmp in your case. Please double check if line 10 from the script actually starts the SystemBackup job and creates corresponding .tmp file.

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

Re: Scripting

Veeam Logoby patrickwilson82 » Tue Dec 12, 2017 2:00 pm

This is the first portion of the script that I have:

JOBNAME=SystemBackup
SCRIPT_DIR=/etc/veeam/scripts
LOG_DIR=/var/log/veeam/Backup/$JOBNAME
JOB_INFO=`veeamconfig job info --name $JOBNAME`
export JOBNAME
#TODAY=$(date +"%Y-%m-%d")
#export TODAY
#VEEAM_PID=`pgrep veeamjobman`
#export VEEAM_PID

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

SESSION_ID=`grep ID /etc/veeam/scripts/$JOBNAME.tmp | awk '{print $3}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
export SESSION_ID
LOGDIR=`grep log /etc/veeam/scripts/$JOBNAME.tmp | awk '{print $4}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
export LOGDIR
LOGFILE=$LOGDIR/Job.log
export LOGFILE
patrickwilson82
Enthusiast
 
Posts: 44
Liked: 2 times
Joined: Wed Nov 08, 2017 2:00 pm
Full Name: Patrick Wilson

Re: Scripting

Veeam Logoby vmniels » Tue Dec 12, 2017 2:04 pm

Can u doublecheck the folder exist under /etc/veeam by running ls /etc/veeam ?

If not try mkdir -p /etc/veeam/scripts and try again.
VCP-DCV
Veeam Certified Architect (VMCA)
http://foonet.be
vmniels
Veeam Software
 
Posts: 1727
Liked: 380 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Scripting

Veeam Logoby patrickwilson82 » Thu Dec 14, 2017 2:59 pm

That did the trick. Thank you!
patrickwilson82
Enthusiast
 
Posts: 44
Liked: 2 times
Joined: Wed Nov 08, 2017 2:00 pm
Full Name: Patrick Wilson

[MERGED] E-mail reporting with new linux agent

Veeam Logoby bc2011 » Wed Jan 10, 2018 11:51 am

New agent is performing great. However, it's still lacking an integrated e-mail report feature. Any roadmap for that?
I'm using some script , found on forum, that sends email with one line, but it would be great if veeam could prepare some official solution in the meantime.

Thanks, Matjaž
bc2011
Service Provider
 
Posts: 183
Liked: 12 times
Joined: Tue Aug 02, 2011 9:30 pm
Location: Celje, Slovenia
Full Name: Matjaž Antloga

Re: Scripting

Veeam Logoby PTide » Wed Jan 10, 2018 8:39 pm

Hi Matjaž,

Your request has been noted, thank you!
PTide
Veeam Software
 
Posts: 3502
Liked: 291 times
Joined: Tue May 19, 2015 1:46 pm

Previous

Return to Veeam Agent for Linux



Who is online

Users browsing this forum: No registered users and 1 guest