PowerShell script exchange
Post Reply
bertdhont
Service Provider
Posts: 45
Liked: 5 times
Joined: Nov 08, 2013 2:53 pm
Full Name: Bert D'hont
Contact:

Set-VBRFileToTapeJob

Post by bertdhont »

I've used the comand 'Set-VBRFileToTapeJob' to change a file-to-tape job, so only the file I want is written to tape.

Code: Select all

$LastFile = $backup.getstorages() | sort CreationTime -descending | Select -First 1
$TapeJob = Get-VBRTapeJob -Name $FullBackupJobName
$FileList = New-VBRFileToTapeObject -Path $LastFile.FilePath
Set-VBRFileToTapeJob -Job $TapeJob -Object $FileList
This works fine, but how can I use this to add multiple files to the file-to-tape job.
When I check the powershell guide, it tells me it is possibe, but I don't know how...

Object:
Specifies the source file system object.
Accepts VBRFileToTapeObject object.
You can assign multiple files to this object.

Kind Regards
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRFileToTapeJob

Post by veremin »

It's just a matter of working with an array, try the following example:

Code: Select all

$Job = Get-VBRTapeJob -name "Name of your file to tape job"
$File1 = New-VBRFileToTapeObject -Path "First path"
$File2 = New-VBRFileToTapeObject -Path "Second path"
$Object = @($File1, $File2)
Set-VBRFileToTapeJob -Job $Job -Object $Object
Thanks.
winnt
Enthusiast
Posts: 29
Liked: 20 times
Joined: Apr 03, 2015 9:19 pm
Full Name: Jason D
Contact:

Re: Set-VBRFileToTapeJob

Post by winnt »

How do we specify the remote server name that has the drive attached? When I use the above example, it assumes it is the local Veeam server and can't find the path. I try to specify the server name, and I get errors. When I view the object details, the server name is listed as "Veeam.Backup.Core.Common.CHost" not matter which server is specified in the GUI. Thank you.
winnt
Enthusiast
Posts: 29
Liked: 20 times
Joined: Apr 03, 2015 9:19 pm
Full Name: Jason D
Contact:

Re: Set-VBRFileToTapeJob

Post by winnt »

I figured it out. I had to add these lines:

Code: Select all

$File1Server = get-vbrserver -name "BACKUP03"
$File1 = New-VBRFileToTapeObject -Path "Q:\SQL" -IncludeMask "*.bak" -Server $File1Server
$File2 = New-VBRFileToTapeObject -Path "C:\Scripts" -IncludeMask "*.txt"
$Object = @($File1, $File2)
Thanks for the code to get me started.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRFileToTapeJob

Post by veremin »

Yep, as mentioned in our Help Center, -Server parameter can be used to specify the source server where files to backup are located. Glad to hear you were able to find it yourself.
enziankunz
Novice
Posts: 5
Liked: never
Joined: Sep 01, 2021 2:25 pm
Contact:

Re: Set-VBRFileToTapeJob

Post by enziankunz »

Hi guys,
really stuck and need some advice. Tried to modify file tot tape job by powershell:

Code: Select all

#add latest vbk files from backup path to array with VBRFileToTapeObjects
$vbkfiles = get-childitem $b2dpath -filter "*.vbk" -rec | Where-Object {$_.FullName -notlike '*\_*' -and $_.FullName -notlike '*\@*'}
$filteredvbkfiles = $vbkfiles | group directory | foreach {@($_.group | sort {[datetime]$_.creationtime} -desc)[0]}
Foreach($file in $filteredvbkfiles){
    #out-host -InputObject $file.FullName
    #out-host -InputObject $file.Name
    $str = $file.DirectoryName.TrimStart($b2dpath)
    #write-host "Server: " $b2dnas.Name "Pfad: " $str " File: " $file.Name "Directory: " $file.DirectoryName " und " $file.Directory
    $obj = New-VBRFileToTapeObject -Server $b2dnas -Path $file.PSParentPath -IncludeMask $file.Name
    echo $obj $file.PSParentPath $file.PSPath
    $b2tobj += $obj
}

# add all objects to the b2t job
Set-VBRFiletoTapeJob -job $b2tjob -Object $b2tobj
Unfortunately the New-VBRFileToTapeObject doesn't acceppt the UNC PAth as "path parameter and also not - like suggested in the last post - within the Server parameter.
Any ideas?
thx in advance
Regards
Enzian
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Set-VBRFileToTapeJob

Post by oleg.feoktistov »

Hi Enzian,

What happens if you try to create a new file to tape object like that? Do you see any error? I just tested it and it worked flawlessly.
The workflow is to pass server added to VBR as a managed one along with the path within to New-VBRFileToTapeObject cmdlet.
Is it the algorithm you are following?

Thanks,
Oleg
enziankunz
Novice
Posts: 5
Liked: never
Joined: Sep 01, 2021 2:25 pm
Contact:

Re: Set-VBRFileToTapeJob

Post by enziankunz »

Hi Oleg,
sry for late response - seem to have issues with my account, no hints on your activity - anyway.
In many contributions, the use of UNC paths was assessed as not possible.
So I tried to connect an smb share, create hardlinks to the vbk files to be backed up and then transfer them as objects - again without success.
I can detect the files but can't get them into the required array (see code mess below :-o)
Actually Error message:
Set-VBRFileToTapeJob : Der Parameter "Object" kann nicht gebunden werden. Der Wert "z:\PYNBG3A-107-01 DoB\PYNBG3A-107-01 DoB2021-09-18T054511.vbk," vom Typ "System.String" kann nicht in den Typ
"Veeam.Backup.PowerShell.Infos.VBRFileToTapeObject" konvertiert werden.
In D:\Batchfile\B2TCopyJobVeeamAgentFullBackupsV2.ps1:43 Zeichen:43
+ Set-VBRFileToTapeJob -Job $b2tjob -Object $b2tobj
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-VBRFileToTapeJob], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.SetVBRFileToTapeJob

Code: Select all

# add all vbk files from backup path where timestamp is not older then n hours (168 hours => one week) to array with VBRFileToTapeObjects
#Get-ChildItem $b2dpath -recurse -filter *.vbk | Where {$_.LastWriteTime -gt (Get-Date).AddHours(-168)} | group path
$vbkfiles = get-childitem $tempdrive -recurse -filter *.vbk | Where {$_.LastWriteTime -gt (Get-Date).AddHours(-168)} #Where-Object {$_.FullName -notlike '*\_*' -and $_.FullName -notlike '*\@*'}
$filteredvbkfiles = $vbkfiles | group directory | foreach {@($_.group | sort {[datetime]$_.creationtime} -desc)[0]}

Foreach($file in $filteredvbkfiles){
	#Generate all harlinks in temporary drive mapped to smb share
    $fileName = $file.Name
	$b2tobj += $file.FullName+','
    #$hlitem = $tempdrive+"\"+$file.Name
	#New-Item -ItemType HardLink -Path $hlitem -Target $file.FullName
    #Write-Host "HLitem: $hlitem File: "$file.FullName

}
# generate new FileToTapeObject within all selected hardlinks to vbk files
#dir z:*.vbk
#$obj = New-VBRFileToTapeObject -NASServer $b2dnas -IncludeMask "*.vbk" -Path $tempdrive
#Add-VBRTapeFilesJob -Name $b2tjob -Server $b2dnas -Path $tempdrive -Masks '*.vbk'
#$b2tobj = New-VBRFileToTapeObject -Server $b2dnas -IncludeMask "*.vbk" -Path $tempdrive
Write-Host $b2tobj
Set-VBRFileToTapeJob -Job $b2tjob -Object $b2tobj

# debug output
#Write-Host "Anzahl Objekte zum Backup: " $b2tobj.count

# delete all hardlinks and remove drive mapping
del $tempdrive*.vbk
Remove-SmbMapping z: -force
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Set-VBRFileToTapeJob

Post by oleg.feoktistov »

Hi,

Sorry for my late reply. From what I see in your error message, you pass a string path directly to Set-VBRFileToTapeJob cmdlet instead of composing a new file to tape object first and then adding it to a tape job. The workflow is as simple as that:

Code: Select all

$job = Get-VBRTapeJob -Name 'File to Tape Job'
$jobObjects = $job.Object
$server = Get-VBRServer -Name 'ServerName' | where {$_.Type -eq 'Windows'} # You need your smb share added as a managed server at this point.
$object = New-VBRFileToTapeObject -Server $server -Path 'C:\Users\Administrator\Documents'
$jobObject += $object
Set-VBRFileToTapeJob -Job $job -Object $jobObject

I do see that you pass the correct variable to Set-VBRFileToTapeJob, however, the error message you refer to says otherwise.
Please see my code example above, re-check the workflow in your script and make sure variables are on their places.

Thanks,
Oleg
enziankunz
Novice
Posts: 5
Liked: never
Joined: Sep 01, 2021 2:25 pm
Contact:

Re: Set-VBRFileToTapeJob

Post by enziankunz »

Hi Oleg,
apparently the notification of your post slipped through my fingers - sry. Thanks to your input it's working!

Code: Select all

$job = Get-VBRTapeJob -Name 'B2T Copy Job'
$jobObjects = $job.Object
$server = Get-VBRServer -Name '\\mynas.mydomain.local\B2DShare' | where {$_.Type -eq 'Windows'} # You need your smb share added as a managed server at this point.
$object = New-VBRFileToTapeObject -Server $server -Path 'C:\Users\administrator\test.pdf'
$jobObject += $object
Set-VBRFileToTapeJob -Job $job -Object $jobObject
Thx for your help
Regards
Enzian
enziankunz
Novice
Posts: 5
Liked: never
Joined: Sep 01, 2021 2:25 pm
Contact:

Re: Set-VBRFileToTapeJob

Post by enziankunz »

Hello Oleg,
Unfortunately, I was a bit hasty - it just doesn't work. Apparently, Veeam has made sure that no files can be added to a "New-VBRFileToTapeObject" via UNC path or via "New-SMBMapping" generated network drive. I have now tried all possible combinations and can add available local files on the backup server but no files on the network.
If you have any ideas, I really would appreciate.
Regards
Etienne
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Set-VBRFileToTapeJob

Post by oleg.feoktistov »

Hi,

Now I think I have the full picture in my head.
Let me clarify a bit. In New-VBRFileToTapeObject we have 2 entry points - for servers added as managed ones (-Server parameter) and servers added as file shares (-NASServer parameter). For those added as managed servers we can also choose the underlying path with -Path parameter. Now, as you know, we can get managed servers with Get-VBRServer cmdlet. However, file shares are also reflected in the output in this case. But -Path parameter works only for those servers added as managed ones by their IP or DNS. For those added or reflected by UNC path currently there is no way to specify the underlying path. We know this limitation for NAS shares and have plans to mirror this behavior to Powershell. Especially, when it does actually work in the UI.
So, the workaround here is to add the server hosting your share by its IP or DNS and then construct a FileToTapeObject with the underlying path of your choice:

Code: Select all

$creds  = Get-VBRCredentials -Name 'Admin'
$server = Add-VBRWinServer -Name 'Server DNS or IP' -Credentials $creds
$objectSpec = New-VBRFileToTapeObject -Server $server -Path 'C:\Backup'
The example above is for Windows. If it is a Linux server hosting file share, add it with Add-VBRLinux.

Hope it helps,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests