Comprehensive data protection for all workloads
mzamesnik
Novice
Posts: 9
Liked: 2 times
Joined: Jun 25, 2012 5:44 pm
Full Name: Mike Zamesnik
Contact:

Variables for pre/post job scripts

Post by mzamesnik »

Are there a list of valid variables that can be used as parameters in the pre/post job scripts? I am particularly interested in whether or not the job name can be passed as an argument to the script i want to run before the job.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

You mean you want to pass something like %Name? If so, it's not possible, and you should get a job name inside a script. Thanks.
mzamesnik
Novice
Posts: 9
Liked: 2 times
Joined: Jun 25, 2012 5:44 pm
Full Name: Mike Zamesnik
Contact:

Re: Variables for pre/post job scripts

Post by mzamesnik » 1 person likes this post

Yes, that is what I had hoped to do. This way I could build a single script that would use the job name as a variable, if I wanted to affect that particular job - as opposed to creating a unique script for each job. It's not a deal breaker. Just a convenience I had hoped existed. I was able to go about it a different way. Thanks for your reply. Sorry for my late reply.
Gostev
Chief Product Officer
Posts: 31456
Liked: 6646 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Variables for pre/post job scripts

Post by Gostev » 1 person likes this post

It's a good idea to add.
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Variables for pre/post job scripts

Post by tsightler » 3 people like this post

Wow, interestingly I just had this very same requirement. I'm curious how you solved it. I came up with the following hack that I just posted on our internal forums yesterday:

Code: Select all

$parentpid = (Get-WmiObject Win32_Process -Filter "processid='$pid'").parentprocessid.ToString()
$parentcmd = (Get-WmiObject Win32_Process -Filter "processid='$parentpid'").CommandLine
$job = Get-VBRJob | ?{$parentcmd -like "*"+$_.Id.ToString()+"*"}
$session = Get-VBRBackupSession | ?{($_.OrigJobName -eq $job.Name) -and ($parentcmd -like "*"+$_.Id.ToString()+"*")}
This looks up the parent process ID of the Powershell session, which in the case of pre/post-scripts is the Veeam.Backup.Manager.exe that controls the job session. The script then grabs the command line used to start said manager process process which as it happens includes the Veeam job and session UUID. This typically looks something like this:

Code: Select all

"C:\Program Files\Veeam\Backup and Replication\Backup\Veeam.Backup.Manager.exe" "startbackupjob" "owner=[vbsvc]" "Normal" "a6782dae-5ebe-4aab-9cb3-3a75827dff22" "a432e43e-b17c-4778-b9d2-e8d6519526ea"
It then does a crude match on these UUIDs to find the actual job and session PS objects and I'm good to go with all of the information I need even with nothing passed in. I should improve the match code as right now it could potentially get the wrong job if somehow a session ID was exactly the same as a job ID or vice-versa. This seems pretty much impossible to occur in the real world but when I have a few minutes I'll add a little logic to address that.

Still, I'd love to hear how you attacked the problem, perhaps it was a better method.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

mzamesnik wrote:Yes, that is what I had hoped to do. This way I could build a single script that would use the job name as a variable, if I wanted to affect that particular job.
So, the %JobName variable for pre/post-job scripts and %VMname for pre-freeze/post-thaw VM scripts should be enough, right? As having those variables would allow to catch whatever specific information you want to. Thanks.
heydonms
Novice
Posts: 3
Liked: never
Joined: Aug 12, 2013 12:39 am
Full Name: Michael Heydon
Contact:

Re: Variables for pre/post job scripts

Post by heydonms »

v.Eremin wrote:So, the %JobName variable for pre/post-job scripts and %VMname for pre-freeze/post-thaw VM scripts should be enough, right?
For pre/post-job scripts I would add:

Whether the backup run will be/was full/incremental

and for post-job scripts

Whether the backup completed with success/warning/partial/failed/etc.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

Got it. Though, having the described variables ($VMName and $Jobname) it would be pretty simple to get that information inside the code itself.
ekisner
Expert
Posts: 202
Liked: 34 times
Joined: Jul 26, 2012 8:04 pm
Full Name: Erik Kisner
Contact:

Re: Variables for pre/post job scripts

Post by ekisner »

Just wanted to post my support for this, if it has not yet been implemented.

In our case, we're getting service management software finally, which I would like to leverage via APIs. At the end of a job, if the job failed, log a ticket with the SM with a specific name (checking for existing tickets first to ensure that the system doesn't get spammed). The SM software uses soap so I can talk to it with powershell easily.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

The said functionality has not been implemented yet. But it's still on our radar. Thanks.
fgw
Enthusiast
Posts: 84
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: Variables for pre/post job scripts

Post by fgw »

guys i searched the forums and the internet and was not able to find any answer to this!

question remains: is this still not implemented?

come on this is not rocket science! it should be fairly easy for veam devs to implement passing ALL AVAILABLE parameters - and im not talking about jobnnames only - im talking about jobname, retry count, max retries configured, last result, whatever ...

actually retry count and max retries configured seems of most importance to me. i does not make any sense to start the post processing action as long as the job might retry to run. the script needs to know if this was the last retry or not in order to start processing its tasks e.g. start copy the backup somewhere!

pls dont get me wrong! this is not meant to be offensive in any way! its just soo simple and i suppose of almost no work for veeam but of so much help for us admins out there! so pls implement this. this is already done for post job mails! pls implement this for post job scripts too!

if i missed it and its already implemented, pls point me to the right location where this is documented! i simply was not able to find it.

THANKS
Gostev
Chief Product Officer
Posts: 31456
Liked: 6646 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Variables for pre/post job scripts

Post by Gostev »

Hi, Franz. We prioritize [hundreds] of pending feature requests based on demand and as you can see, there were too few requests for this functionality for now. Thanks!
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

it should be fairly easy for veam devs to implement passing ALL AVAILABLE parameters - and im not talking about jobnnames only - im talking about jobname, retry count, max retries configured, last result, whatever ...
I still believe that having job name as a variable should be enough, since with this parameter at hand it will be fairly easy to get all other properties via our PowerShell snap-in.

And for now you can stick to the workaround coined by Tom, until we get that functionality implemented.

Thanks.
jonheese
Lurker
Posts: 1
Liked: never
Joined: Feb 26, 2016 5:31 pm
Full Name: Jon Heese
Contact:

Re: Variables for pre/post job scripts

Post by jonheese »

Gostev wrote:Hi, Franz. We prioritize [hundreds] of pending feature requests based on demand and as you can see, there were too few requests for this functionality for now. Thanks!
Where do we need to go to vote for/request this feature? Thanks.
fgw
Enthusiast
Posts: 84
Liked: 2 times
Joined: Jun 11, 2009 8:39 pm
Full Name: Franz Glatzer
Contact:

Re: Variables for pre/post job scripts

Post by fgw »

the reason i need this is to decide if certain actions in this script needs to be performed based on job status!

as stated earlier, it doesn't make any sense to trigger copy of the backup file to second location when the job failed and probably will start a retry in a couple of minutes ...

thus i would like to see "Last Result", "Retry Count", and "Retries performed".

that way its easy to figure out if this was already the last retry: "Retry Count" == "Retries performed"

or there are some more retries pending: "Retry Count" > "Retries performed"

and of course "Last Result" as it does also make no sense to copy failed backups.

well, it might be sufficient to just have "Last Result" passed, as if the job was successful there won't be any more retries anyway ...

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!

to get the nameof the vm within the pre/post thaw scripts shouldn't be much of a problem either. suppose u can use %COMPUTERNAME% on windows and probably $hostname on unix?

reason for coming back here:
actually i thought i can come around the use of post scripts to copy backupfiles to a secondary location. as nice as "backup copy" and "file copy" jobs are, they perform very bad in my environment. they are nicely integrated and offer sweet features but my problem is performance! did some testing and figured out copying the backupfiles between windows server using copy is about 2 times faster than copying the very same data through veeam! and this scales nicely with network bandwidth also.

have no idea why "backup copy" and "file copy" is so slow here, may be i have setup something odd, but i doubt as setting this up is very straight forward!

so i'm back to the start again and consider using scripts for this task. and that's where my problem popped up again ...

ps. will open a thread tomorrow with the figures regarding transfer speeds i observed . late here already, too lazy now!
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Variables for pre/post job scripts

Post by tsightler »

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.
zaf
Service Provider
Posts: 7
Liked: 1 time
Joined: Jan 11, 2016 7:08 pm
Full Name: Tim Fournet
Contact:

Re: Variables for pre/post job scripts

Post by zaf »

I would like to see this implemented as well
AdamR
Novice
Posts: 4
Liked: never
Joined: Nov 04, 2013 11:42 am
Full Name: Adam
Contact:

[MERGED] run PRE or POST scripts with argument

Post by AdamR »

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%
danic
Novice
Posts: 3
Liked: never
Joined: Nov 16, 2016 4:18 pm
Contact:

[MEGED] Powershell - Sync Copy Jobs

Post by danic »

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

Re: Variables for pre/post job scripts

Post by veremin »

Check the answer provided by Tom on the first page to see how your goal can be achieved. Thanks.
danic
Novice
Posts: 3
Liked: never
Joined: Nov 16, 2016 4:18 pm
Contact:

Re: Variables for pre/post job scripts

Post by danic »

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?
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Variables for pre/post job scripts

Post by tsightler »

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.
danic
Novice
Posts: 3
Liked: never
Joined: Nov 16, 2016 4:18 pm
Contact:

Re: Variables for pre/post job scripts

Post by danic »

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?
daphnis
Enthusiast
Posts: 47
Liked: 3 times
Joined: Jun 13, 2012 7:01 pm
Contact:

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

Post by daphnis »

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: Jun 13, 2012 7:01 pm
Contact:

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

Post by daphnis »

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: Jun 13, 2012 7:01 pm
Contact:

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

Post by daphnis »

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

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

Post by veremin »

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.
daphnis
Enthusiast
Posts: 47
Liked: 3 times
Joined: Jun 13, 2012 7:01 pm
Contact:

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

Post by daphnis »

Thanks for your replies.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Variables for pre/post job scripts

Post by veremin »

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.
AndyBG
Novice
Posts: 3
Liked: 1 time
Joined: Oct 05, 2022 5:35 pm
Full Name: Andy G
Contact:

Re: Variables for pre/post job scripts

Post by AndyBG » 1 person likes this post

tsightler wrote: Mar 25, 2015 1:47 am I came up with the following hack that I just posted on our internal forums
Sorry for digging up an old thread. Google lead me here and I wasn't sure if a better approach has been developed since then. If so, please let me know.

If it is still relevant, I was looking for a better way to report on the outcome of a backup job than the stock email or community script (which takes many hours in a large environment).

I have taken the code snippet and made some changes that have a big impact in environments with lots of jobs and lots of sessions where running `Get-VBRJob` and `Get-VBRBackupSession` is a 15 - 20 minute affair.

Since the session GUID is passed in the process commandline, it looks like we can jump straight to the session which includes things like the jobname if needed.

Code: Select all

$parentPID = (Get-CimInstance Win32_Process -Filter "processid=$pid").parentprocessid
$parentCMD = (Get-CimInstance Win32_Process -Filter "processid=$parentpid").CommandLine
$parentCMDSplit = $parentCMD.split('"')
$parentCMDSplitNS = $parentCMDSplit | Where {-not [string]::IsNullOrWhiteSpace($_)}
$currentJobSessionGUID = $parentCMDSplitNS[-1].replace('"','')
$currentJobSession = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($currentJobSessionGUID)
Now it runs in a few seconds :)
Post Reply

Who is online

Users browsing this forum: Google [Bot], xzvf and 196 guests