-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-PureSnapshot.ps1
97 lines (94 loc) · 3.62 KB
/
New-PureSnapshot.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
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
94
95
96
97
<#
NAME : New-PureSnapshot.ps1
AUTHOR: Jake Dennis
DATE : 4/8/2019
DESCRIPTION
This script will take a volume snapshot on a Pure flash array. The user must provide the array name, valid storage admin credentials, and name of the volume that resides on the array.
#>
function New-PureSnapshot{
function Connect-PureArray{
$ModuleName="PureStoragePowerShellSDK"
try{
if(Get-Module | Where-Object {$_.Name -eq $ModuleName}){
Write-Output ""
Write-Output "Loading $($ModuleName)..."
Write-Output ""
}
else{
Write-Output "Attempting to install $($ModuleName)."
Install-Module -Name $ModuleName
}
Import-Module -Name $ModuleName
}
catch{
Write-Host "There was a problem installing the PureStoragePowerShellSDK module."
Write-Host "Consult Pure Support's documentation regarding installation of the binary."
Start-Sleep -Seconds 10
Exit
}
$tries = 0
do{
#attempt login to Pure flash array
try{
$Array = Read-Host -Prompt "Enter the array hostname or IP address that needs to be connected to"
$Creds = Get-Credential -Message "Enter administrative credentials for $($Array). Example: sa_account or svc.account"
$Global:ArrayConnection = New-PfaArray -EndPoint $Array -Credential $Creds -IgnoreCertificateError -HttpTimeOutInMilliSeconds 8000 -ErrorAction Stop
$Success=$true
}
catch{
$tries++
Write-Output ""
Write-Output $_
Write-Output ""
Write-Output "Try again."
Start-Sleep -Seconds 2
}
#allow for 5 attempts
}until($tries -eq 5 -or $success)
if(-not($success)){
Write-Host ""
Write-Output "Error limit reached. Terminating script."
Start-Sleep -Seconds 10
Exit
}
$ArrayConnection
} #end Connect-PureArray
function Take-PureSnapshot{
$tries = 0
do{
#attempt to take snapshot of user provided volume
try{
$PureVolume = Read-Host "Enter the name of the Pure volume needing a snapshot taken"
$Suffix = "Backup-$((Get-Date).ToString("MM-dd-yyyy-HHmm"))"
Write-Output ""
Write-Output "Taking snapshot for volume named $($PureVolume)..."
New-PfaVolumeSnapshots -Array $ArrayConnection -Sources $PureVolume -Suffix $Suffix
$Success=$true
}
catch{
$tries++
Write-Output ""
Write-Output $_
Write-Output ""
Write-Output "Error encountered. Please check the name of the volume and try again."
Start-Sleep -Seconds 2
}
#allow for 5 attempts
}until($tries -eq 5 -or $success)
if(($success)){
Write-Output "Snapshot taken."
Get-PfaVolumeSnapshots -Array $ArrayConnection -VolumeName $PureVolume
Start-Sleep -Seconds 10
}
if(-not($success)){
Write-Host ""
Write-Host "Maximum attempts reached. Terminating script."
Start-Sleep -Seconds 10
Exit
}
} #end Take-PureSnapshot
Connect-PureArray
Take-PureSnapshot
}
#Run parent function
New-PureSnapshot