Microsoft Virtualization Discussions

Getting the latest snapshot name

storageguy
6,015 Views

Hello Automation gurus,

 

I am trying to write a PS script to create flexclones using the lastest snapshot available on the snapmirror destination volume. So, far I have got the destination volumes from snapmirror relationship and getting the snapshot displayed for those volumes. I know that last snapshot is the latest one. I would like to know how get the volume name and the latest snapshot name from this list?  I am still new to PS scripting so my methods are still long way.

 

Thanks

 

Invoke-NcSsh "snapmirror show -type DP" |out-file snapmirrors

 

Get-Content .\snapmirrors |select-string vserver1 |% { (($_ -split '\s+',4)[2..2])} | %{(($_ -split ':',4)[1])} |% {Get-Ncsnapshot $_} |ft -auto

 

Name Volume Vserver Created Total Cumulative Dependen
---- ------ ------- ------- ----- ---------- --------
snapmirror.1a01e427-fffd-11e5-8686-00a0983a408c_2147484685.2016-11-18_142737 vol1_mirror vserver1-dr 19/11/16 35.1 GB 35.1 GB
8hour.2017-10-03_1015 vol1_mirror vserver1-dr 03/10/17 332.0 KB 35.1 GB
8hour.2017-10-03_1815 vol1_mirror vserver1-dr 04/10/17 180.0 KB 35.1 GB
8hour.2017-10-04_0215 vol1_mirror vserver1-dr 04/10/17 280.0 KB 35.1 GB
8hour.2017-10-04_1015 vol1_mirror vserver1-dr 04/10/17 312.0 KB 35.1 GB
8hour.2017-10-04_1815 vol1_mirror vserver1-dr 05/10/17 160.0 KB 35.1 GB
8hour.2017-10-05_0215 vol1_mirror vserver1-dr 05/10/17 212.0 KB 35.1 GB
8hour.2017-10-05_1015 vol1_mirror vserver1-dr 05/10/17 240.0 KB 35.1 GB
8hour.2017-10-05_1815 vol1_mirror vserver1-dr 06/10/17 168.0 KB 35.1 GB
8hour.2017-10-06_0215 vol1_mirror vserver1-dr 06/10/17 256.0 KB 35.1 GB
8hour.2017-10-06_1015 vol1_mirror vserver1-dr 06/10/17 252.0 KB 35.1 GB
8hour.2017-10-06_1815 vol1_mirror vserver1-dr 07/10/17 196.0 KB 35.1 GB
8hour.2017-10-07_0215 vol1_mirror vserver1-dr 07/10/17 240.0 KB 35.1 GB
8hour.2017-10-07_1015 vol1_mirror vserver1-dr 07/10/17 460.0 KB 35.1 GB
8hour.2017-10-07_1815 vol1_mirror vserver1-dr 08/10/17 172.0 KB 35.1 GB
8hour.2017-10-08_0215 vol1_mirror vserver1-dr 08/10/17 256.0 KB 35.1 GB
8hour.2017-10-08_1015 vol1_mirror vserver1-dr 08/10/17 2.0 GB 37.1 GB
8hour.2017-10-08_1815 vol1_mirror vserver1-dr 09/10/17 184.0 KB 37.1 GB
8hour.2017-10-09_0215 vol1_mirror vserver1-dr 09/10/17 232.0 KB 37.1 GB
8hour.2017-10-09_1015 vol1_mirror vserver1-dr 09/10/17 308.0 KB 37.1 GB
8hour.2017-10-09_1815 vol1_mirror vserver1-dr 10/10/17 160.0 KB 37.1 GB
8hour.2017-10-10_0215 vol1_mirror vserver1-dr 10/10/17 160.0 KB 37.1 GB
snapmirror.ce253acd-12c8-11e4-ba75-123478563412_2147484818.2017-10-10_041000 vol1_mirror vserver1-dr 10/10/17 116.0 KB 37.1 GB
snapmirror.f7bb604b-a2e9-11e7-9ab1-00a098a83ee7_2150931583.2017-10-09_230500 vol1_mirror vserver1-dr 10/10/17 108.0 KB 37.1 GB
snapmirror.ce253acd-12c8-11e4-ba75-123478563412_2147484818.2017-10-10_051000 vol1_mirror vserver1-dr 10/10/17 0 37.1 GB busy
snapmirror.1a01e427-fffd-11e5-8686-00a0983a408c_2147484686.2016-11-18_142737 Vol2_mirror vserver1-dr 19/11/16 94.1 MB 94.1 MB
snapmirror.ce253acd-12c8-11e4-ba75-123478563412_2147484713.2017-10-10_041000 Vol2_mirror vserver1-dr 10/10/17 108.0 KB 94.2 MB
snapmirror.f7bb604b-a2e9-11e7-9ab1-00a098a83ee7_2150931591.2017-10-09_230500 Vol2_mirror vserver1-dr 10/10/17 96.0 KB 94.3 MB
snapmirror.ce253acd-12c8-11e4-ba75-123478563412_2147484713.2017-10-10_051000 Vol2_mirror vserver1-dr 10/10/17 0 94.3 MB busy
........
........

1 ACCEPTED SOLUTION

asulliva
5,963 Views

Hello @storageguy,

 

Here is an example script which, I think, does something like what you're requesting.

 

# get all snapmirror destination volumes for the desired SVM
Get-NcSnapmirror -Query @{ DestinationVserver = $svmName; RelationshipType = "data_protection"; } | ForEach-Object { # cleanup the old clone $currentClone = Get-NcVolClone -Query @{ Vserver = $svmName; ParentVolume = $_.DestinationVolume } | Get-NcVol $currentClone | Dismount-NcVol -Confirm:$false | Set-NcVol -Offline -Confirm:$false | Remove-NcVol -Confirm:$false # get the newest snapshot on the snapmirorr destination volume $newestSnap = Get-NcVol -Vserver $svmName -Name $_.DestinationVolume | Get-NcSnapshot | Sort-Object -Property Created -Descending | Select-Object -First 1 # create the volume clone $splat = @{ # the SVM to use for the clone...the same as the source volume 'Vserver' = $svmName; # the name of the new volume 'CloneVolume' = "$($_.DestinationVolume)_clone"; # the parent SVM 'ParentVserver' = $svmName; # the source volume 'ParentVolume' = $_.DestinationVolume; # the source snapshot 'ParentSnapshot' = $newestSnap.Name # thin provision 'SpaceReserve' = "none"; # junction at the new volume name, not needed if using LUNs 'JunctionPath' = "/$($_.DestinationVolume)_clone" # make sure it's an active junction, not needed if using LUNs 'JunctionActive' = $true; } New-NcVolClone @splat

# not included, making a LUN in the volume available }

It doesn't take into account export policies or LUNs, so you'll need to account for any modifications which need to happen there.  Additionally, it's pretty aggressive with simply deleting the existing clone, so if you have some sort of safety mechanism for making sure it's not in use before being destroyed you'll want to take that into account as well.

 

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

2 REPLIES 2

asulliva
5,964 Views

Hello @storageguy,

 

Here is an example script which, I think, does something like what you're requesting.

 

# get all snapmirror destination volumes for the desired SVM
Get-NcSnapmirror -Query @{ DestinationVserver = $svmName; RelationshipType = "data_protection"; } | ForEach-Object { # cleanup the old clone $currentClone = Get-NcVolClone -Query @{ Vserver = $svmName; ParentVolume = $_.DestinationVolume } | Get-NcVol $currentClone | Dismount-NcVol -Confirm:$false | Set-NcVol -Offline -Confirm:$false | Remove-NcVol -Confirm:$false # get the newest snapshot on the snapmirorr destination volume $newestSnap = Get-NcVol -Vserver $svmName -Name $_.DestinationVolume | Get-NcSnapshot | Sort-Object -Property Created -Descending | Select-Object -First 1 # create the volume clone $splat = @{ # the SVM to use for the clone...the same as the source volume 'Vserver' = $svmName; # the name of the new volume 'CloneVolume' = "$($_.DestinationVolume)_clone"; # the parent SVM 'ParentVserver' = $svmName; # the source volume 'ParentVolume' = $_.DestinationVolume; # the source snapshot 'ParentSnapshot' = $newestSnap.Name # thin provision 'SpaceReserve' = "none"; # junction at the new volume name, not needed if using LUNs 'JunctionPath' = "/$($_.DestinationVolume)_clone" # make sure it's an active junction, not needed if using LUNs 'JunctionActive' = $true; } New-NcVolClone @splat

# not included, making a LUN in the volume available }

It doesn't take into account export policies or LUNs, so you'll need to account for any modifications which need to happen there.  Additionally, it's pretty aggressive with simply deleting the existing clone, so if you have some sort of safety mechanism for making sure it's not in use before being destroyed you'll want to take that into account as well.

 

Hope that helps.

 

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

storageguy
5,918 Views

Thanks Andrew. We delete the clones after the test (deletion and creation not done at the same time). So I am testing your method.

Public