Scripting

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

Scripting

Veeam Logoby Alvi » Thu Jul 28, 2016 8:09 am

Sorry, but I can't find further documentation about the command-line parameters of veeamconfig, and the short help is rather short...

I want to start a job by a script, let's wait the script for ending up the job and then continue.

This would be for:
- mount the destination directoy
- run the backup
- unmount the destination

When running "veeamconfig job start --name FullBackup" the job starts and I am ending up in command line.
How does my script knows when the started job ended?

Maybe you have a sample bash script to to this job?
Alvi
Influencer
 
Posts: 12
Liked: 10 times
Joined: Wed Jul 08, 2015 10:19 am

Re: Scripting

Veeam Logoby vmniels » Thu Jul 28, 2016 8:19 am

Currently you can't add post job scripts but this will be added.

Currently you'll have to monitor the logs for a success or failure.
VCP-DCV
Veeam Certified Engineer
http://foonet.be
vmniels
Veeam Software
 
Posts: 1555
Liked: 340 times
Joined: Mon Jul 15, 2013 11:09 am
Full Name: Niels Engelen

Re: Scripting

Veeam Logoby davide.depaoli » Thu Jul 28, 2016 12:48 pm 2 people like this post

Alvi,
I've tried to write a simple script, you can find in this post.

Hope it can help you.
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 Jul 28, 2016 1:53 pm 2 people like this post

Hi,

Here is a piece of code that starts "JobName1" job and waits until it finishes its current session, and then checks its failure/success status:

Code: Select all
veeamconfig job start --name BackupJob1
sessionID=$(veeamconfig session list | grep BackupJob1 | grep Running | awk '{print $3}')
while [[ $(veeamconfig session list | grep BackupJob1 | grep Running) ]]; do
:
done
if [[ $(veeamconfig session list | grep $sessionID | grep Success) ]]; then
        echo "Success!"
else
        echo "Failed!"
fi
PTide
Veeam Software
 
Posts: 3084
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Scripting

Veeam Logoby Alvi » Fri Jul 29, 2016 8:22 am

davide.depaoli wrote:Hope it can help you.


You did, thanks a lot!
Seem's like Veeam improved your version now, hope they will spend you a pizza :roll:

PTide wrote:Here is a piece of code that starts "JobName1" job and waits until it finishes its current session, and then checks its failure/success status:

Just took yours, I placed a "sleep 10" within the while-loop. Don't know if uses more or less cpu this way... Using the sleep indeed my script did not appear in top while waiting.

Works great for me,
thank you both, guys!
Alvi
Influencer
 
Posts: 12
Liked: 10 times
Joined: Wed Jul 08, 2015 10:19 am

Re: Scripting

Veeam Logoby chjones » Sun Jul 31, 2016 11:52 pm 1 person likes this post

When scripting for job success you need to make sure you also include the status of WARNING. Jobs can finish with a Success, Failure or Warning status. Warning means the job did complete, but there was an issue with a server, agent or component that should be investigated.
chjones
Enthusiast
 
Posts: 83
Liked: 25 times
Joined: Tue Oct 30, 2012 7:53 pm
Full Name: Chris Jones

Re: Scripting

Veeam Logoby davide.depaoli » Tue Sep 06, 2016 7:19 am 1 person likes this post

Hi all,
I have improved the script that launch the backup job and send email with job status. In this version the script tests all exit codes (Success, Warning, Failed) and if the job fails, attach to the email the related job.log file, in order to check what caused the error.

Hope it is useful.

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

JOBNAME=Backup_to_Cifs
export JOBNAME
TODAY=$(date +"%Y-%m-%d")
export TODAY
veeamconfig job start --name $JOBNAME

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

STATUS=`veeamconfig session list | grep $JOBNAME | grep $TODAY | awk '{print $4}'`
export STATUS

if [ $STATUS = Failed ]
   then
        LOGDIR=/var/log/veeam/Backup/$JOBNAME/*`veeamconfig session list | grep $JOBNAME | grep $TODAY | awk '{print $3}'`
        echo "Job $JOBNAME $STATUS" | mailx -s "VAL session $JOBNAME $STATUS"  -a $LOGDIR/Job.log -r VeeamLinuxAgent@mail.local my_email@email.it
   else
         echo "Job $JOBNAME $STATUS" | mailx -s "VAL session $JOBNAME $STATUS" -r VeeamLinuxAgent@mail.local my_email@email.it
fi
------------------------------
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 davide.depaoli » Tue Sep 06, 2016 10:46 am

My code has some bugs. I'm trying to correct errors and add more controls
------------------------------
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 » Tue Sep 06, 2016 1:31 pm

Hi,

In BETA2 pre/post-job scripts have been added thus until [ -z `pgrep veeamjobman` ] is not needed anymore.
PTide
Veeam Software
 
Posts: 3084
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Re: Scripting

Veeam Logoby davide.depaoli » Tue Sep 06, 2016 4:28 pm

PTide,
I'm just installed BETA but in the gui have not found pre/post script setup. Is there any cli switch to configure this ?
tnx
------------------------------
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 » Tue Sep 06, 2016 4:38 pm

If you create a new job then just specify --postjob parameter:
Code: Select all
veeamconfig job create --name job1 --objects /dev/sda --reponame Repo1 --postjob /email.sh


If you'd like to add a post-job script to the job that already exists then just edit the job:
Code: Select all
veeamconfig job edit --postjob /email.sh for --name job1


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

Re: Scripting

Veeam Logoby davide.depaoli » Tue Sep 06, 2016 4:56 pm

Ok.
Many thanks

Inviato dal mio ZP999 utilizzando Tapatalk
------------------------------
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 davide.depaoli » Wed Sep 07, 2016 10:50 am 1 person likes this post

Now it seems to work properly.
This script is intended to be used in crontab instead of the standard VAL schedule, and check:
- if another job is running; if yes, the second job aborts and send an email.
- if the job fails (status Failed) send an email with attached the logfile (Job.log).
- if the job ends successfully with warnings (status Warning) send an email with detail of warnings.
- if the job ends successfully send an email

During my few tests I did not find any malfunction, but I will be happy if someone will want to try and correct or improve it
Here the code.

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

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

# check if another job is running
if [ -s $JOBNAME.err ]
then
     STATUS=`grep Error /etc/veeam/scripts/$JOBNAME.err`
     echo "$STATUS " | mailx -s "VAL session $JOBNAME Error" -r VeeamLinuxAgent@email.local  recipient@email.com
     veeamconfig job delete --id $SESSION_ID
fi

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

STATUS=`veeamconfig session info --id $SESSION_ID | grep State | awk  '{print $2}'`
export STATUS

if [ $STATUS = 'Warning' ]
then
     WARN_MSG=`grep "Failed to backup" $LOGFILE | awk '{print $7,$8,$9,$10}' | sed 's/--asyncNtf:--wn://'`
     export WARN_MSG
     echo "Job $JOBNAME Successful with following $STATUS:            $WARN_MSG" | mailx -s "VAL session $JOBNAME $STATUS" -r VeeamLinuxAgent@email.local  recipient@email.com
fi

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

if [ $STATUS = 'Success' ]
then
     echo "Job $JOBNAME $STATUS" | mailx -s "VAL session $JOBNAME $STATUS" -r VeeamLinuxAgent@email.local  recipient@email.com
fi

rm -f /etc/veeam/scripts/$JOBNAME.tmp /etc/veeam/scripts/$JOBNAME.err


Now I try to modify it to use as postjob script.

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 davide.depaoli » Wed Sep 07, 2016 11:46 am

@PTide or any Veeam guy,

I'll need to know if is possible to remove a postjob script from a job. I have following workaround: export val configuration, edit the output file deleting the PostjobCommand (leaving "") and reimport the configuration.

veeamconfig job edit --postjob /email.sh for --name job1
Is there a complementary command to remove postjob ?

tnx
------------------------------
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 » Wed Sep 07, 2016 12:05 pm

Hi,

Currently that's the only way how you can remove scripts from the job settings. In GA scripts settings will be added to UI also CLI will be extended with extra commands.

Thank you!
PTide
Veeam Software
 
Posts: 3084
Liked: 252 times
Joined: Tue May 19, 2015 1:46 pm

Next

Return to Veeam Agent for Linux



Who is online

Users browsing this forum: No registered users and 4 guests