forked from rubrikinc/rubrik-scripts-for-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoke-krollrecovery.ps1
More file actions
93 lines (72 loc) · 4.08 KB
/
invoke-krollrecovery.ps1
File metadata and controls
93 lines (72 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<#
.SYNOPSIS
Allows users to setup a Kroll recovery Rubrik.
.DESCRIPTION
This script will set up a Kroll OnTrack recovery by using Rubrik to create a VM Live Mount and then move
the VMDKs from the the Live Mount to the Kroll OnTrack server. This process makes use of both the Rubrik
PowerShell Module (https://github.com/rubrikinc/PowerShell-Module) and VMWare's PowerCLI (https://www.vmware.com/support/developer/PowerCLI/).
Due to the nature of some of the disk mounting operations, the script also needs to be run in an elevated
(Administrator) session.
Depending on the security context, the user might need to provide credentials for both Rubrik and VCenter.
Please review the parameters below for more information.
Once the script execution completes, there will be a notification for cleanup. Run the provided command in the output
to cleanup the operation once the recovery work is done.
.NOTES
Written by Mike Fal for community use
Twitter: @Mike_Fal
GitHub: MikeFal
.EXAMPLE
.\KrollRecovery.ps1 -KrollServer 'DEMO-KROLL2' -TargetServer 'DEMO-EXCH10-1' -RubrikCluster 172.17.28.15 -VCenter demovcsa.rubrik.demo
Execute the KrollRecovery script remotely.
.EXAMPLE
.\KrollRecovery.ps1 -TargetServer 'DEMO-EXCH10-1' -RubrikCluster 172.17.28.15 -VCenter demovcsa.rubrik.demo
Execute the KrollRecovery script locally.
.LINK
https://github.com/rubrikinc/PowerShell-Module
https://www.vmware.com/support/developer/PowerCLI/
#>
#Requires -Modules Rubrik,VMware.VimAutomation.Core
#Requires -RunAsAdministrator
[CmdletBinding(SupportsShouldProcess = $true,ConfirmImpact = 'High')]
param(
[string]$KrollServer = $env:COMPUTERNAME
,[parameter(Mandatory=$true)]
[string]$TargetServer
,[parameter(Mandatory=$true)]
[string]$RubrikCluster
,[parameter(Mandatory=$true)]
[string]$VCenter
,[pscredential]$RubrikCred=(Get-Credential -Message "Please enter your Rubrik credential:")
,[pscredential]$VCenterCred
,[array]$DiskIDstoExclude
)
$ErrorActionPreference = 'Stop'
#Connect to the VCenter
if(-not $global:DefaultVIServers){
if(-not $VCenterCred){$VCenterCred = Get-Credential -Message "Please enter your VCenter credential:" }
Connect-VIServer -Server $VCenter -Credential $VCenterCred -Force | Out-Null
}
#connect to the Rubrik cluster
Connect-Rubrik -Server $RubrikCluster -Credential $RubrikCred | Out-Null
$reqdate = Read-Host 'Enter desired snapshot date (yyyy-mm-dd)'
#Collect Snaps from the last 24 hours
# Want a date range, show backups between
$snaps = Get-RubrikVM -Name $TargetServer | Get-RubrikSnapshot | Where-Object {((get-date $_.date).Date -eq $reqdate)} | Sort-Object Date -Descending | Select-Object
#$snaps = Get-RubrikVM -Name $TargetServer | Get-RubrikSnapshot | Where-Object {$_.date -gt (Get-Date).AddDays(-1)} | Sort-Object Date -Descending | Select-Object -First 10
#Choose snap to use
"Please select a snapshot to use:" | Out-Host
"--------------------------------" | Out-Host
$Snaps | ForEach-Object -Begin {$i=0} -Process {"SnapID $i - $(get-date $_.Date)";$i++}
$selection = Read-Host 'Enter ID of selected snapshot'
#Move VMDKs from LiveMount of target to KROLL Server
$result = Move-RubrikMountVMDK -SourceVM $TargetServer -TargetVM $KrollServer -Date $snaps[$selection].date -ExcludeDisk $DiskIDstoExclude -confirm:$false
#Output asking to cleanup after themselves
"`n--------------------------------" | Out-Host
"Once you have completed your work, please run the cleanup command: `n$($result.Example)" | Out-Host
#Perform disk cleanup on offline and read only disks
if($env:COMPUTERNAME -eq $KrollServer){
Get-Disk | Where-Object {$_.IsOffline -eq $true} | Set-Disk -IsOffline $false;get-disk | Where-Object {$_.IsReadOnly -eq $true} | Set-Disk -IsReadOnly $false
} else {
Invoke-Command -ComputerName $KrollServer -ScriptBlock {Get-Disk | Where-Object {$_.IsOffline -eq $true} | Set-Disk -IsOffline $false;get-disk | Where-Object {$_.IsReadOnly -eq $true} | Set-Disk -IsReadOnly $false}
}