Andys scripting corner - Post job command remote repository

PowerShell script exchange

Andys scripting corner - Post job command remote repository

Veeam Logoby Andreas Neufert » Tue May 08, 2012 8:10 am 1 person likes this post

Hi all,

On a project it took use some time to figure out how to run a post job script remote on the repository server (Backup to tape - h in this case IBM TSM).

Preparations:
1. Backup & Replication Management Server and Repository Server (Win) in the same AD Domain.
2. Backup & Replication Service Account as a Domain User Account which has Local Administrator rights at Management and Repository Server.
3. Follow the steps at this microsoft article to enable remote PowerShell > http://technet.microsoft.com/en-us/maga ... 00227.aspx

Command to start from Veeam Job "post job command"
Code: Select all
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\scripts\job1_post.ps1"

job1_post.ps1 on Management Server at C:\scripts\
Code: Select all
Invoke-Command -comp RepositoryFQDN -scriptblock {C:\scripts\TSM\job1.ps1}

At Repository Server under C:\scripts\TSM\job1.ps1
Code: Select all
C:\products\ibm\tsm\baclient\dsmc.exe incremental -optfile=C:\Scripts\TSM\veeamtest01_job1.opt >>c:\scripts\log\j1.txt

If the job didn´t start remote, you can check if the job1_post.ps1 works with a test command "mkdir c:\test" for example.

If you have any questions feel free to ask here.

CU Andy
Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby bmeyer99 » Tue May 08, 2012 10:12 pm

This may be a good feature request to have an option under the Post Job script to choose where to run the script. Either on the management backup server, a proxy server or the repository. The local agent could then run the script instead of the script having to run through the network.
Brandon Meyer - ProPartner in Chicago, IL
Ex-Veeam employee
bmeyer99
Veeam ProPartner
 
Posts: 681
Liked: 49 times
Joined: Tue Mar 01, 2011 5:14 pm
Location: Chicago, IL
Full Name: Brandon Meyer

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby mwant » Wed Jun 13, 2012 3:46 pm

I got this to work, many thanks. I just need to work out how to send a notification when its done now!

Brandon - Yes a good feature to have in the product as BR is usually separate from the management server.
mwant
Influencer
 
Posts: 13
Liked: never
Joined: Tue Oct 04, 2011 10:33 am
Full Name: m want

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby Andreas Neufert » Wed Jun 13, 2012 3:55 pm

Andreas Neufert
Veeam Software
 
Posts: 2201
Liked: 360 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby mwant » Thu Jun 14, 2012 10:32 am

Thanks very much Andreas.
mwant
Influencer
 
Posts: 13
Liked: never
Joined: Tue Oct 04, 2011 10:33 am
Full Name: m want

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Fri Jan 25, 2013 3:00 pm

Hi Andy,,
Have been trying to find out the best possible way to be able to copy only my vbk files from my exisiting backup repo to an external USB drive as Veeam post job activity. Have gone through the forums and have been trying out the scripts posted by different users. However for some reason it isnt working for me. Raised up this issue with support and they directed me to this forum.
My setup is basically simple. My Veeam server is a VM and the backup repo is a physical server. Once Veeam puts the vbks and vrbs on the backup server , i just need to copy them automatically to one external drive every month. I am not doing any rotation at the moment as I will be installing another dedup repo after a while. But for the time being need to copy just the vbks to the external drive.
Could you help me get a proper power shell script inorder to run it without any issues.
Thanks
zak2011
Expert
 
Posts: 367
Liked: 41 times
Joined: Tue May 15, 2012 2:21 pm
Full Name: Arun

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby v.Eremin » Sun Jan 27, 2013 10:55 am 2 people like this post

Unfortunately, I don’t a have a chance to take a look at a console closer right now. However, I believe first of all you should follow preparations steps mentioned by Andy, such as enabling remote PowerShell, placing VB&R server and Repository in the same AD domain, etc.

After having done it, you’ll be able to use invoke-command responsible for running command on local and remote computers.
Code: Select all
Invoke-Command -comp RepositoryFQDN -scriptblock {ScriptBlock}

Note: ScriptBlock is part of the script that will be implemented on remote machine.

If you’re willing just to copy corresponding backup files from local disks of your remote computer to external USB mounted to this server, then you can probably put into use Copy-Item method in ScriptBlock.

In order to use this method, you’ll have to specify source and target path. In the following examples the role of the souce path is played by D:\Repo\JobName and the role of target path (external USB) by E:\Test.

This example will copy all the items (including subfolders) from D:\Repo\JobName to E:\Test
Code: Select all
Copy-Item D:\Repo\JobName\* E:\test

This one only *vbk-files:
Code: Select all
Copy-Item D:\Repo\JobName\*.vbk E:\test


And in this example only the last created vbk will be copied to external USB:
Code: Select all
$LastVBK = Get-ChildItem D:\Repo\JobName\*.* -include *.vbk| Sort-Object CreationTime -Descending | Select-Object -First 1
Copy-Item $LastVBK E:\test


Feel free to play with the last parameter. E.g., if in the end of the month according to your retention policy you have two *vbk-files that need to be copied to external USB, you should use -First 2, instead of 1, etc.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Mon Jan 28, 2013 8:58 am

Thanks Vladimir for the options. Basically my requirement is to copy the vbks for now. So as you mentioned i need to try the last option.
I will check this out now and let you know the results.
Thanks again for the help.
zak2011
Expert
 
Posts: 367
Liked: 41 times
Joined: Tue May 15, 2012 2:21 pm
Full Name: Arun

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Mon Jan 28, 2013 10:57 am

Tried the script..but got this error

Code: Select all
PS C:\> Invoke-Command -comp backupsrv03 -scriptblock {Copy-Item B:\Veeam Backup
s\TIDBANK\*.vbk F:\TIDBANKSRV}
A positional parameter cannot be found that accepts argument 'F:\TIDBANKSRV'.
    + CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindi
   ngException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.CopyItemCommand

The target has the folder TIDBANKSRV.
zak2011
Expert
 
Posts: 367
Liked: 41 times
Joined: Tue May 15, 2012 2:21 pm
Full Name: Arun

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby v.Eremin » Mon Jan 28, 2013 12:30 pm 1 person likes this post

Try to put the source path into quotation marks and see whether it works. In fact, It's typical problem with the pathes that include spaces.

So, it shoud look like this:
Code: Select all
Invoke-Command -comp backupsrv03 -scriptblock {Copy-Item "B:\Veeam Backup
s\TIDBANK\*.vbk" F:\TIDBANKSRV}


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Mon Jan 28, 2013 1:18 pm

Thankyou very much Vladmir. You are right..the quotations marks were missing and therefore didnt work.
can i save this as a .ps1 file and run it as a post job activity directly?
Thanks
zak2011
Expert
 
Posts: 367
Liked: 41 times
Joined: Tue May 15, 2012 2:21 pm
Full Name: Arun

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby Sethbartlett » Mon Jan 28, 2013 3:11 pm 1 person likes this post

You could do that, just make sure you invoke powershell.exe with that script and you should be good.
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: Andys scripting corner - Post job command remote reposit

Veeam Logoby v.Eremin » Mon Jan 28, 2013 5:17 pm 2 people like this post

Providing you have followed all the aforesaid steps, there should be no issues related to this process.

In addition, be aware that you can only specify *cmd,*exe or *bat files as the job post-activity. So, there are three possible options for you in this case:

1. Convert you powershell script into a batch file (as described in the this article).

2.1. Create the bat file responsible for execution your PowerShell script, using the following command as a bat-file body:
Code: Select all
Powershell.exe -File C:\YourScript.ps1

2.2. Just follow Andy’s advice:
Code: Select all
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\scripts\job1_post.ps1"


Either way you’ll be able to meet your expectations.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Mon Jan 28, 2013 10:05 pm 1 person likes this post

Thanks a lot Vladimir. It was very straight forward to follow the steps you provided.Its working well now.
From the different threads i went through regarding copying veeam backup files offsite, Vladmir's post and Andys was the best
Thanks again.
zak2011
Expert
 
Posts: 367
Liked: 41 times
Joined: Tue May 15, 2012 2:21 pm
Full Name: Arun

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby v.Eremin » Tue Jan 29, 2013 7:00 am 1 person likes this post

Thank you, Arun, for kind words.
Should any other questions arise, don't hesitate to let me know.

Thanks again.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 974 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests