Start-VBRWindowsFileRestore

PowerShell script exchange

Start-VBRWindowsFileRestore

Veeam Logoby jozne » Tue Dec 16, 2014 4:28 pm

I updated veeam to v8 and the example in http://helpcenter.veeam.com/backup/80/p ... files.html does not seem to work anymore. I have not run the jobs with the new v8 version yet.

$result seems to be missing MountSession and I can not retrieve the FLR mountpoint.
Code: Select all
PS C:\scripts> $result | gm


   TypeName: Veeam.Backup.PowerShell.Model.FileRestore

Name         MemberType Definition
----         ---------- ----------
Dispose      Method     System.Void Dispose()
Equals       Method     bool Equals(System.Object obj)
GetHashCode  Method     int GetHashCode()
GetType      Method     type GetType()
ToString     Method     string ToString()
CreationTime Property   System.DateTime CreationTime {get;}
Drives       Property   System.String Drives {get;}
Id           Property   System.Guid Id {get;}
MountPoint   Property   System.String MountPoint {get;}
Oib          Property   Veeam.Backup.Core.COib Oib {get;}
Size         Property   System.String Size {get;}
VmName       Property   System.String VmName {get;}


PS C:\scripts> $result | Format-List
Id           : 164731f8-5dbc-47a1-b1b4-f155066243c8
MountPoint   : C
Drives       : C:\VeeamFLR\dc1\Volume0, C:\VeeamFLR\dc1\Volume1, C:\VeeamFLR\dc
               1\Volume2
VmName       : dc1
Size         : 1,2 TB
CreationTime : 16.12.2014 1:32:27
Oib          : Veeam.Backup.Core.COib
jozne
Novice
 
Posts: 8
Liked: 1 time
Joined: Wed Apr 18, 2012 6:55 pm
Full Name: Jari Haikonen

Re: Start-VBRWindowsFileRestore

Veeam Logoby v.Eremin » Wed Dec 17, 2014 12:27 pm

How many disks does the said VM have? And from which one you're trying to restore? In case of source disk being C:, the following script might allow you to achieve what you're after:

Code: Select all
asnp VeeamPSSnapin
$result = Get-VBRBackup | where {$_.jobname -eq "Name of your Job"} | Get-VBRRestorePoint | where {$_.name -eq "Name of your VM"} | Sort-Object creationtime -Descending | Select-Object -First 1 | Start-VBRWindowsFileRestore
$Files = "File or folder to restore"
$RestoreDestination = "Folder to which file or folder should be restored"
$File = $Result.Drives.Substring($Result.Drives.LastIndexOf(" ")).substring(1) + (split-path -NoQualifier $Files)
Copy $File $RestoreDestination -Force -Recurse
Stop-VBRWindowsFileRestore $Result


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

Re: Start-VBRWindowsFileRestore

Veeam Logoby jozne » Wed Dec 17, 2014 12:39 pm

I'll be using the script for number of VMs with different number of disks and I cannot be sure which Volume1-X is the correct one
for example E-Drive -> hence I tried finding the correct FLR mountpoint by using the provided example in documentation.

But since it does not provide MountSession property I could not. Your example would work if the number of disks etc. would
remain the same.
jozne
Novice
 
Posts: 8
Liked: 1 time
Joined: Wed Apr 18, 2012 6:55 pm
Full Name: Jari Haikonen

Re: Start-VBRWindowsFileRestore

Veeam Logoby jozne » Wed Dec 17, 2014 12:46 pm

I think I'll quickly "bypass" this problem by using test-path for all the volumeX FLR paths...
jozne
Novice
 
Posts: 8
Liked: 1 time
Joined: Wed Apr 18, 2012 6:55 pm
Full Name: Jari Haikonen

Re: Start-VBRWindowsFileRestore

Veeam Logoby v.Eremin » Wed Dec 17, 2014 12:53 pm

Using Test-Path method in order to get an appropriate drive might do the trick. As to missing MountSession parameter, we're currently investigating this situation (whether the parameter can be brought back).Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 969 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Start-VBRWindowsFileRestore

Veeam Logoby jozne » Wed Dec 17, 2014 1:02 pm 1 person likes this post

For reference, changes my apply (depending your settings)


Code: Select all
asnp -Name VeeamPSSnapin -ErrorAction SilentlyContinue
$computer = "computer"
$origfile = "folder"
$restoreto = "restoreto"
$result = Get-VBRBackup | where {$_.jobname -eq "$computer"} | Get-VBRRestorePoint | where {$_.name -eq "$computer"} | Sort-Object creationtime -Descending | Select-Object -First 1 |Start-VBRWindowsFileRestore

$folders = gci "c:\veeamflr\$computer" | select-object FullName
foreach($folder in $folders){
if(Test-Path ($folder.fullname +(Split-Path -NoQualifier $origfile))) {
$file = ($folder.fullname +(Split-Path -NoQualifier $origfile))
Copy-Item $file $restoreto -recurse
}
}
Stop-VBRWindowsFileRestore $result
jozne
Novice
 
Posts: 8
Liked: 1 time
Joined: Wed Apr 18, 2012 6:55 pm
Full Name: Jari Haikonen

[MERGED] : Get-VBRRestorePoint in Version 8, patch 1

Veeam Logoby AdrianHinton » Mon Jan 19, 2015 5:04 am

Hi,

Has anything changed with what is returned in Get-VBRRestorePoint since V8? I have the following script that gets all my copy jobs and does an FLR on the most recent log file in C:\Windows\Logs in the backup but it isnt working anymore:

Code: Select all
$Backups = $Null

$Backups = Get-VBRBackup | ?{$_.IsBackupSync -eq $true -and $_.Name -ne 'Normal-ServerName - Copy'}

Foreach($Backup in $Backups){

try{


$LogString = $Null
$WFLR = $null

$WFLR = Get-VBRBackup -Name $Backup.name | Get-VBRRestorePoint  |
Sort CreationTime -Descending | Select -First 1 | Start-VBRWindowsFileRestore

$WFLR.MountSession.MountedDevices.mountpoint[0] | % {

   
    LogWrite "Started Veeam File Level Restore on $($Backup.name)"

    $File = GCI C:\Windows\Logs -Recurse |
    Sort LastwriteTime |
    Select -Last 1 |
    ? {$_.PsIsContainor -ne $true}
   
    LogWrite "Found $($File.FullName)"

    if((Test-Path "C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\") -eq $false){

        New-Item "C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\" -ItemType Directory

        Logwrite "Created directory C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\ "

    }
     
    Copy-Item $File.FullName -Destination "C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\"
   
    if(Test-Path "C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\$($File.Name)"){

        LogWrite "Successfully copied $($File.Name) to C:\VeeamRestores\$($Backup.Name)\$(Get-Date -Format 'yyyyMMdd')_Restore\"

        }
   
    }

Stop-VBRWindowsFileRestore $WFLR

}

Catch [system.exception]{

    Logwrite " ERROR: $($Error[0].exception.message) against $($Backup.name) "

  }
}


This line here is not returning anything where previously it did:

Code: Select all
$WFLR.MountSession.MountedDevices.mountpoint[0]


And I have checked the members of the $WFLR variable and there is no such member named Mountsession. But this was working before the upgrade to V8.
AdrianHinton
Enthusiast
 
Posts: 71
Liked: 5 times
Joined: Mon Apr 07, 2014 10:00 am
Full Name: Adrian Hinton

Re: Start-VBRWindowsFileRestore

Veeam Logoby v.Eremin » Mon Jan 19, 2015 9:39 am

The internal structure of the said object has changed, indeed. You might want to apply the described changes to make the script work. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 969 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Start-VBRWindowsFileRestore

Veeam Logoby Tim783 » Wed Jan 21, 2015 4:22 pm

v.Eremin wrote:How many disks does the said VM have? And from which one you're trying to restore? In case of source disk being C:, the following script might allow you to achieve what you're after:

Code: Select all
asnp VeeamPSSnapin
$result = Get-VBRBackup | where {$_.jobname -eq "Name of your Job"} | Get-VBRRestorePoint | where {$_.name -eq "Name of your VM"} | Sort-Object creationtime -Descending | Select-Object -First 1 | Start-VBRWindowsFileRestore
$Files = "File or folder to restore"
$RestoreDestination = "Folder to which file or folder should be restored"
$File = $Result.Drives.Substring($Result.Drives.LastIndexOf(" ")).substring(1) + (split-path -NoQualifier $Files)
Copy $File $RestoreDestination -Force -Recurse
Stop-VBRWindowsFileRestore $Result


Thanks.


Hi Eremin,

I have been trying to get your script working but am having a few problems I am hoping you might be able to help me with.

For some reason the volume mapping is not working. The script always looks in Volume6 (in the Veeam FLR folder) when the file is not actually on this volume. Because of this the script fails

Code: Select all
Copy : Cannot find path 'C:\VeeamFLR\VMNAME\Volume6\MSSQL\DATA\OnlinePayments.mdf' because it does not exist.
At line:1 char:1
+ Copy $File $RestoreDestination -Force -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\VeeamFLR\INV...inePayments.mdf:String) [Copy-Item], ItemNotFoundExce
   ption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand


Any ideas why this is happening?

Thanks
Tim783
Influencer
 
Posts: 11
Liked: never
Joined: Fri Jul 20, 2012 2:05 pm

Re: Start-VBRWindowsFileRestore

Veeam Logoby AdrianHinton » Wed Jan 21, 2015 11:44 pm

More breakage. Is there a page which shows all the changes to Powershell cmdlets, methods and outputs?

Code: Select all
Function Import-SingleBackup{

param(
    [Parameter(Mandatory=$True,Position=1)]
    [String]$ServerName
)


Add-PSSnapin VeeamPSSnapin

$VBRServer = Get-VBRServer | where {$_.Type -eq "Local"}
$DirectoryVBMs = Get-ChildItem "D:\Backups\*.vbm" -Recurse | %{$_.FullName}
$SelectedBackup = $DirectoryVBMs | ?{$_ -like "*$($ServerName)*"}


Import-vbrbackup -server $VBRServer -FileName $SelectedBackup
}

Function Import-AllBackups{

Add-PSSnapin VeeamPSSnapin

$VBRServer = Get-VBRServer | where {$_.Type -eq "Local"}
$DirectoryVBMs = Get-ChildItem "D:\Backups\*.vbm" -Recurse | %{$_.FullName}

foreach($VBM in $DirectoryVBMs){
   
    Import-vbrbackup -server $VBRServer -FileName $VBM
    }
   
}
AdrianHinton
Enthusiast
 
Posts: 71
Liked: 5 times
Joined: Mon Apr 07, 2014 10:00 am
Full Name: Adrian Hinton

Re: Start-VBRWindowsFileRestore

Veeam Logoby v.Eremin » Thu Jan 22, 2015 11:49 am

Hey, Tim,

Have you tried to use the updated script provided by Jari?

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

Re: Start-VBRWindowsFileRestore

Veeam Logoby Tim783 » Thu Jan 22, 2015 1:30 pm

Hi Eremin,

Just tried Jari's script,but get the following error

Code: Select all
gci : Cannot find path 'C:\veeamflr\INVGSYVMSQLPR01' because it does not exist.
At C:\Users\thardwickadm\Desktop\test.ps1:7 char:12
+ $folders = gci "c:\veeamflr\$computer" | select-object FullName
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\veeamflr\INVGSYVMSQLPR01:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Stop-VBRWindowsFileRestore : Cannot validate argument on parameter 'FileRestore'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Users\thardwickadm\Desktop\test.ps1:14 char:28
+ Stop-VBRWindowsFileRestore $result
+                            ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Stop-VBRWindowsFileRestore], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.StopVBRWindowsFileRestore


Am I doing something wrong?
Thanks
Tim783
Influencer
 
Posts: 11
Liked: never
Joined: Fri Jul 20, 2012 2:05 pm

Re: Start-VBRWindowsFileRestore

Veeam Logoby AdrianHinton » Tue Feb 17, 2015 12:11 am

Hi,

Any answers? A page with all the changes after V8 so us scripters can easily fix all the problems V8 has introduced?

AdrianHinton wrote:More breakage. Is there a page which shows all the changes to Powershell cmdlets, methods and outputs?

Code: Select all
Function Import-SingleBackup{

param(
    [Parameter(Mandatory=$True,Position=1)]
    [String]$ServerName
)


Add-PSSnapin VeeamPSSnapin

$VBRServer = Get-VBRServer | where {$_.Type -eq "Local"}
$DirectoryVBMs = Get-ChildItem "D:\Backups\*.vbm" -Recurse | %{$_.FullName}
$SelectedBackup = $DirectoryVBMs | ?{$_ -like "*$($ServerName)*"}


Import-vbrbackup -server $VBRServer -FileName $SelectedBackup
}

Function Import-AllBackups{

Add-PSSnapin VeeamPSSnapin

$VBRServer = Get-VBRServer | where {$_.Type -eq "Local"}
$DirectoryVBMs = Get-ChildItem "D:\Backups\*.vbm" -Recurse | %{$_.FullName}

foreach($VBM in $DirectoryVBMs){
   
    Import-vbrbackup -server $VBRServer -FileName $VBM
    }
   
}
AdrianHinton
Enthusiast
 
Posts: 71
Liked: 5 times
Joined: Mon Apr 07, 2014 10:00 am
Full Name: Adrian Hinton

Re: Start-VBRWindowsFileRestore

Veeam Logoby v.Eremin » Tue Feb 17, 2015 11:13 am

Chances are, the mountsession parameter will be added back in patch 2 or a bit later.

As to listing all of changes introduced, you can refer to the corresponding section of help center for more information about new commandlets. The problem is that some custom scripts utilize internal methods or properties that are being modified on regular basis (product patch, release, etc.), and it's almost impossible to track those.

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

Re: Start-VBRWindowsFileRestore

Veeam Logoby AdrianHinton » Mon Feb 23, 2015 3:53 am

v.Eremin wrote:Chances are, the mountsession parameter will be added back in patch 2 or a bit later.

As to listing all of changes introduced, you can refer to the corresponding section of help center for more information about new commandlets. The problem is that some custom scripts utilize internal methods or properties that are being modified on regular basis (product patch, release, etc.), and it's almost impossible to track those.

Thanks.


Some notice would be nice. Considering Veeam was touted as being the backup solution that we could automate with powershell, I find it distressing at the very least that Veeam will go ahead and change powershell cmdlets, members or methods without first showing a front and centre stage *WARNING* about the changes.

I had a working script that would mount each backup of a windows server, search that backup for the latest log file and copy that log file out to a dir before unmounting and moving off to the next one. This satisfied the business that backups are OK each month. The business requires this and now I can't seem to use the code you have provided to do the same thing. Just as I figured it out, Veeam go and remove it. Why? I don't get it. IT JUST WORKS!
AdrianHinton
Enthusiast
 
Posts: 71
Liked: 5 times
Joined: Mon Apr 07, 2014 10:00 am
Full Name: Adrian Hinton

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 7 guests