PowerShell script exchange
Post Reply
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Restore script taking a text file as input

Post by AndyH »

Hi all,

I have been working with our legal team on a data discovery request. The task is to restore 65 folders, from across 4 file servers, for 150 restore points. These servers are spread over 3 different jobs. Obviously, the best way to do this is to write a script that can be run outside of the backup window.

In my mind I need a script that will take an input of a text file containing the various folder paths (or 3 text files, 1 per backup job), and another file containing the restore points. I am aware of the commandlet Start-VBRRestoreVMFiles, but Powershell scripting is not one of my strong points and I'm struggling to see how I could use it with files.

I have raised this with Veeam Support, but they have suggested that I ask here.

Any help would be very much appreciated.

Andy
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

I've been working my way through this today and seem to be making some progress. I'm having difficulty with one particular statement at the moment, that of specifying a specific restore point from a VM. I'm trying to use the following:

Code: Select all

$RestorePointObject = Get-VBRBackup -Name $JobName1 | Get-VBRRestorePoint -Name $VMName1 | where {$_.CreationTime -like '$RestorePointDate1*'} 
Where $RestorePointDate1 is in the form dd/mm/yyyy and does not include the time element.

Whenever I run the above it returns null.

Every example I've found for scripts like these seems to assume that you want the latest restore point, not a specific dated restore point.
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

I've just found the following help center document and example 3 looks ideal for my purpose, but again it assumes that I want to use the latest backup.

https://helpcenter.veeam.com/docs/backu ... l?ver=95u4
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Restore script taking a text file as input

Post by veremin »

How do you assign $RestorePointDate1 variable? Are you using Get-Date cmdlet for that? Thanks!
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

I have just been specifying the date as a text string. I will be supplied with a long list of dates that I need to restore from, so $RestorePointDate1 needs to be easily editable.
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

I've just taken a look at Get-Date. Would the following work?

Code: Select all

$RestorePointDate1 = get-date 30/1/19 -format g
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Restore script taking a text file as input

Post by veremin »

Nope, you need to convert string to date time, using this approach.

For instance:

Code: Select all

$invoice = '30/1/19'
$RestorePointDate1 = [datetime]::parseexact($invoice, 'dd/m/yy', $null)
Thanks!
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

I'm not really getting anywhere with this. Let me ask in a different way.

When providing a restore point date as a string, how can I select the relevant restore point object?

Every single example I've seen assumes that you want the latest restore point, whereas I want to choose a specific date.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Restore script taking a text file as input

Post by veremin »

- Get your string value
- Convert it to a datetime, using the approach mentioned above
- Assign it to a variable
- Compare creationtime of restore point object (which is writtent in datetime format) with the converted variable

Thanks!
AndyH
Influencer
Posts: 12
Liked: never
Joined: Aug 25, 2016 8:21 am
Contact:

Re: Restore script taking a text file as input

Post by AndyH »

Ok, I have this so far

Code: Select all

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

$JobName1 = "job name"
$VMName1 = "vm name"
$RestorePointDate1 = "31-01-2019"

$RestorePointDateObject = [datetime]::parseexact($RestorePointDate1, 'dd-MM-yyyy', $null)

Disconnect-VBRServer | out-null
connect-vbrserver -server server.int -user username -password password

$RestorePointObject = Get-VBRBackup -Name $JobName1 | Get-VBRRestorePoint -Name $VMName1 | Where {$_.CreationTime -match '$RestorePointDateObject'} 

Start-VBRWindowsFileRestore –RestorePoint $RestorePointObject –Path “\\path\to\destination” -Files "c:\a\path"
The problem is with the -match operater. I've also tried -like with wildcards.
Post Reply

Who is online

Users browsing this forum: ekulaga and 21 guests