Host-based backup of VMware vSphere VMs.
Post Reply
electricd7
Expert
Posts: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Pre / Post Job Scripts

Post by electricd7 »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre / Post Job Scripts

Post by veremin »

Check pre-freeze, past-thaw scripts; seems to be something you're looking for. Thanks.
electricd7
Expert
Posts: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Re: Pre / Post Job Scripts

Post by electricd7 »

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?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre / Post Job Scripts

Post by veremin »

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.
electricd7
Expert
Posts: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Re: Pre / Post Job Scripts

Post by electricd7 »

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: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Re: Pre / Post Job Scripts

Post by electricd7 »

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?
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre / Post Job Scripts

Post by veremin »

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.
electricd7
Expert
Posts: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Re: Pre / Post Job Scripts

Post by electricd7 »

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: 121
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

Re: Pre / Post Job Scripts

Post by electricd7 »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre / Post Job Scripts

Post by veremin »

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.
jkyriazakos
Lurker
Posts: 2
Liked: never
Joined: Mar 06, 2013 5:25 pm
Full Name: John Kyriazakos
Contact:

Re: Pre / Post Job Scripts

Post by jkyriazakos »

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... :(
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Pre / Post Job Scripts

Post by PTide »

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.
pacorus
Novice
Posts: 7
Liked: never
Joined: Dec 17, 2015 11:16 am
Contact:

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

Post by pacorus »

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?
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Pre / Post Job Scripts

Post by PTide »

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.
lp@albersdruck.de
Enthusiast
Posts: 82
Liked: 33 times
Joined: Mar 25, 2013 7:37 pm
Full Name: Lars Pisanec
Contact:

Re: Pre / Post Job Scripts

Post by lp@albersdruck.de »

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.
nielsengelen
Product Manager
Posts: 5619
Liked: 1177 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Pre / Post Job Scripts

Post by nielsengelen »

You could make a script that does this via SSH on the specific Linux server.
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
mamosorre84
Veeam Legend
Posts: 336
Liked: 34 times
Joined: Oct 24, 2016 3:56 pm
Full Name: Marco Sorrentino
Location: Ancona - Italy
Contact:

Re: Pre / Post Job Scripts

Post by mamosorre84 »

Has someone done the post job-script to run on a guest Linux VM?
Post Reply

Who is online

Users browsing this forum: No registered users and 98 guests