Start-VBRWindowsFileRestore and getting a folder path

PowerShell script exchange

Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby ShawnKPERS » Wed Oct 23, 2013 6:56 pm

I am looking to automating a restore of a copy of our production database on our production SQL server to our test SQL server on a weekly basis. I found a script example on the forms that does a file level restore but it doesn't seem to be quite complete or maybe just not correct in the syntax. Here is my example of it:

Code: Select all
$result = Get-VBRBackup | where {$_.JobName -eq "Backup Job 1"} | Get-VBRRestorePoint | sort CreationTime -Descending | select -First 1 | Start-VBRWindowsFileRestore
$file = $result.FirstDrive + “:\readme.txt”
Copy $file c:\
Stop-VBRWindowsFileRestore $result


The script seemed to work for the most part but where there is an issue for me was at the "$result.FirstDrive" variable. I didn't see how the ".FirstDrive" is supposed to work. I don't even see a ".FirstDrive" property but I do see a ".Drives" property but if you do a "$result.drives" you get a string that looks like this:

C:\VeeamFLR\DBServer\Volume0, C:\VeeamFLR\DBServer\Volume1, C:\VeeamFLR\DBServer\Volume2, C:\VeeamFLR\DBServer\Volume3

Now am I supposed to know how pull out a specific value in a CSV string or is there a simpler way to do it? Currently I get around all of it by just putting "C:\VeeamFLR\DBServer\Volume3\readme.txt" but I was hoping to use the variable as it will have the true value incase it creates a DBServer(2) folder instead of the expected DBServer folder when it mounts the recovered folder structure.

Any help would be appreciated.
ShawnKPERS
Enthusiast
 
Posts: 49
Liked: 4 times
Joined: Fri Apr 29, 2011 3:55 pm
Full Name: Shawn Nix

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby tsightler » Wed Oct 23, 2013 10:01 pm

Indeed I believe that the "FirstDrive" property is no longer available, however, you should be able to leverage some of the other properties to determine which file you want to restore.

For example $result.MountSession.MountedDevices contains a nicely parsed output that includes drive letter mappings, something like this (edited to fit more easily on the screen):
Code: Select all
MountPoint                   DeviceNames         DriveLetter     Attributes
----------                   -----------         -----------     ----------
C:\VeeamFLR\proxy01\Volume0  {Volume{09215e33}}                      Normal
C:\VeeamFLR\proxy01\Volume1  {C:, Volume{092e... C:                  Normal
C:\VeeamFLR\proxy01\Volume2  {E:}                E:            Deduplicated


This allows you to fairly easily determine which of the mounted volumes corresponded to what drive letter on the original VM. Here's some code that uses this method:
Code: Select all
$jobname ="<Job_Name>"  # Name of Job that contains VM to restore
$vmname = "<VM_Name>" # Name of VM that contains file sto restore
$origfile = "<full_path_to_file_on_original_VM>"  # Set this to full path such as E:\File\restore.txt

# Start the FLR process
$result = Get-VBRBackup -Name $jobname | Get-VBRRestorePoint -Name $vmname | sort CreationTime -Descending | select -First 1 | Start-VBRWindowsFileRestore

# Find the FLR mount point for the specific drive letter
$flrmountpoint = ($result.MountSession.MountedDevices | ? {$_.DriveLetter -eq (Split-Path -Qualifier $origfile)}).MountPoint

# Build the path to the file via the FLR mount point
$file = $flrmountpoint + (Split-Path -NoQualifier $origfile)

# Copy/Restore the file to root of C:\ drive
Copy $file c:\

# Stop the FLR process
Stop-VBRWindowsFileRestore $result
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby ShawnKPERS » Wed Oct 23, 2013 11:53 pm

Thanks tsightler,

That helped me get a little closer but I must be running an older version of Veeam as I am on build 6.5.00.144. Is that a v7 feature? I can run "$result.MountSession.MountPoints" and get this for the output:
Code: Select all
PS C:\VeeamFLR> $result.MountSession.MountPoints

C:\VeeamFLR\DBServer\Volume0
C:\VeeamFLR\DBServer\Volume1
C:\VeeamFLR\DBServer\Volume2
C:\VeeamFLR\DBServer\Volume3

But these are the options I have under "$result.MountSession":

Code: Select all
PS C:\VeeamFLR> $result.MountSession | gm


   TypeName: Veeam.Backup.Core.CViMountSession

Name           MemberType Definition                                         
----           ---------- ----------                                         
Dispose        Method     void Dispose(), void IDisposable.Dispose()         
Equals         Method     bool Equals(System.Object obj)                     
GetHashCode    Method     int GetHashCode()                                 
GetType        Method     type GetType()                                     
Start          Method     void Start(), void IMountSession.Start()           
ToString       Method     string ToString()                                 
FlrMountFolder Property   string FlrMountFolder {get;}                       
JobSession     Property   Veeam.Backup.Core.CRestoreSession JobSession {get;}
MountPoints    Property   string[] MountPoints {get;}

If this is a v7 feature then no big deal I can just wait as I am just about to start running it in test in the next few days and hope to have it in production by the end of the month. Currently if I run your script it just assumes drive c:\ regardless what drive I put down in the path under "$origfile".
ShawnKPERS
Enthusiast
 
Posts: 49
Liked: 4 times
Joined: Fri Apr 29, 2011 3:55 pm
Full Name: Shawn Nix

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby tsightler » Thu Oct 24, 2013 3:26 am

I'll admit I wrote this example code for V7, it's actually a mash of the script you previously posted and some code I helped another user to write. I don't currently have access to a 6.5 install to test so it might very well be that this only works with V7.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby v.Eremin » Thu Oct 24, 2013 11:39 am

I’ve conducted a simple test with 6.5 installation and it seems that neither “MountedDevices” nor “FirstDrive” parameter has been present previously.

Surprisingly enough, I do remember that “FirstDrive” existed in 6.5 version as I wrote several scripts using the said parameter and users also didn’t report any issue with it.

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

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby ShawnKPERS » Thu Oct 24, 2013 6:54 pm

Thanks I will give it a shot in v7 and see if I have better luck.
ShawnKPERS
Enthusiast
 
Posts: 49
Liked: 4 times
Joined: Fri Apr 29, 2011 3:55 pm
Full Name: Shawn Nix

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby v.Eremin » Fri Oct 25, 2013 7:54 am

Yep, Parameters/properties mentioned by Tom can be certainly found in Veeam version 7. So, it might be the best strategy, indeed. Should other help be needed, don’t hesitate to let us know.

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

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby alex.nunley » Wed Jan 22, 2014 9:08 pm

I know this is an old post I am replying on, just hoping for some insight as it's related.

Working on a PS script, cant get start-vbrwindowsfilerestore to work. This is a snippet.

Code: Select all
$job = "<job name>"
$vm = "<vm name>"


$gen = Get-VBRBackup -Name $job | get-vbrrestorepoint -name "$vm"
$gen.creationtimestring >> c:\creationtimestring.csv # This generates a list of dates , in a CSV file.
import-csv c:\creationtimestring.csv -header date | foreach-object{ #reads from the CSV and starts a loop
$dateofres=$_.date
write-host "Attempting to restore" $dateofres
$res = Get-VBRBackup -Name $job | get-vbrrestorepoint -name $vm | where {$_.CreationTime -eq $dateofres} 
Start-VBRWindowsFileRestoreFiles
}


I think the problem is in "selecting" which restore point to work with. In the sample, it does a sort and select, which I dont want to do. This is intended to go through the list generated, select each one and do a restore. There will be some other PS magic in there to do some file counting and whatnot, that parts no problem. I just can't get the restore to start. Am I missing something? I keep getting
Code: Select all
Start-VBRWindowsFileRestore : Exception has been thrown by the target of an invocation.
alex.nunley
Influencer
 
Posts: 19
Liked: never
Joined: Fri Jan 18, 2013 3:36 pm
Full Name: Alex Nunley

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby v.Eremin » Thu Jan 23, 2014 12:02 pm

Hi, Alex, in the snippet provided "Start-VBRWindowsFileRestore" seems to be separated from $res variable, while it should be connected by the means of "|". So, the correct version should:

Code: Select all
$res = Get-VBRBackup -Name $job | get-vbrrestorepoint -name $vm | where {$_.CreationTime -eq $dateofres}  | Start-VBRWindowsFileRestore

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

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby alex.nunley » Thu Jan 23, 2014 2:47 pm

So theres an obvious typo, should be Start-VBRWindowsFileRestore. Removed that, added the pipe, which I had tried before, no love.

Went and found thishttp://helpcenter.veeam.com/backup/70/powershell/start-vbrwindowsfilerestore.html, which I tried the default methodology, of just selecting the last restore point (very not helpful in this example, but whatever), and even that doesnt work.

Throws the same error :

Code: Select all
Start-VBRWindowsFileRestore : Exception has been thrown by the target of an invocation.
At line:16 char:127
+ ... ect -First 1 | Start-VBRWindowsFileRestore
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-VBRWindowsFileRestore], TargetInvocationException
    + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Veeam.Backup.PowerShell.Command.St
   artVBRWindowsFileRestore


Scratching my head here. Ideas?
alex.nunley
Influencer
 
Posts: 19
Liked: never
Joined: Fri Jan 18, 2013 3:36 pm
Full Name: Alex Nunley

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby nefes » Thu Jan 23, 2014 2:51 pm

Is there any chance that you've got empty list of restorepoints?
You can try to call commands one by one and see the results in between to find out the cause of problem.
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby v.Eremin » Thu Jan 23, 2014 3:15 pm

Have you tried to run the script as an Administrator? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby tsightler » Thu Jan 23, 2014 3:27 pm

Can you please confirm that there are no active FLR jobs currently running in the GUI. Reading your original code it looks like it would try to loop through and start many FLR sessions for the same VM (although with different points). That would fail as I'm pretty sure you can only have one FLR session for the same VM at the same time and I think I've seen that error when a session was already running.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby alex.nunley » Thu Jan 23, 2014 9:33 pm

thanks for all the quick replies. Working with another guy here, we got it working, well, most of it. Still having a problem with a non-veeam aspect of the function we're trying to create. To address one of the replies, yes, we are trying to restore multiple dates on the same VM. Once its up, we take a look at a specific directory, do some fun counting stuff, write that to a csv and then stop the restore. The loop is to go back and do it again with a different date. Once its gone through the list of dates, we can examine the CSV, and find which restore date has the directory in the state we want it to be. I'll include what I can of the script below.

Thanks again for the assist.

Code: Select all
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
## Declare
$job = "<jobname>"
$vm = "vmname"
$path = "c:\veeamflr\"
$dir = "<second half of path>" 
$finalpath = $path+$vm+$dir
$countcsv = "C:\util\scripts\count.csv"
$creationcsv = "C:\util\scripts\creationtimestring.csv"

##Generate List of Dates to examine. This is separate, in case we want to remove entries from the CSV.
##Could/should be separate script all together, but there may be a case for it to be together as well
$gen = Get-VBRBackup -Name $job | get-vbrrestorepoint -name "$vm"
$gen.creationtimestring >> $creationcsv

#import date, start the loop
import-csv $creationcsv -header date | foreach-object{
$dateofres=$_.date

#Start the Restore
write-host "Attempting to restore" $dateofres
$res = Get-VBRBackup | where {$_.JobName -eq "$job"} | Get-VBRRestorePoint | sort CreationTime -Descending | where {$_.VMName -eq "$vm"} | select -First 1 | Start-VBRWindowsFileRestore

#count the files - Where we still have problems
$files = (get-childitem $finalpath -recurse).count

#put the count, the vm name and backup creation date in a csv
$files, $res.name, $res.CreationTimeString >> $countcsv
#stop the file restore
stop-vbrwindowsfilerestore $vm
}
alex.nunley
Influencer
 
Posts: 19
Liked: never
Joined: Fri Jan 18, 2013 3:36 pm
Full Name: Alex Nunley

Re: Start-VBRWindowsFileRestore and getting a folder path

Veeam Logoby v.Eremin » Thu Jan 23, 2014 9:36 pm

So, I'm wondering what was the root cause of the said error; might be helpful for the future readers. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests