HPE Storage Users Group https://www.3parug.com/ |
|
Automatic VMWare VM "snapping" prior to Virtual Copy. https://www.3parug.com/viewtopic.php?f=17&t=162 |
Page 1 of 1 |
Author: | franck.fuziol [ Tue Jun 19, 2012 5:46 pm ] |
Post subject: | Automatic VMWare VM "snapping" prior to Virtual Copy. |
Hello all, I wrote this script a while back and it has been very usefull to us; maybe somebody else can benefit from it. Basically what it does, is trigger a VMWare snapshoot of all VM in a Datastore prior to trigerring a 3PAR Virtual Copy of the associated LUN (need to have a 1 to 1 relationship of VMWare datastore to LUN). Once completed, it then remove the VMWare shapshoots. In case of a VM failure, the Virtual Copy can be presented back to a VMWare host, the datastore re-discovered (VMWare will complain about a duplicate disk ID and will ask to re-ID it). At that point you can browse the datastore, re-import the VM, go back to the last snapshoot to have a crash consistant VM. We typically power up the VM from the the Virtual Copy Datastore and then do a storage vMotion to a production datastore to keep downtime to a minimum. Once completed, you can just unmount and unpresent the datastore. Hope this make sense. Franck. #************************** # Project Name: PowerSnap * #******************************************************************************* # Author: Franck Fuziol - Seminole Hard Rock Hotel and Casino Hollywood * # Revision History: * # - 1.0 - 01/20/12 - Original Relase * #******************************************************************************* # Role: * # The role of this script is to obtain a crash consistent copy of all VMs in a * # datastore(s) and save them into a 3PAR Virtual Copy(s) for a pre-set number * # of days (7). If needed the 3PAR Virtual Copy can be presented to a VMWare * # host and the relevant crash consistent VM (ie VMWare Snaped) recovered. * #******************************************************************************* # Usage: * # Typically this script would be called from a batch file (see sample below) * # that would itself be called daily from Microsoft scheduler * #******************************************************************************* # * Software Dependencies: * # - Microsoft PowerShell * # - VMWare PowerCLI * # - Putty.exe (recommend placing in System32) * # * Authentication Dependencies: * # - VMWare vCenter account with right to create/remove snapshots to VMs * # - 3PAR account with right to create Virtual Copy * # * 3PAR requirement: * # - the Virtual Volume for the Datastore MUST have a copy space set * # * PowerShell Execution Policy: * # By default the PowerShell execution Policy is set to restricted.(for more * # info type get-help about_signing in powershell). * # In order for the script to run you will have to set the policy to * # unrestricted by opening a CMD, then launching "powershell", then entering: * # set-executionpolicy unrestricted * # * PowerSnap.BAT file sample: * # POWERSHELL "C:\Backup-ESX-Datastores.ps1" * #******************************************************************************* Function PowerSnap {param ($VMWareDatastore, $3PARVV, $3PARSnapPrefix) $SnapTime = GET-DATE -UFORMAT "%Y-%m-%d_%H-%M" get-vm -Datastore $VMWareDatastore | new-snapshot -name PowerSnap $TempFile = $Env:temp + '\3PAR-CMD.TXT' if (Test-Path $TempFile) {del $TempFile} [System.IO.File]::AppendAllText($TempFile, "createsv -ro -exp 7D " + $3PARSnapPrefix + "_" + $SnapTime + " " + $3PARVV, [System.Text.Encoding]::default) $3PARTarget = $3PARUser + '@' + $3PARServer putty.exe -ssh $3PARTarget -pw $3PARPassword -m $TempFile Start-Sleep -s 15 get-vm -Datastore $VMWareDatastore | get-snapshot -name PowerSnap | remove-snapshot -confirm:$false } #******************************************************************************* # VMWare Virtual Center Credentials * #******************************************************************************* $VCServer = 'VCenterServerName' $VCUser = 'domain/user' $VCPassowrd = 'XXXXXXXX' #******************************************************************************* # 3PAR Credentials * #******************************************************************************* $3PARServer = '12.34.56.78' $3PARUser = '3paradm' $3PARPassword = 'XXXXXXXXX' Add-PSSnapin VMware.VimAutomation.Core connect-viserver -server $VCServer -user $VCUser -password $VCPassowrd #******************************************************************************* # PowerSnap function synthax: * # PowerSnap 'VMWare Datastore' '3PAR Virtual Volume' '3PAR Virtual Copy Prefix'* # 'VMWare Datastore' - Name of the Datastore in VMWare * # '3PAR Virtual Volume' - Name of the associated 3PAR Virtual Volume * # '3PAR Virtual Copy Prefix' - Prefix of the 3PAR Virtual Copy. This prefix * # will be followed by the Date Time of the VC * #******************************************************************************* PowerSnap '3PAR Datastore 001' 'HWHR-ESX_Datastore_001' 'ESX-DS-001' PowerSnap '3PAR Datastore 002' 'HWHR-ESX_Datastore_002' 'ESX-DS-002' PowerSnap '3PAR Datastore 003' 'HWHR-ESX_Datastore_003' 'ESX-DS-003' PowerSnap '3PAR Datastore 004' 'HWHR-ESX_Datastore_004' 'ESX-DS-004' PowerSnap '3PAR Datastore 005' 'HWHR-ESX_Datastore_005' 'ESX-DS-005' PowerSnap '3PAR Datastore 006' 'HWHR-ESX_Datastore_006' 'ESX-DS-006' PowerSnap '3PAR Datastore 007' 'HWHR-ESX_Datastore_007' 'ESX-DS-007' PowerSnap '3PAR Datastore 008' 'HWHR-ESX_Datastore_008' 'ESX-DS-008' PowerSnap '3PAR Datastore 009' 'HWHR-ESX_Datastore_009' 'ESX-DS-009' PowerSnap '3PAR Datastore 010' 'HWHR-ESX_Datastore_010' 'ESX-DS-010' |
Author: | Richard Siemers [ Wed Jun 20, 2012 3:55 pm ] |
Post subject: | Re: Automatic VMWare VM "snapping" prior to Virtual Copy. |
Franck, that is a great script and good info about ESX prompting to re-id the volume. Thank you for sharing. |
Page 1 of 1 | All times are UTC - 5 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |