-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPureStorage Restore All PG Volumes.ps1
46 lines (43 loc) · 4.57 KB
/
PureStorage Restore All PG Volumes.ps1
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
###########################################################################
#
# NAME: (Pure Storage) Restore most recent protection group volumes
# on a target array.
#
# AUTHOR: Andrew Reeves
#
# COMMENT: Use this script to grab the most recently replicated snapshot
# from each protection group on a taget array and restore/copy
# out as pure volumes.
# ** Script does not assign new volumes to a host/group.
# ** This can either be done manually after volume creation
# ** or by adding '-Hostname "hostabc123"' to the
# ** Restore-PfaProtectionGroupVolumeSnapshots command below.
# Note: If volume is protected by multiple PGs. Script will skip
# additional volume creation because of duplicate names.
#
# VERSION HISTORY:
# 1.0 8/11/2015 - Initial release
#
###########################################################################
# Import appropriate module (if not already added)
Import-Module PureStoragePowerShellSDK
# Gather information from the user
$faip = Read-Host "Enter the IP or FQDN of the array you'd like to work from"
$pfxlabel = Read-Host "Enter the prefix label to be used for snapshot copies"
# Connect to session/controller and pull list of PGs
$pfasession = New-PfaArray -EndPoint $faip -Credentials(Get-Credential) -IgnoreCertificateError
$pfagroups = (Get-PfaProtectionGroups -Array $pfasession).name
# Loop through each PG name
foreach ($name in $pfagroups) {
# Determine the last fully replicated snap for that PG
$helper = Get-PfaProtectionGroupSnapshotReplicationStatus -Array $pfasession -Name $name | Where-Object {$_.progress -eq 1.0} | Select-Object -Last 1
# Make sure the previous step returned something (can be null if there are no snaps or if none have fully replicated)
if (-not ($helper -eq $null)) {
# Divy up the snapshot details so we can pass them to the restore command
$pgsourcename = $helper.name.Split(".")[0]
$snapname = $helper.name
Write-Host "$faip | Restoring all volumes from: $snapname (group: $pgsourcename) using the prefix $pfxlabel"
# NOTE: Command below does not exist in SDK post 2.x. Need to locate and update command.
Restore-PfaProtectionGroupVolumeSnapshots -FlashArray $faip -ProtectionGroup $pgsourcename -SnapshotName $snapname -Prefix $pfxlabel -Session $pfasession
}
}