Andys scripting corner - Post job command remote repository

PowerShell script exchange

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Tue Jan 29, 2013 8:59 am

Your welcome..
Unfortunately ran into some errors today again

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


Cant seem to find why this is failing. Is this because the job name has spaces in between or with the way the jobs are named?

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 » Tue Jan 29, 2013 9:50 am

In the way I see it, It happens due to the fact that your target path does have spaces, and meanwhile isn't put into quotation marks.

Proper example should look this:

Code: Select all
PS C:\> Invoke-Command -comp backupsrv03 -scriptblock {Copy-Item "B:\Veeam Backu
ps\Terminal Server Backups\*.vbk" "F:\Terminal Server Backups"}


Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 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 » Tue Jan 29, 2013 10:44 am

Thanks Vladmir. I will try this out and update you.
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 » Wed Jan 30, 2013 8:50 am

The vbks are getting copied..however for some jobs only one vbk gets copied when there are two vbks in the source , and for some jobs each time the job runs the same vbks get copied again..and for the other jobs both the vbks at the source and target are exact.
Any particular reason for this?

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 » Wed Jan 30, 2013 3:16 pm 1 person likes this post

In fact, copy-item method can’t be noticeable for very thoughtful approach of copying file. Each time it just copies existing files, as is, rewriting files with identical names.

In order to answer your requirements you should slightly modify your code, adding verification means responsible for checking names and dates of modification.

Otherwise, you can put into use Robocopy utility which is a command-line directory replication command. By default, Robocopy will only copy a file if the source and destination have different time stamps or different file sizes.

Syntax should be as the following:
Code: Select all
Invoke-Command -comp backupsrv03 -scriptblock {robocopy “Source path” *.vbk “Target path”;}


Furthermore, it’s much more preferable to use Robocopy in this case.

More information about Robocopy parameters can be found here.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 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 » Thu Jan 31, 2013 7:59 am

I have used Robocopy earlier however..if i would be able to acheive the same thing using copy-item method..i would prefer using that.
How do you add the verification part to this?
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 » Thu Jan 31, 2013 1:00 pm 2 people like this post

I believe something like this should work in case of using Copy-Item method:

Code: Select all
$SourcePath = "Your source path"
$TargetPath = "Your target path"
$filessource = Get-ChildItem $SourcePath\*.vbk
$filesdestination = Get-ChildItem $TargetPath\*.vbk
$DontCopy = $False
If($filesdestination.count -eq "0")
{
 Copy-Item $filessource $TargetPath
}
else
{
  foreach($FilestoCopySource in $filessource)
  {
    foreach($FilestoCopyDestination in $Filesdestination)
    {
     If ($FilestoCopySource.Name -eq $FilestoCopyDestination.Name)
     {
       if($FilestoCopySource.LastWriteTime -eq $FilestoCopyDestination.LastWriteTime)
       {$DontCopy = $True}
     }
    }
    If($DontCopy -ne $True) {Copy-Item $FilestoCopySource $TargetPath}
    $DontCopy = $False
  }
}

Firstly it checks if there are some *.vbk-files on your target already. If no, all .vbks are copied from source to the target.

If yes, it takes existing .vbk-files one by one from your source location and starts comparing their names and modification dates with the .vbk-files residing on target location. If there is no .vbk files with such name, or, modification dates of files with identical names don’t coincide, corresponding .vbk-files will be copied. The only exception is a case of full coincidence (name=name, LastWriteTime=LastWriteTime).

Be aware that It’s nothing but a rough example with a lot of space for improvement (some kind of size check can be added, for instance). Thus, feel free to modify it however you want.

Nevertheless, it doesn’t stand to any good reason to perform all of necessary actions manually, since Robocopy utility was deliberately created to meet such requirements. Furthermore, it does provide much more functionality along with flexibility, comparing with abovementioned script. Hence, I’m still wondering what your motivation is for not using it.

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

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby Martin9700 » Thu Jan 31, 2013 2:16 pm

I concur, this is what Robocopy was built for. Microsoft is even bundling it with Windows 2008R2 and higher now so they're good with it :)
Martin
www.thesurlyadmin.com
@thesurlyadm1n
Martin9700
Influencer
 
Posts: 17
Liked: 3 times
Joined: Wed Nov 10, 2010 2:18 pm
Location: Massachusetts
Full Name: Martin Pugh

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby zak2011 » Thu Jan 31, 2013 2:38 pm

Thanks Vladmir for the code. Thats true Robocopy has much functionality also.
Previously i have had to use Robocopy in situations where it was not possible to install backup agents on the some customized servers. It came in handy then..however i ran into some issues.
I can try Robocopy and see.

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 Andreas Neufert » Thu Jan 31, 2013 4:39 pm 1 person likes this post

Thanks for the help and feedback :-)
Andreas Neufert
Veeam Software
 
Posts: 2198
Liked: 357 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 eantonio » Mon Jun 15, 2015 2:45 pm

I'm trying to execute a Veeam backup job from a remote server. When I run the Invoke-Command, it is saying the "Start-VBRJob" is not recognized as the name of the cmdlet. Can you please advise what I'm doing wrong here?

I have winRM already running and enabled remotesign.
eantonio
Influencer
 
Posts: 24
Liked: never
Joined: Tue Jan 27, 2015 9:14 pm
Full Name: Emil Antonio

Re: Andys scripting corner - Post job command remote reposit

Veeam Logoby v.Eremin » Mon Jun 15, 2015 2:49 pm

Is Veeam PS snap-in installed on the remote machine? Do you have "asnp VeeamPSSnapin" portion inside invoke-expression? Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests