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: 4768
Liked: 1737 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: 6
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: 13266
Liked: 968 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: 4768
Liked: 1737 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

Previous

Return to Veeam Backup & Replication



Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 33 guests