Question

nas backup recovery file via powershell script


Userlevel 1

Hello everyone
I am trying to restore files in a specific path from the current backup restore point.
The number of files to be restored is large and scattered, so it is done using a powershell script.
The backup image is that of the NAS server.
The command used is Save-VBRNASBackupFLRItem.
However, when recovering through the command below, if the type is a folder, only the entire folder is restored.
However, I want to select and recover only some files, not all files in the folder.
What should I do?

## Powershell script (test environment)
$nfs_source = Get-VBRNASServer | Where-Object {$_.path -eq "nas:/nfs"}
$nfs_restore = Get-VBRNASServer | Where-Object {$_.path -eq "nas:/restore"}
$path_restore = Get-VBRNASServerPath -Server $nfs_restore
$restorepoint_nfs=Get-VBRNASBackupRestorePoint | Where-Object {$_.NASServerName -eq "nas:/nfs" -and $_.CreationTime.tostring() -eq "5/25/2023 11:47:43 AM"}
$restore_session_nfs = Start-VBRNASBackupFLRSession -RestorePoint $restorepoint_nfs

$list_files = Get-VBRNASBackupFLRItem -Session $restore_session_nfs
Save-VBRNASBackupFLRItem -Item $list_files[0] -Server $nfs_restore -Path $($path_restore+"/test") -PreservePermissions:$true
Stop-VBRNASBackupFLRSession -Sessio $restore_session_nfs

 

$list_files is as below
PS C:\test> $list_files


Type : Folder
CreationDate: 2023-05-25 10:19:22 AM
Path : file1
Name: file1

Parent:
ModificationDate : 2023-05-25 10:19:22 AM
VersionId : 4

Size : 450733505
Type : File
CreationDate: 2/28/2023 11:45:06 AM
Path : bandicam 2023-02-28 09-32-01-032.mp4
Name : bandicam 2023-02-28 09-32-01-032.mp4
Parent:
ModificationDate: 2/28/2023 11:45:06 AM
VersionId : 4

Size : 457012698
Type : File
CreationDate: 2023-02-28 4:38:07 PM
Path : bandicam 2023-02-28 14-14-16-827.mp4
Name : bandicam 2023-02-28 14-14-16-827.mp4
Parent:
ModificationDate : 2023-02-28 4:38:07 PM
VersionId : 4

Size : 457012698
Type : File
CreationDate: 2023-02-28 4:38:07 PM
Path : copy1-1.mp4
Name : copy1-1.mp4
Parent:
ModificationDate : 2023-02-28 4:38:07 PM
VersionId : 4

Size : 450733505
Type : File
CreationDate: 2/28/2023 11:45:06 AM
Path : copy2-2.mp4
Name : copy2-2.mp4
Parent:
ModificationDate: 2/28/2023 11:45:06 AM
VersionId : 4

Size : 5765996544
Type : File
CreationDate: 6/16/2017 6:05:32 PM
Path : SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_Korean_-2_MLF_X21-22833.ISO
Name : SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_Korean_-2_MLF_X21-22833.ISO
Parent:
ModificationDate : 2017-06-16 6:05:32 PM
VersionId : 4

 

Below is the file list of the test nas server. 

(top is nas:/nfs , bottom is nas:/nfs/file1)

 

Thanks for reading.


6 comments

Userlevel 7
Badge +15

Hi @jhlee ...I’m wondering if this is more of a PoSH misconfiguration than a Veeam Script Module feature lack. What I mean by this is getting files within a folder path can be tricky due to some ‘quirks’ in how it needs to be done. Though I’ve used PoSH quite a bit and feel comfortable scripting, I wouldn’t call myself an expert by any means. This being said, I have played with retrieving files & folders a bit using the Get-ChildItem cmdlet and notice some requirements from Microsoft as noted here. If you look down the page just a bit, there is a character requirement to retrieve just the files within a Folder path, and not just the whole Folder. You must use a * at the end of your Path to retrieve all the files within a Folder (i.e. C:\Path\* and not C:\Path). Can you try adding the asterisk at the end of your Path variable and see if doing so helps?

Userlevel 7
Badge +7

I agree with @coolsport00 

You will need to use a * after the folder name otherwise PowerShell will be trying trying to explicitly reference just the folder and not the level below. 

Userlevel 1

Thank for reply. I will try it and add comment

Userlevel 7
Badge +15

Great...keep us posted on how it goes. 

Userlevel 1

Hi. everyone

The intent of my question was to find a way to separate individual files from a backup image.
I didn't know the -recurse option of the get-vbrnasbackupflritem command at first, so I asked a question to find it.


However, I soon realized that there was a problem.
Note that this command does not display all sub-items if the number of backed up files is large.

So, after moving to the last directory where the file exists through a loop statement as shown below, the file to be restored was found.

If there is a better way, please comment.
I also share how I did it.

thank you

=====================================================

$file_matched = $null
$loop_count=0
$loop_child_path=$null
$loop_child_folder=$null
$loop_parent_folder=$null

$folder_slcms=Get-VBRNASBackupFLRItem -Session $restore_session_nfs | Where-Object {$_.Name -eq "slcms"}
$folder_slcms_datastore=Get-VBRNASBackupFLRItem -Session $restore_session_nfs -Folder $folder_slcms | Where-Object {$_.Name -eq "slcms|datastore"}
 

##inserted data's fullpath is "/linux/slcms/datastore/mid-path/filename" pattern
##veeam filepath is "slcms|datastore|mid-path|filename" pattern
##so , i need to change pattern to veeam's

$file_fullpath=$file.fullpath    
$file_fullpath_veeam=$file.fullpath.Replace('/linux/','').Replace('/','|')    
$file_path=$file_fullpath.Replace($file_fullpath.Split('/')[-1],'')
    
$loop_count=$file_fullpath_veeam.Split('|').count
$loop_parent_folder=$folder_slcms_datastore

 

## $i=2 at staring /linux/slcms/datastore, $i < splict(|) word's count (== at stoping last directory)
for($i=2;$i -lt $loop_count;$i++){
    
    if ($i -ne $loop_count-1) {
        ## if not last directory , loop to next directory
        $loop_child_path=$file_fullpath_veeam.Replace("|"+$file_fullpath_veeam.Split('|',$i+2)[-1],'')
        $loop_child_folder=Get-VBRNASBackupFLRItem -Session $restore_session_nfs -Folder $loop_parent_folder | Where-Object {$_.Name -eq $loop_child_path}
    
        $loop_parent_folder=$loop_child_folder
    } else {
        ## if last directory, record target file's object in $file_matched    
        $file_matched=Get-VBRNASBackupFLRItem -Session $restore_session_nfs -Folder $loop_parent_folder | Where-Object {$_.Name -eq $file_fullpath_veeam}
    }
}


if ($null -ne $file_matched ) {
    Write-Output "[$((Get-Date -F o).split('.')[0].replace('-',''))] $file_fullpath is exist." >> $logfile
    
    Save-VBRNASBackupFLRItem -Item $file_matched -Server $nfs_restore -Path $($path_restore+$nfs_target_subdir+$file_path) -PreservePermissions:$true 
}

 

Userlevel 7
Badge +15

Honestly @jhlee ...if you found a way in your script which does what you need it to, then I think you’re good.

Comment