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: 3906
Liked: 330 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

Backup Notification Linux

Veeam Logoby rui.rodrigues » Fri Jul 28, 2017 3:02 pm

Hello,

I manage a few dozens of Linux Debian Servers.
I'm making some tests with the latest version available.
I need to receive an email after the backup is made with the resume of the Backup below:

Backup 100% Status: Warning
Summary Data

Duration: 00:05:23 Processed: 9.6 GB (100%)
Processing rate: 32.5 MB/s Read: 9.6 GB
Bottleneck: Target Transferred: 34.5 MB (285.6x)

Time Action Duration

19:40:37 Job BackupJob1 started at 2017-07-25 19:40:37 BST
19:40:37 Preparing to backup
19:40:42 Creating volume snapshot 00:00:01
19:40:43 Starting incremental backup to Repository_1
19:40:55 Backed up sda 9.6 GB at 33.2 MB/s 00:04:58
19:45:53 [warn] Cannot find EFI boot manager utility
19:45:53 Backing up summary.xml 00:00:00
19:45:57 Releasing snapshot 00:00:03
19:46:00 [warn] Processing finished with warnings at 2017-07-25 19:46:00 BST

Is this info in one file only, so that I can attach the info to an email with a script?
If so, where is the location of the log?

I can ony find info very detailed of the backup, in different files.

Every time the BackupJob runs it creates a new folder with log files in it, but I don't need all the information, and Im not able to do a script to read info in a different folder everytime:
/var/log/veeam/Backup/BackupJob1# ls -lat
total 24
drwxr-xr-x 2 root root 4096 Jul 28 15:42 Session_20170728_154205_{20920194-caea-480a-bbe6-aee0db4bc3ee}
drwxr-xr-x 6 root root 4096 Jul 28 15:42 .
drwxr-xr-x 3 root root 4096 Jul 28 14:33 ..
drwxr-xr-x 2 root root 4096 Jul 25 19:40 Session_20170725_194037_{d20f74e4-9ff4-4297-8e92-1face19ebae6}
drwxr-xr-x 2 root root 4096 Jul 21 19:47 Session_20170721_194658_{49a6f90a-bb14-40fa-a864-0310465c9a82}
drwxr-xr-x 2 root root 4096 Jul 21 19:15 Session_20170721_191532_{5c9e048a-39e0-4d84-ad69-2f6465df60a5}

/var/log/veeam/Backup/BackupJob1/Session_20170728_154205_{20920194-caea-480a-bbe6-aee0db4bc3ee}# ls -lat
total 308
-rw-rw-r-- 1 root root 96705 Jul 28 15:48 Job.log
-rw-rw-r-- 1 root root 106287 Jul 28 15:48 Agent.Target.log
-rw-rw-r-- 1 root root 66602 Jul 28 15:48 Agent.Source.log
drwxr-xr-x 2 root root 4096 Jul 28 15:42 .
-rw-rw-r-- 1 root root 28776 Jul 28 15:42 Agent.Repair.log
drwxr-xr-x 6 root root 4096 Jul 28 15:42 ..
rui.rodrigues
Novice
 
Posts: 4
Liked: never
Joined: Thu Feb 23, 2017 10:43 pm
Full Name: Rui Rodrigues

Re: Backup Notification Linux

Veeam Logoby vmniels » Fri Jul 28, 2017 3:13 pm

That specific info is not in a file available. However you can find info in the database (/var/lib/veeam/veeam_db.sqlite). Other options are using scripts after the job has ran showing info based on the sessions (for example veeamconfig session list | grep -e UUID -e Failed | mailx -s "VAL session Failed" someone@somewhere.com )

If you have Veeam Backup & Replication you can send backup to the backup repo there and let it handle the mailflow.
VCP-DCV
Veeam Certified Architect (VMCA)
http://foonet.be
vmniels
Veeam Software
 
Posts: 1885
Liked: 406 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Backup Notification Linux

Veeam Logoby grufo » Wed Sep 27, 2017 7:11 am

I tried to build a notification script which provides nearly the same information as the windows agent notification...

Screenshots and download:
http://blog.grufo.com/2017/09/26/veeam-agent-for-linux-mit-e-mail-bericht-versehen/
grufo
Lurker
 
Posts: 1
Liked: never
Joined: Wed Sep 27, 2017 4:50 am
Full Name: Manfred

[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: 1885
Liked: 406 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: 3906
Liked: 330 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: 1885
Liked: 406 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

PreviousNext

Return to Veeam Agent for Linux



Who is online

Users browsing this forum: No registered users and 4 guests