PowerShell script exchange
Post Reply
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

Foggy kindly suggested I ask in this forum :-

What I would like to do (for DR) is make an automated extra copy of my latest Full backup (on StoreOnce Catalyst) and pull it onto Windows storage. Just as a spare, to be imported to Veeam if the main store became unusable. The RP wouldn't have to be used directly from Windows storage (though a bonus if it could be). The V10 Catalyst Copy function apparently only copies from StoreOnce to StoreOnce, not to Windows, and I don't want to buy another StoreOnce.

For non-Catalyst backups (VAW) I can create & run a File Copy Job that copies a .vib from Windows server to Windows server - but VAW is not Catalyst. [I just chose a vib to test quickly: vbk should be no different]

For Catalyst jobs, I can manually select a Catalyst .vib (via Files page in the GUI) and copy it to a Windows server - but that is manual, not automated.

I figure that whatever I can do manually via the GUI I ought to be able to do via Veeam PowerShell/Data Management APIs - and PowerShell can be automated.

Is there a way in Powershell? The Add-VBRCopyJob looks initially hopeful - with Type=Files it creates a FCJ which could then be started/scheduled, but it rejects the name of the StoreOnce. Export-RestorePoint just puts the RP on the same storage, doesn't move it. Is there a command that simply duplicates the manual copy process of the GUI and allows Catalyst>Windows copy? It doesn't need to create a Veeam object (job or RP) - just copy the file(s).

Foggy has confirmed what I expected, that a copy from Catalyst will rehydrate the data.

TIA
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov » 5 people like this post

Hi Ian,
The Add-VBRCopyJob looks initially hopeful - with Type=Files it creates a FCJ which could then be started/scheduled, but it rejects the name of the StoreOnce.
Yes, it looks the name up in the list of host objects retrievable with Get-VBRServer. And StoreOnce appliance is not one of them.

Well, there are no long story shorts about that since we don't have cmdlets for the case you're asking. However, if you dig deeper into .NET types, you can find the following .NET implementation of copy/paste method for Files pane:

Code: Select all

#get source and target entities
$source = Get-VBRBackupRepository | where {$_.Type -eq 'HPStoreOnceIntegration'}
$target = Get-VBRServer -Name 'TargetHostName'

#create accessor for a source entity
$sourceAccessor = [Veeam.Backup.Core.CRepositoryAccessorFactory]::Create($source)

#get full backups in a source entity
$items = $sourceAccessor.FileCommander.EnumItems($source.Path)
$fulls = @()
foreach ($item in $items) {
$folder = $source.FriendlyPath + $item.Name
$backups = $sourceAccessor.FileCommander.EnumItems($folder)
 foreach ($backup in $backups) {
    if ($backup.Name -like '*vbk') {
        $fulls += $backup
    }
  }
}

<# Load binary file content you want to copy from source, where 18446744073709551615 is the maximum value for integer of UInt64 format in bytes.
Passed to the method below as a maximum value of data to load.#>
$content = $sourceaccessor.FileCommander.LoadFileContentBinary($fulls[0].FullName, 18446744073709551615)

#create accessor for a target entity
$targetAccessor = [Veeam.Backup.Core.CHostAccessor]::new($target, $true)

#copy loaded content to a target entity. It is essential to specify full path to the target file including its name.
$targetAccessor.FileCommander.SaveFileContentBinary('\\targetHostName\c$\temp\test.vbk', $content)
Please note that the method above is not officially supported and provided as a possible workaround for your case. Source and target entities used are exactly of StoreOnce and Windows types.
If you want to copy files between backup repositories precisely (e.g. between StoreOnce appliances and etc.), just switch the class for the target accessor:

Code: Select all

[Veeam.Backup.Core.CHostAccessor] => [Veeam.Backup.Core.CRepositoryAccessorFactory]
I tried to describe all the steps as detailed as possible, but feel free to reach me in case you have any further questions.

Hope that helps,
Oleg
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 » 1 person likes this post

Wow, thanks Oleg! That certainly deserves its Best Post Of The Week award! Looks like a good way to get expensively-deduped backups onto cheap storage. Now hide this, alongside a VBR server to run the script pulling the backups in, behind a 1-way firewall (physical access only), and you have an insurance policy against ransomware. As close as you can get to Fort Knox. Very much appreciated!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov » 1 person likes this post

Glad to help, Ian!
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

Hi Oleg,
I'm no Powershell expert, but I'm learning fast . . .
Based on the first part of your code, I can output $fulls as a list of matching backups, and can export that to a CSV - so I can see names & sizes etc. So my next step was to identify a small file and try to copy that to Windows using the rest of your code. I entered the filename in the search-string instead of *.vbk but the code is failing. I get the output entry, then error messages - something to do with your "::new" syntax, or am I doing something wrong (quite likely)? My code is lower down :-


Name : UMIS.ba4d2fa1-3fca-4555-ab89-6806f5546236D2020-06-26T230520_A5B0.vib
FullName : storeonce://HP4700MH:Virtual_Machines@/HV_Job6_1/UMIS.ba4d2fa1-3fca-4555-ab89-6806f5546236D2020
-06-26T230520_A5B0.vib
IsDirectory : False
IsSymlink : False
Size : 22178304
ModificationTime : 6/27/2020 2:34:26 AM
LocalModificationTime : 1/1/0001 12:00:00 AM
IsUnsupported : False
Error : 0
Exists : True
Flags : GenericCanAnything

Method invocation failed because [Veeam.Backup.Core.CHostAccessor] does not contain a method named 'new'.
At C:\scripts\VeeamPowershell\SO2W_Test2.ps1:37 char:1
+ $targetAccessor = [Veeam.Backup.Core.CHostAccessor]::new($target, $true)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

You cannot call a method on a null-valued expression.
At C:\scripts\VeeamPowershell\SO2W_Test2.ps1:40 char:1
+ $targetAccessor.FileCommander.SaveFileContentBinary('\\DPMHM1\c$\temp\test.vbk', ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

My code is :-

Code: Select all

Asnp VeeamPSSnapin 

#get source and target entities
#$source = Get-VBRBackupRepository | where {$_.Type -eq 'HPStoreOnceIntegration'}
$source = Get-VBRBackupRepository | where {$_.Name -eq 'HP4700MH'}
$target = Get-VBRServer -Name 'DPMHM1'

#create accessor for a source entity
$sourceAccessor = [Veeam.Backup.Core.CRepositoryAccessorFactory]::Create($source)

#get full backups in a source entity
$items = $sourceAccessor.FileCommander.EnumItems($source.Path)

$items

$fulls = @()
foreach ($item in $items) {
$folder = $source.FriendlyPath + $item.Name
$backups = $sourceAccessor.FileCommander.EnumItems($folder)
 foreach ($backup in $backups) {
    if ($backup.Name -like "UMIS.ba4d2fa1-3fca-4555-ab89-6806f5546236D2020-06-26T230520_A5B0.vib") {
        $fulls += $backup
    }
  }
}

$fulls
$fulls | Export-CSV "SO_Umis_inc.csv"

<# Load binary file content you want to copy from source, where 18446744073709551615 is the maximum value for integer of 

UInt64 format in bytes.
Passed to the method below as a maximum value of data to load.#>
$content = $sourceaccessor.FileCommander.LoadFileContentBinary($fulls[0].FullName, 18446744073709551615)

#create accessor for a target entity
$targetAccessor = [Veeam.Backup.Core.CHostAccessor]::new($target, $true)

#copy loaded content to a target entity. It is essential to specify full path to the target file including its name.
$targetAccessor.FileCommander.SaveFileContentBinary('\\DPMHM1\c$\temp\test.vbk', $content)
Any suggestions?
TIA
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

Ah, it looks like Powershell version. Currently 4.0. I'll download 5.1 & try again.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov »

To me looks like it's VBR version though. Which version do you have? Worked for me on v10 P2.
I'd suggest to try accessing [Veeam.Backup.Core.CHostAccessor] type using PowerShell ISE intellisense
and see if there is new() method at all. Check out this video for a guidance. Thanks!
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

You're probably right. We're on 9.5 U4b. Unfortunately, I already upgraded PS to 5.1 and now the code doesn't output anything.

Code: Select all

You cannot call a method on a null-valued expression.
At C:\scripts\VeeamPowershell\SO2W_Test2.ps1:12 char:1
+ $items = $sourceAccessor.FileCommander.EnumItems($source.Path)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
    
I'll have to remove the WMF5.1 update that upgraded PS, and get a bit more PS practice, while we think about upgrading Veeam to V10. Or perhaps just install the V10 console on my machine (I think that includes the VeeamPS stuff).
Thanks anyway.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov »

Now it looks like either $sourceAccessor or $source.Path are rendered empty for some reason.
Unfortunately, I don't have a lab with VBR 9.5 U4b and StoreOnce Catalysts at my disposal to test your case further properly,
but I'll ask around. Cheers!
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov »

I managed to test it in a lab with VBR v9.5 u4b and could copy files normally. PS version - 5.1.14393.1884
My other suggestion would be that when passing $source.Path as an argument for EnumItems() method, for some reason it doesn't convert Path from the object of CLegacyPath type to the link of string type. Try passing $source.FullPath.Root instead since it is of string type for sure:

Code: Select all

$items = $sourceAccessor.FileCommander.EnumItems($source.FullPath.Root)
Thanks!
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

Thank you very much Oleg, that fixed the problem and I transferred vib and vbm files fine. But when I tried a 41GB vbk file, the connection to the VBR server failed after 91 mins. I am running this on the VBR server, so it wasn't a physical break.

Code: Select all

Exception calling "LoadFileContentBinary" with "2" argument(s): "Connection to 'Veeam Backup Service' is not
available, host 'XXXXXXXXX', port '9392'"
At C:\scripts\veeampowershell\SO2W_Test2.ps1:32 char:1
+ $content = $sourceaccessor.FileCommander.LoadFileContentBinary($fulls ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CAppException

You cannot call a method on a null-valued expression.
At C:\scripts\veeampowershell\SO2W_Test2.ps1:38 char:1
+ $targetAccessor.FileCommander.SaveFileContentBinary('\\DPMHM1\c$\test ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull 
Do you know if there's any kind of timeout in these processes, and how I might overcome that?
Thanks again
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov » 2 people like this post

Hi Ian,

Unfortunately, I can't see any settings, which would configure timeout for such cases. I can't see what is a timeout either.
What I see is that new() method inside [Veeam.Backup.Core.CHostAccessor] class accepts useReconnects bool as an argument. So, once you pass it as $true, it should reconnect to the source host if connection is lost. However, Create() method for [Veeam.Backup.Core.CRepositoryAccessorFactory] acts differently and has no such argument.
During further tests I noticed that LoadFilesContentBinary() method loads backup file contents to the VBR host RAM memory. To be precise, to the memory allocated for Veeam.Backup.Satellite process. Thus, you are running risk of getting OutOfMemory exception if size of a single file being loaded > free RAM on VBR host that can be allocated. I checked if offset for the method can be specified so that data could be loaded and passed to SaveFileContentBinary() method in chunks lest to overload RAM, but didn't find any. As it turns out eventually, my workaround can easily win Golden Raspberry Awards.

Best regards,
Oleg
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 »

Hi Oleg,
Yes, I think file size is a problem. A 4MB .vbm file loads into $content in 4 seconds on our VBR server, and a 22MB .vib file loads in 16 seconds. But a 3GB .vib that by extrapolation should take <1 hour has been trying to load for nearly 2 hours, and a 20GB .vbk has been trying for >2 days. I suspected it had run out of resource somewhere. Never mind, it seemed a good idea, and I've learned a bit more Powershell. Perhaps the chunking idea can be added as a future feature.
It's interesting that the GUI method can do the job manually and much faster - a 39GB .vbk transferred in 9 minutes, at >70MB/sec. But I guess the GUI uses its own coding, not Powershell methods. So I'll have to find another solution to copying our backups into hidden storage.
Thanks for trying to help, anyway.
Kind regards,
Ian
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by oleg.feoktistov » 3 people like this post

Yes, I see that the methods for UI implemented differently. Nonetheless, your case gave me a pretty good idea on how official cmdlets for browsing/copying/deleting files from different entities can be designed. I'll mark it as a feature request to discuss further internally.
Cheers, Oleg
ianbutton1
Enthusiast
Posts: 58
Liked: 18 times
Joined: Oct 14, 2016 3:54 pm
Full Name: Ian Button
Contact:

Re: Automated File Copy from StoreOnce Catalyst to Windows?

Post by ianbutton1 » 1 person likes this post

Yes Oleg - that's a great idea! I look forward to some new cmdlets in due course.
Большое спасибо!!
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests