Post Job Activity PowerShell BEMCLI

PowerShell script exchange

Post Job Activity PowerShell BEMCLI

Veeam Logoby matwraith » Wed Apr 25, 2012 2:22 pm

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/articles/preparing-your-powershell-environment-run-bemcli-and-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: Wed May 18, 2011 7:05 am
Full Name: MatW

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby matwraith » Wed Apr 25, 2012 2:51 pm

Mistake in previous post
I successfully tested the PowerShell script by running it from PowerSell NOT Command Prompt
matwraith
Novice
 
Posts: 3
Liked: never
Joined: Wed May 18, 2011 7:05 am
Full Name: MatW

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby ThomasMc » Wed Apr 25, 2012 2:58 pm

Can you try this

Code: Select all
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -File "d:\Scripts\script.ps1"
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby Sethbartlett » Wed Apr 25, 2012 6:05 pm

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.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby matwraith » Thu Apr 26, 2012 11:37 am

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
matwraith
Novice
 
Posts: 3
Liked: never
Joined: Wed May 18, 2011 7:05 am
Full Name: MatW

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby AGGFanatic » Wed Sep 26, 2012 7:04 am

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: Fri Aug 31, 2012 2:38 am
Full Name: Adam

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby AGGFanatic » Wed Sep 26, 2012 7:26 am

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?
AGGFanatic
Influencer
 
Posts: 21
Liked: 2 times
Joined: Fri Aug 31, 2012 2:38 am
Full Name: Adam

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby tsightler » Wed Sep 26, 2012 12:08 pm

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.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby AGGFanatic » Thu Sep 27, 2012 1:53 am

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: Fri Aug 31, 2012 2:38 am
Full Name: Adam

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby AGGFanatic » Tue Nov 20, 2012 8:48 pm

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?
AGGFanatic
Influencer
 
Posts: 21
Liked: 2 times
Joined: Fri Aug 31, 2012 2:38 am
Full Name: Adam

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby Tobias_Elfstrom » Fri Nov 23, 2012 9:48 am

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
}
Tobias_Elfstrom
Enthusiast
 
Posts: 84
Liked: 8 times
Joined: Wed Jul 04, 2012 6:32 am
Full Name: Tobias Elfstrom

Re: Post Job Activity PowerShell BEMCLI

Veeam Logoby payneful » Fri Jan 18, 2013 2:46 pm

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
   }
payneful
Novice
 
Posts: 3
Liked: 1 time
Joined: Mon Feb 28, 2011 8:25 pm
Full Name: R Payne


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 12 guests