Pre / Post Job Scripts

VMware specific discussions

Pre / Post Job Scripts

Veeam Logoby electricd7 » Thu Aug 27, 2015 2:48 pm

All-

I have a backup job which backs up only a single VM. I would like to execute a script before the snapshot for the machine takes place that will actually run on the target VM. Then backup the machine normally, then run another script on the target VM after the backup. I know Veeam allows for running scripts before/after jobs, but these scripts are run locally on the Veeam server, correct? Can I use a powershell script, or am I limited to bat/cmd scripts?

Chad
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby v.Eremin » Thu Aug 27, 2015 2:52 pm

Check pre-freeze, past-thaw scripts; seems to be something you're looking for. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre / Post Job Scripts

Veeam Logoby electricd7 » Thu Aug 27, 2015 3:16 pm

so scripts that I specify on the application settings for the VM are executed locally on the VM, ie if I put c:\script.bat, that is referencing the C drive on the VM itself and not the veeam server? The pre-freeze script would be OK, but I would need to run the after-job script not after the snapshot is taken, but rather after the job completes. Can I use powershell scripts on either the pre/post freeze, or the advance settings pre-post job script areas?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby v.Eremin » Thu Aug 27, 2015 4:36 pm

so scripts that I specify on the application settings for the VM are executed locally on the VM, ie if I put c:\script.bat, that is referencing the C drive on the VM itself and not the veeam server?

Scripts should be located on a backup server. During backup, those will be uploaded inside the guests. You can either convert PS script to .bat or make .bat execute PS. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre / Post Job Scripts

Veeam Logoby electricd7 » Thu Aug 27, 2015 5:10 pm

OK, so the scripts available within the pre/post thaw will not work for me. I need to do this on the Storage - Advanced - Advanced Settings for the Veeam job itself as I want the scripts to be run with the start and end of the job, not necessarily with the backed up VM snapshot create. Under what security context are those scripts executed when scheduled from that screen?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby electricd7 » Thu Aug 27, 2015 7:10 pm

OK, so I have it working for the most part, but I need to pass a variable to the script inside the call from Veeam. I have tried both of the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Auto\Oracle\StopOracle.ps1 foo"
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Auto\Oracle\StopOracle.ps1" foo

But neither of those work as the argument "foo" doesn't get passed to the powershell script. How would I go about passing "foo" to the file I am calling into powershell?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby v.Eremin » Fri Aug 28, 2015 8:51 am

The first variant should, as long as, there is something inside the script expecting an argument:

Code: Select all
param ([string]$something)
Write-Output $something


Code: Select all
PowerShell.exe -File "C:\Auto\Oracle\StopOracle.ps1 foo"

Once the command is executed $Something should have foo as its value.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre / Post Job Scripts

Veeam Logoby electricd7 » Fri Aug 28, 2015 12:28 pm

I am using the following as top lines of my script, but I don't think the variable is getting sent from the command line in the Veeam script text box:

Code: Select all
IF ($args.length -ne 1){Exit}

Switch ($args){
  "foo" {
$oracleserver = "server1"
$batpath = "c:\shutscript.bat"}
  "foo2" {
$oracleserver = "server2"
$batpath = "F:\shutscript.bat"}
}


I will try again and see if maybe I had something wrong.
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby electricd7 » Fri Aug 28, 2015 5:49 pm

Yea that definitely doesn't work. I get "Pre-job script teminated with exit code -196608" when I run it as suggested:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\Auto\Oracle\StopOracle.ps1 foo"

I also tried changing my script to use param instead of $args. Same results.
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: Pre / Post Job Scripts

Veeam Logoby v.Eremin » Mon Aug 31, 2015 12:04 pm

As a first investigation step, I'd probably remove switch statement and add some checks, instead, to see whether the string value is passed to $args properly.

Code: Select all
$args[0] > C:\Check.txt


Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Pre / Post Job Scripts

Veeam Logoby jkyriazakos » Tue Dec 15, 2015 10:40 am

Hi all,
Did you manage to find a solution? Although my scripts are working right, Veeam B&R is never happy with the exit code... :(
jkyriazakos
Lurker
 
Posts: 2
Liked: never
Joined: Wed Mar 06, 2013 5:25 pm
Full Name: John Kyriazakos

Re: Pre / Post Job Scripts

Veeam Logoby PTide » Tue Dec 15, 2015 10:47 am

Hi,

Veeam B&R is never happy with the exit code
Have you tried appending the following line to your script?

Code: Select all
exit /b 0


That will force your script to return "0" (VBR considers zero as "success")

Thank you.
PTide
Veeam Software
 
Posts: 3017
Liked: 245 times
Joined: Tue May 19, 2015 1:46 pm

[MERGED]: post-job script terminated with exit code 1

Veeam Logoby pacorus » Thu Dec 17, 2015 11:27 am

I have a task that running gives this error.
The task has a fichero.bat running before launching the JOB
fichero.bat works ok from the console of Microsoft MS-DOS
Can you help me?
pacorus
Lurker
 
Posts: 1
Liked: never
Joined: Thu Dec 17, 2015 11:16 am

Re: Pre / Post Job Scripts

Veeam Logoby PTide » Thu Dec 17, 2015 11:44 am

Hi,

fichero.bat works ok from the console of Microsoft MS-DOS
If you want to disable a warning message you can force your script to return zero, please see this thread to know how to do that. Anyway I'd check which part of the script throws an error.

Thank you.
PTide
Veeam Software
 
Posts: 3017
Liked: 245 times
Joined: Tue May 19, 2015 1:46 pm

Re: Pre / Post Job Scripts

Veeam Logoby lp@albersdruck.de » Wed Apr 20, 2016 1:14 pm

I would like to have scripts that run before/after the job, but for the script to run on the target and not on the Veeam server itself.

What do I need this for?
Backup Copy Job, target is a linux server. I would like to mount the backup repository locally before the job starts and unmount it afterwards, so that the repository is only mounted when the job runs and not when it is not needed.
lp@albersdruck.de
Enthusiast
 
Posts: 81
Liked: 31 times
Joined: Mon Mar 25, 2013 7:37 pm
Full Name: Lars Pisanec

Next

Return to VMware vSphere



Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 21 guests