Variables for pre/post job scripts

Availability for the Always-On Enterprise

Re: Variables for pre/post job scripts

Veeam Logoby tsightler » Sun Feb 28, 2016 11:58 pm

fgw wrote:regarding the way to get jobname within the script as posted earlier:

as scripts are configured for every job individually, it can be done pretty easy by passing the name of the job as parameter to the script. of course this wont help in getting UUID if thats needed also!


I'm not sure you are understanding the scripts I posted above as they don't require any per-job configuration, that was the entire purpose of creating them since I had a client that needed some special tape setup for dozens of jobs and I didn't want to have to have a different script command for every single job. You don't have to pass the script the UUID, or anything else for that matter. The commands automatically discover the job UUID by detecting it from the parent process that called the script.
tsightler
Veeam Software
 
Posts: 4843
Liked: 1787 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Variables for pre/post job scripts

Veeam Logoby zaf » Mon May 23, 2016 1:53 pm

I would like to see this implemented as well
zaf
Service Provider
 
Posts: 7
Liked: 1 time
Joined: Mon Jan 11, 2016 7:08 pm
Full Name: Tim Fournet

[MERGED] run PRE or POST scripts with argument

Veeam Logoby AdamR » Mon Jun 13, 2016 12:40 pm

Is it possible to run Pre-Freeze or Post-Thaw scripts with pass argument into the script?

When I tray run Pre- Freeze script and put in the path to the pre-freeze or post-thaw scripts name with argument, like this “D:\Script.bat stop” then gets an error
“Running pre-freeze script in the guest OS Error: Unable to find script file”

Passing arguments need to be able to minimize the number of scripts, we can use the same script as a PRE or POST (providing other argument).


The following sample BAT script (PRE or POST)
Code: Select all
@echo off
SET /A CODE_SUCCESS=0
SET /A CODE_ERROR_STOPPING=1
SET /A CODE_ERROR_STARTING=2
SET /A CODE_ERROR_NOARGUMENT=3
SET /A CODE_ERROR_BADARGUMENT=4
SET /A CODE_ERROR_OTHER=9

SET /A errno=%CODE_ERROR_OTHER%

if [%1] == [] goto NOARGUMENT
if %1 == stop goto STOP
if %1 == start goto START
goto BADARGUMENT



:NOARGUMENT
SET /A errno=%CODE_ERROR_NOARGUMENT%
goto END


:STOP
Net Stop "PostgreSQL"
if %ERRORLEVEL% NEQ 0 (
SET /A errno=%CODE_ERROR_STOPPING%
) else (
SET /A errno=%CODE_SUCCESS%
)
goto END


:START
net start " PostgreSQL "
if %ERRORLEVEL% NEQ 0 (
SET /A errno=%CODE_ERROR_STARTING%
) else (
SET /A errno=%CODE_SUCCESS%
)
goto END


:BADARGUMENT
SET /A errno=%CODE_ERROR_BADARGUMENT%
goto END


:END
Echo %errno%
exit /B %errno%
AdamR
Novice
 
Posts: 4
Liked: never
Joined: Mon Nov 04, 2013 11:42 am
Full Name: Adam

[MEGED] Powershell - Sync Copy Jobs

Veeam Logoby danic » Wed Nov 16, 2016 4:29 pm

Hi,

Is there a way to force a copy job sync via a post job task using powershell and param values for individual job names?

So far, I have managed to force a copy job using these commands:

Script:
Code: Select all
powershell.exe -File "C:\VeeamScripts\force_copyjob.ps1"


PS:

Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn
$Job = Get-VBRJob -name "Test - Backup Copy" --> hard-coded job name
Sync-VBRBackupCopyJob -Job $Job -FullBackup


Ideally, Veeam should make use of one PS script and use -JobName as parameter for the different jobs.:

Code: Select all
powershell.exe -noninteractive -Command "&{C:\VeeamScripts\force_copyjob.ps1 -jobName "Test - Backup Copy"}"


Thanks in advance.
danic
Novice
 
Posts: 3
Liked: never
Joined: Wed Nov 16, 2016 4:18 pm

Re: Variables for pre/post job scripts

Veeam Logoby v.Eremin » Wed Nov 16, 2016 5:04 pm

Check the answer provided by Tom on the first page to see how your goal can be achieved. Thanks.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Variables for pre/post job scripts

Veeam Logoby danic » Wed Nov 16, 2016 7:07 pm

Thanks for your comment. Just to clarify that what I require is that a Backup Copy job is synced via a PS script after its Daily job is finished (post job script).

In order to avoid having multiple scripts for all BC jobs I would like to use param values such -JobName. This works within an elevated PS session but fails within the Daily job itself - any pointers pls?
danic
Novice
 
Posts: 3
Liked: never
Joined: Wed Nov 16, 2016 4:18 pm

Re: Variables for pre/post job scripts

Veeam Logoby tsightler » Wed Nov 16, 2016 7:30 pm

You should be able to pass parameters via the cmdline, however, it can get a little tricky, especially if you have values with spaces that need quotes, since you'll need to escape the quotes. I don't have the exact syntax handy, but I'm sure I've posted it on the forum before so I'll try to dig it up.

However, you might find it easier to use the technique that I proposed earlier in this thread that would allow you to do what you want without passing any parameters. This makes it easier since you can use the exact same command on every job, and the script will just automatically determine which job called it and then properly run the appropriate backup copy job.

Let's take you example, assuming that the backup job is named "Test" the following script could be run as a post-job script and it would automatically sync the BCJ job called "Test - Backup Copy"

Code: Select all
# User defined variables
$copyJobSuffix = " - Backup Copy"

asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

# Determine job name from calling Veeam.Backup.Manager process
$parentPid = (Get-WmiObject Win32_Process -Filter "processid='$pid'").parentprocessid.ToString()
$parentCmd = (Get-WmiObject Win32_Process -Filter "processid='$parentPid'").CommandLine
$cmdArgs = $parentCmd.Replace('" "','","').Replace('"','').Split(',')
$jobName = (Get-VBRJob | ? {$cmdArgs[4] -eq $_.Id.ToString()}).Name

$copyJobName = $jobName + $copyJobSuffix

Sync-VBRBackupCopyJob -Job $copyJobName -FullBackup


This could obviously be tweaked to match different naming schemes for your specific environment. That way, as long as the naming scheme is followed, you don't have to pass any parameters at all so you can easily copy and paste the exact same script (or set it via Powershell) into every job and just let the script call the correct BCJ.
tsightler
Veeam Software
 
Posts: 4843
Liked: 1787 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Variables for pre/post job scripts

Veeam Logoby danic » Wed Nov 23, 2016 7:13 am

Script provided worked as intended - many thanks!
I have noticed that after the post script (Full BCJ sync) the copy interval is not reset and started the BCJ on a week day. Should I run the "Sync Now" option on a Friday to reset the copy interval?
danic
Novice
 
Posts: 3
Liked: never
Joined: Wed Nov 16, 2016 4:18 pm

[MERGED] Veeam able to pass internal params to pre-/post-scr

Veeam Logoby daphnis » Sun Oct 08, 2017 11:46 pm

Is/does Veeam capable of passing any parameters to pre- or post-job scripts? It's obviously possible to manually specify those, but is it possible for Veeam to pass, by default, certain metadata about the job that is calling those scripts? Just for example, if one had a script that accepted parameters and they didn't need to manually specify what should be passed in the command line. If Veeam passed its own parameters that could be harnessed by the script, they wouldn't need to be hard coded into the script or pre- post-job command line option.
daphnis
Enthusiast
 
Posts: 47
Liked: 3 times
Joined: Wed Jun 13, 2012 7:01 pm

Re: Veeam able to pass internal params to pre-/post-script

Veeam Logoby daphnis » Mon Oct 09, 2017 2:40 am

An unrelated question to the first but I couldn't edit the posting: Is it possible to surface script output back to the Veeam job status window? So rather than just returning, if true, "Pre-job script completed successfully", can it print output from Powershell? If so, how is that possible?
daphnis
Enthusiast
 
Posts: 47
Liked: 3 times
Joined: Wed Jun 13, 2012 7:01 pm

Re: Veeam able to pass internal params to pre-/post-script

Veeam Logoby daphnis » Mon Oct 09, 2017 3:46 pm

And yet another follow-up to make it three questions: Can I configure a pre- or post-job script to output information to the job log? I was hoping Write-Output statements would do this, but they do not. Is this possible?
daphnis
Enthusiast
 
Posts: 47
Liked: 3 times
Joined: Wed Jun 13, 2012 7:01 pm

Re: Veeam able to pass internal params to pre-/post-script

Veeam Logoby v.Eremin » Tue Oct 10, 2017 11:48 am

but is it possible for Veeam to pass, by default, certain metadata about the job that is calling those scripts?

Nope.

Is it possible to surface script output back to the Veeam job status window?

Nope.

Can I configure a pre- or post-job script to output information to the job log?

Theoretically that should be possible, since logs are nothing but text files which are totally modifiable via PowerShell, but personally I wouldn't do that - being unaware of log file structure and how and when log entities get updated, you can easily edit or remove valuable lines.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Veeam able to pass internal params to pre-/post-script

Veeam Logoby daphnis » Tue Oct 10, 2017 12:20 pm

Thanks for your replies.
daphnis
Enthusiast
 
Posts: 47
Liked: 3 times
Joined: Wed Jun 13, 2012 7:01 pm

Re: Variables for pre/post job scripts

Veeam Logoby v.Eremin » Tue Oct 10, 2017 3:30 pm

You're welcome. By the way, your post has been merged into existing discussion, so, you can check how other people address similar problem. Thanks.
v.Eremin
Veeam Software
 
Posts: 13558
Liked: 1006 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to Veeam Backup & Replication



Who is online

Users browsing this forum: Bing [Bot] and 59 guests