PowerShell script exchange
Post Reply
ShawnKPERS
Enthusiast
Posts: 54
Liked: 4 times
Joined: Apr 29, 2011 3:55 pm
Full Name: Shawn Nix
Contact:

Start-VBRWindowsFileRestore and getting a folder path

Post by ShawnKPERS » 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.

tsightler
VP, Product Management
Posts: 5337
Liked: 2185 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by tsightler » 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

ShawnKPERS
Enthusiast
Posts: 54
Liked: 4 times
Joined: Apr 29, 2011 3:55 pm
Full Name: Shawn Nix
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by ShawnKPERS » 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".

tsightler
VP, Product Management
Posts: 5337
Liked: 2185 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by tsightler » 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.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » 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.

ShawnKPERS
Enthusiast
Posts: 54
Liked: 4 times
Joined: Apr 29, 2011 3:55 pm
Full Name: Shawn Nix
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by ShawnKPERS » Oct 24, 2013 6:54 pm

Thanks I will give it a shot in v7 and see if I have better luck.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » 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.

alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by alex.nunley » 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.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » 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.

alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by alex.nunley » 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/p ... store.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?

nefes
Veeam Software
Posts: 623
Liked: 155 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by nefes » 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.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » Jan 23, 2014 3:15 pm

Have you tried to run the script as an Administrator? Thanks.

tsightler
VP, Product Management
Posts: 5337
Liked: 2185 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by tsightler » 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.

alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by alex.nunley » 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
}

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » 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.

alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by alex.nunley » Jan 23, 2014 9:56 pm

So we followed the methodology noted here http://forums.veeam.com/veeam-backup-re ... 18515.html. This worked, but isnt the way I wanted to do in the first place...


You know what, I am realizing this isn't what I wanted to do, and I am convinced I cant do what I wanted to do, which is to loop based solely on the date. This is still sorting and selecting the first one.

I guess I could do some thing where the value in the select - First 1 gets incremented every cycle. Not exactly what I wanted, but okay. I guess I could do a thing where the value is incremented every time it finds a value in creationtimestring, and that gets decremented each run through the other loop.

More work to be done.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » Jan 24, 2014 8:46 am

So, the cause seems to have been the way $RestorePoint variable was assigned.
You know what, I am realizing this isn't what I wanted to do, and I am convinced I cant do what I wanted to do, which is to loop based solely on the date
As long as the date stored in csv file coincides with the creation date of given restore point, there shouldn't be any issues in selecting the right restore points by its date.

Though, I'm wondering whether there is only one restore point created on a given date. In other words, can't it be that there are two restore points (for instance) assigned to $RestorePoint variable, and the script tries to start FLR session for both of them simultaneously, which results in "Exception" error? So, if I were you, I would double check it first.

Thanks.

alex.nunley
Influencer
Posts: 19
Liked: never
Joined: Jan 18, 2013 3:36 pm
Full Name: Alex Nunley
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by alex.nunley » Jan 27, 2014 2:41 pm

One of the great things about the creationdatestring, is that it includes time, so it should keep them separate, even if they occur on the same day.

drcurtis
Lurker
Posts: 1
Liked: never
Joined: May 21, 2014 10:33 pm
Full Name: David Curtiss
Contact:

{MERGED] : COIBFileInfo data type

Post by drcurtis » May 21, 2014 11:23 pm

I've been asked by our database team to set up a script that restores Windows guest files from one VM to a separate VM. More specifically, they're looking to pull database files from a production DB server into a development DB server. This way, the dev server always has updated data to test.

For instance, I want to restore VM-PROD H:\SQLData\*.mdf into VM-DEV H:\VeeamStaging. Using the GUI is simple enough, I just specify \\VM-DEV\H$\VeeamStaging in the popup destination prompt and it transfers across the network. I want to replicate this behavior using a PowerShell script.

So I'm playing with the Start-VBRRestoreVMFiles cmdlet, and this is what I have:

Code: Select all

Start-VBRRestoreVMFiles $restorepoint -Server $server -path "\\VM-DEV\H$\VeeamStaging" -Files ...
And here is where I'm confused. The parameter type for -Files is COIBFileInfo[], but nowhere can I find a description of what that data type is.

What type of parameter am I supposed to pass in here? I can't use a string such as "C:\path\", so what are my options?

Thanks in advance!
-David

nefes
Veeam Software
Posts: 623
Liked: 155 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: COIBFileInfo data type

Post by nefes » May 22, 2014 8:02 am

Have you already reviewed online help here?
The commandlet you are referring is restoring VM configuration files/disks rather than in-guest files.
You need to use Start-VBRWindowsFileRestore and copy files from mount point to share after that.
Documentation referred above provides some simple sample, please ask any additional questions, if required.

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » May 22, 2014 9:12 am

Hi, David, please take a look at the answers provided above. They contain workable examples of Windows restore can be scripted. Thanks.

jyothi
Lurker
Posts: 1
Liked: never
Joined: Aug 18, 2015 7:18 am
Full Name: Jyothi Nori
Contact:

[MERGED] : Restore File, VM using Powershell Scripting

Post by jyothi » Aug 18, 2015 7:24 am

Hi Team,

Could someone please help us in having a script in place for restoring a file and VM using Powershell , also process to perform same.

Veeam Backup & Replication version -7.0.0.871.

Your inputs are highly appreciable.

Regards,
jyothi

v.eremin
Product Manager
Posts: 16392
Liked: 1355 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRWindowsFileRestore and getting a folder path

Post by v.eremin » Aug 18, 2015 8:24 am

Code examples that work with version 7 can be found above. If someday you update to version 8, kindly, use script provided in the adjacent thread. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest