Unsolved
This post is more than 5 years old
4 Posts
0
28111
October 28th, 2015 11:00
PowerShell automation for off host backups using a Volume Snapshot.
I've looked all over the net for a script that will create a new snapshot and bring online without luck...So I've created my own that I thought I would share, hopefully this will help some of you. Please feel free to change and republish...etc. It is not the best developed script, however it does what I need it to do. I created it so that I can complete off host backups of my production SQL Cluster. The Volume is attached to my cluster where I dump the SQL backups. Then I create a snapshot and attached it to another server that I can backup with my Backup Appliance...etc.
It is being run on Windows 2012 R2, takes about 4min 15sec to run, every command runs fast except for bringing the disk online and changing to Read_Write? Have not tried it on earlier editions of Windows Server!
The script is meant to run after you have already created the snapshot, brought it online, assigned a drive letter and can read the data...etc. Since it runs every night this is what it will do;
- Set the disk(old snapshot) offline #this way I can get rid of the old Snapshot and create a new one every night
- Connect to the EqualLogic using a credential file that has the password encrypted
- Disconnect the iSCSI Initiator
- Set Snapshot Offline
- Remove all existing Snapshots
- Create a new Snapshot
- Change Snapshot to Read-Write and bring online
- Connect to iSCSI Target
- Bring Disk online
- Set disk to Read-Write
- Test path to ensure drive(snapshot) is online
- email results to recipient
- Then backup with your backup software
- Dump the next nights backup to the volume
- Then rerun the script to delete and recreate the new Snapshot, attached to off-host server, rinse and repeat...so on....etc.
Prerequisites:
- import the EqualLogic powershell commands
- set persistence so that the commands are available every time powershell is launched
- set powershell to allow execution of scripts
This can be completed by following pages 6-9 in the following link;
en.community.dell.com/.../TR1089_2D00_PowerShell_2D00_EqualLogic.pdf
PowerShell Script:
| $VolName = "VOLNAME1" #change to your volume name $GrpAddr = "192.168.50.2" #change to ip address of SAN Group $GrpName = "EQSAN" #change name of your SAN Group $credPath = 'C:\EQSNAP\cred.xml’ #Populate variable with path to txt file with encrypted password $credentials = Import-CliXml -Path $credPath #Populate variable with encrypted credentials path, #(Must export Credentials to files first see below.) $Notification = "Testing if X: Drive is online:" #Populate variable with text to print in results file $Body = @() #set $Body variable to nothing, this will be used to send email with all results. # The following directions show you how to create an encrypted xml file that # contains the username and encrypted password. You populate a variable then use the variable in the # command # Use this command below to export encrypted credentials to file...It will prompt for your Equallogic # username and password. # Then change the file name above in $CredPath to the new path\file...etc. # $MyCredentials=GET-CREDENTIAL –Credential “Username” | EXPORT-CLIXML C:\eqsnap\cred.xml # Then use the following command to poplate the variable $Credentials with the username and # password; # $credentials = Import-CliXml -Path $credPath # $credentials will be used in the Connect-EQLGroup command below # Please Note: I did this to prevent users who have access to the credential file from seeing my clear text #password. # However, This doesn't prevent someone from decrypting the file who knows what they are doing so # please lock down access to the file. # Set Disk offline $Body+=''*50 $Body+=Get-Disk -FriendlyName EQLOGIC* | Set-Disk -isOffline $True #Run Get-Disk to see the name of the disk, #Then use it in -FriendlyName as I did EQLOGIC* # Connect to Equallogic $Body+=''*50 $Body+=Connect-EqlGroup -GroupName $GrpName -GroupAddress $GrpAddr -Credential $credentials # Disconnect from iscsi initiator $Body+=''*50 $Body+=$session=$(iscsicli sessionlist | select-string "Session Id" | Out-String).split("{:}")[1].TrimStart() $Body+=iscsicli LogoutTarget $session # Set Snapshot offline $Body+=''*50 $Body+=$VolSnaps = get-eqlsnapshot -VolumeName $VolName | select -last 1 -ExpandProperty SnapShotName $Body+=Set-EqlSnapshot -VolumeName $VolName -SnapshotName $VolSnaps -OnlineStatus offline # Remove all existing Snapshots $Body+=''*50 $Body+=Remove-EqlSnapshot -VolumeName $VolName # Create a new snapshot $Body+=''*50 $Body+=New-EqlSnapshot -VolumeName $VolName # Change new Snashot to read-Write and bring online $Body+=''*50 $Body+=$VolSnaps = get-eqlsnapshot -VolumeName $VolName | select -last 1 -ExpandProperty SnapShotName $Body+=Set-EqlSnapshot -VolumeName $VolName -SnapshotName $VolSnaps -OnlineStatus online -AccessType read_write # Connect to iSCSI Target $Body+=''*50 $Body+=Update-IscsiTarget #update iScsi target with new name $Body+=Start-Sleep -s 5 #Wait a few seconds to ensure name has been refreshed $Body+=Get-IscsiTarget | Connect-IscsiTarget #Connect to all Targets # Bring Disk online $Body+=''*50 $Body+=Start-Sleep -s 5 #Wait 5 seconds to ensure target is connected. $Body+=Get-Disk | ? IsOffline | Set-Disk -IsOffline:$false #Bring any disk offline online #Set disk to Read-Write $Body+=''*50 $Body+=Start-Sleep -s 5 #Wait 5 seconds to ensure disk is online $Body+=Get-Disk -FriendlyName EQLOGIC* | Set-Disk -IsReadOnly:$false #Set any disk named Eqlogic* #to Read-Write $Body+=''*50 $Body+=$Notification $Body+=Test-Path 'X:\DirectoryName' #Test that the new snapshot is accessible $Body = $Body | Out-String $email = @{ From = "fromemail@domain.com" To = "Toemail@domain.com" Subject = "Snapshot creation job completed" SMTPServer = "192.168.56.23" Body = $body # This will take the results of the commands above and put it in the email body } send-mailmessage @email #Send email with parameters above... |
Useful Links I used to build this script;
blogs.msdn.com/.../managing-iscsi-initiator-connections-with-windows-powershell-on-windows-server-2012.aspx
blogs.technet.com/.../use-powershell-to-manage-an-equallogic-san.aspx
h t t p s://gallery.technet.microsoft.com/scriptcenter/Managing-an-EqualLogic-PS-9f
Cheers!
Greg



gregtm
4 Posts
0
October 29th, 2015 13:00
.
gregtm
4 Posts
0
October 29th, 2015 13:00
.