Powershell: Restore the most recent backup of all VM's

PowerShell script exchange

Powershell: Restore the most recent backup of all VM's

Veeam Logoby steegy » Thu Nov 13, 2014 8:01 am

Hello everyone,

Using powershell, I would like to restore all VM's, made by a specific backup job, but only the latest version of the VM's.
So far I ran my tests with this script;


Add-PSSnapin VeeamPSSnapin
$respool = Get-VBRServer -Name "esx04" | Find-VBRViResourcePool -Name "test-restore"
$datastore = Get-VBRServer -Name "esx04" | Find-VBRViDatastore -Name "veeam"
$rpo = Get-VBRBackup -Name "customer1*" | Get-VBRRestorePoint -Name * | Sort-Object $_.creationtime -Descending | Select -Last 1
Start-VBRRestoreVM -restorepoint $rpo –Server "esx04" -ResourcePool $respool -Datastore $datastore
exit


Of course, due to the parameter "Select -Last 1", the script only selects the last version of the last backupped VM, and restores it.
All other VM's in the backup job are not restored.
Does anyone know if this is possible please?

Thanks in advance
steegy
Novice
 
Posts: 4
Liked: never
Joined: Thu Nov 13, 2014 7:49 am
Full Name: kevin

Re: Powershell: Restore the most recent backup of all VM's

Veeam Logoby steegy » Thu Nov 13, 2014 9:57 am

Hello,

I found a solution myself.
This script makes a list of all VM's in a specific backup job, and gets only the backups that were created in the last 8 hours.
Then it does a restore of the entire list:


Add-PSSnapin VeeamPSSnapin
$8hour = (get-date).addHours(-8)
$respool = Get-VBRServer -Name "esx04" | Find-VBRViResourcePool -Name "test-restore"
$datastore = Get-VBRServer -Name "esx04" | Find-VBRViDatastore -Name "veeam"
$rpo = Get-VBRBackup -Name "customer1*" | Get-VBRRestorePoint -Name * | where {$_.CreationTime -gt $8hour} | sort-object @{Expression={$_.CreationTime}; Ascending=$false}

foreach ($rpopervm in $rpo) {
Start-VBRRestoreVM -restorepoint $rpopervm –Server "esx04" -ResourcePool $respool -Datastore $datastore
}

exit
steegy
Novice
 
Posts: 4
Liked: never
Joined: Thu Nov 13, 2014 7:49 am
Full Name: kevin

Re: Powershell: Restore the most recent backup of all VM's

Veeam Logoby v.Eremin » Thu Nov 13, 2014 12:14 pm

Hi, Kevin,

Glad to hear that you've nailed it yourself. However, be aware that the fist script provided uses the incorrect sorting algorithm. With such expression ("Sort-Object $_.creationtime -Descending | Select -Last 1") not the latest, but rather the oldest restore point will be selected.

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

[MERGED] How to schedule a VM restore to target server?

Veeam Logoby Marcus » Wed Dec 06, 2017 12:03 pm

Hi Guys,

I wonder could anyone help me out with the following.

I have a host server (Server1) and target server (server2)

I need to set up a scheduled restore of my 4 vm's (vm1 , vm2 , vm3 ,vm4) every Friday at 8pm.

Would nay of you have dine this before or have any handy scripts.
Thanks
Mark
Marcus
Influencer
 
Posts: 21
Liked: 1 time
Joined: Wed Jul 13, 2016 4:33 pm
Full Name: Marcus MaC

Re: Powershell: Restore the most recent backup of all VM's

Veeam Logoby v.Eremin » Wed Dec 06, 2017 12:46 pm

Hi, Marcus,

Take a look at the example provided above and ask for additional clarification, should need be.

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


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 1 guest