PowerShell script exchange
Post Reply
matwraith
Novice
Posts: 3
Liked: never
Joined: May 18, 2011 7:05 am
Full Name: MatW
Contact:

Post Job Activity PowerShell BEMCLI

Post by matwraith »

I'm trying to run a Backup Exec job after a Veeam backup job completes so that I can archive Veeam backup files to tape.
I'm close to success but the 'post job activity' script does not start.
Here's what I've done so far: (as per http://www.symantec.com/connect/article ... nd-scripts)

Change PowerShell's execution policy
Edited Powershell profile file
Imported BEMCLI module into PowerShell and added the following line

Code: Select all

 import-module "D:\program files\symantec\backup exec\modules\bemcli\bemcli"
Added All Users, Current Host to profile
$Profile.AllUsersCurrentHost

I then created a PowerShell script to run BackUp Exec job and named it 'script.ps1'

Code: Select all

start-bejob -i "<BackUpExecJobName>-Full" -Confirm:$False
I have successfully tested the PowerShell script by running it from Command Prompt

Code: Select all

powershell d:\Scripts\script.ps1
or

Code: Select all

C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe 'd:\Scripts\script.ps1'
But when I copy either of the above lines into 'Post Job Activity' the BackUp Exec job does not start

Any ideas anyone?
matwraith
Novice
Posts: 3
Liked: never
Joined: May 18, 2011 7:05 am
Full Name: MatW
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by matwraith »

Mistake in previous post
I successfully tested the PowerShell script by running it from PowerSell NOT Command Prompt
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by ThomasMc »

Can you try this

Code: Select all

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "d:\Scripts\script.ps1"
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by Sethbartlett »

Make sure that the account running the Veeam service has access to these files also.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
matwraith
Novice
Posts: 3
Liked: never
Joined: May 18, 2011 7:05 am
Full Name: MatW
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by matwraith »

Seth,
Veeam Backup Service already set to Log on as Administrator

Thomas,
Adding the -Noninteractive -File and containing the script location with double quotes has solved the issue.

Thanks
AGGFanatic
Influencer
Posts: 21
Liked: 2 times
Joined: Aug 31, 2012 2:38 am
Full Name: Adam
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by AGGFanatic »

Hi Guys,

We are doing the same copying the files from Veeam to tape using BUE2012
However still cant get it going.

Here what we have done

Open powershell
Ran set-executionpolicy remotesigned
Ran import-module "\program files\symantec\backup exec\modules\bemcli\bemcli"

After this, how do we set profile?
And what do we put in our script.ps1?

Can someone please assist?

Thanks.
AGGFanatic
Influencer
Posts: 21
Liked: 2 times
Joined: Aug 31, 2012 2:38 am
Full Name: Adam
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by AGGFanatic »

Quick update

Cant seem to run the start-BEjob command in Powershell


PS C:\Windows\System32\WindowsPowerShell\v1.0> Start-BEJob -InputObject "Test123" -Confirm:$false
Start-BEJob : Cannot bind parameter 'InputObject'. Cannot convert value "Test123" to type "BackupExec.Management.CLI.BE
Job". Error: "Cannot find any Job objects with the name Test123."
At line:1 char:25
+ Start-BEJob -InputObject <<<< "Test123" -Confirm:$false
+ CategoryInfo : InvalidArgument: (:) [Start-BEJob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,BackupExec.Management.CLI.Commands.StartBEJobCommand


Is there something wrong? I've done all the prerequisites?
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by tsightler »

It's pretty much telling you what you did wrong with this message:
Cannot convert value "Test123" to type "BackupExec.Management.CLI.BEJob".
So basically you are passing a string to a parameter that expects a different type of object. I'm not familiar with BE powershell, but my guess is there's some type of "Get-BEJob" command to be able to retrieve the job object by job name, then pass this to the Start-BEJob, maybe something like:

Code: Select all

Get-BEJob -Name "Test123" | Start-BEJob -Confirm:$false
Once again, that's a total guess on my part, might have better luck on a BE forum.
AGGFanatic
Influencer
Posts: 21
Liked: 2 times
Joined: Aug 31, 2012 2:38 am
Full Name: Adam
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by AGGFanatic »

All good.
I got it going :)
Took some time, but eventually got it up and running.
:D :lol:
AGGFanatic
Influencer
Posts: 21
Liked: 2 times
Joined: Aug 31, 2012 2:38 am
Full Name: Adam
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by AGGFanatic »

Also now we need to advance the script.
I want to be able to run Full on Fridays and Diff from Mon to Thir with the command to reset archive bit.
Anyone able to share?
Tobias_Elfstrom
Enthusiast
Posts: 84
Liked: 8 times
Joined: Jul 04, 2012 6:32 am
Full Name: Tobias Elfstrom
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by Tobias_Elfstrom »

Not using BE this would be some guess work from me but since you have:

Code: Select all

start-bejob -i "<BackUpExecJobName>-Full" -Confirm:$False
I guess you also have:

Code: Select all

start-bejob -i "<BackUpExecJobName>-Diff" -Confirm:$False
and in that case you can simple check the day with in your powershell.
Something along these lines:

Code: Select all

# Get the day
$day = (Get-Date).DayOfWeek
if ($day -match "Friday") {
 # Do full backup
 Get-BEJob -Name $BEJobName-Full | Start-BEJob -Confirm:$false
} elseif (($day -match "Monday") -or ($day -match "Thusday")) {
# Do diff backups
 Get-BEJob -Name $BEJobName-Diff | Start-BEJob -Confirm:$false
} 
payneful
Novice
Posts: 3
Liked: 1 time
Joined: Feb 28, 2011 8:25 pm
Full Name: R Payne
Contact:

Re: Post Job Activity PowerShell BEMCLI

Post by payneful »

Just to make it interesting, this script backs up only Veeam changes with "one-time" incremenatal BackupExec job and changes media set to Daily or Weekend depending on hour and day of week (after 1pm on Friday and before 1pm on Monday is Weekend media set).It then removes the traces of the job from BackupExec. I only remove tapes once a week and I like to know what is on each tape.
"DCs.ps1" Contents follow:

Code: Select all

<##
Command to add to Veeam to execute Backup Exec Job
powershell.exe -command "& {Invoke-Command -computername falcon -filepath c:\bescripts\ps\DCs.ps1}"
##>

import-module bemcli
#
$a = get-date
$startdate = ((Get-Date).toshortdatestring()+" 00:01:00")
$dow = ($a).DayOfWeek
$th = ($a).hour
#$ts = $a.toshorttimestring()
#
if ( $dow -eq "Sunday" ) {
	$BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
	Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -Name "DCs to tape" `
	-FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
	-tapestoragemediaset "Tape Media Set Weekend" `
	| Wait-BEJob
	get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
	}
	elseif ( $dow -eq "Saturday" ) {
	$BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
	Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
	-FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
	-tapestoragemediaset "Tape Media Set Weekend" `
	| Wait-BEJob
	get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
	}
	elseif ( $dow -eq "Monday" -and $th -lt "13" ) {
	$BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
	Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
	-FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
	-tapestoragemediaset "Tape Media Set Weekend" `
	| Wait-BEJob
	get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
	}	
	elseif ( $dow -eq "Friday" -and $th -gt "13" ) {
	$BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
	Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
	-FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
	-tapestoragemediaset "Tape Media Set Weekend" `
	| Wait-BEJob
	get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
	}
	else {
	$BESel = New-BEFileSystemSelection -Path "D:\VeeamBackups\Backup Job DCs" -PathIsDirectory -Recurse -IncludeOnlyModifiedFiles -FromDate $startdate
	Get-BEAgentServer falcon | Submit-BEOnetimeBackupJob -BackupSetDescription "DCs to tape" -name "DCs to tape" `
	-FileSystemSelection $BESel -Storage "Dell LTO5 Robotic Library" `
	-tapestoragemediaset "Tape Media Set Daily" `
	| Wait-BEJob
	get-bejob -Name "DCs to tape*" | Remove-BEJob -Confirm:$false
	}
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests