ONTAP Discussions

254 snapshot limit on volume

IGORSTOJNOV
8,264 Views

Hiya!

 

One of the volumes on our 7-Mode 8.1.4 systems has hit a 254 snapshot limit... It holds the underlying LUN for one of the vSphere datastores (APP01), whose purpose is to host virtual disks for a lot of virtual machines. These machines also have disks on other datastores as well so when VSC is creating snapshots for either one of these other datstores, it triggers a snapshot for APP01 datastore also. And the snapshot retention we have in place made the volume reach it's snapshot limit a few days ago.

 

node1> snap autodelete app01
snapshot autodelete settings for app01:
state                           : on
commitment                      : try
trigger                         : volume
target_free_space               : 20%
delete_order                    : oldest_first
defer_delete                    : user_created
prefix                          : (not specified)
destroy_list                    : none

 

As you can see above, snap autodelete is enabled - but as far as I can see, there's no trigger for snapshout count.

Only for volume,  snap_reserve or space_reserve utilization. And neither of those is the case here...

 

Is there a way to automate deletion of oldest snapshots once snapshot count reaches maximum value?

 

Regards,

Igor

1 ACCEPTED SOLUTION

mbeattie
8,197 Views

Hi,

 

Here is an "example" script for you. The code to delete the snapshots is commented out so it will simply state what it "would" do if you remove the mulit line comments "<# #>" around the do loop.

As an example i have used hourly snapshots. EG

 

TESTNS01> vfiler run testnv01 snap list volume_01

===== testnv01
Volume volume_01
working...

  %/used       %/total  date          name
----------  ----------  ------------  --------
 29% (29%)    0% ( 0%)  Jan 12 20:00  hourly.0
 47% (32%)    0% ( 0%)  Jan 12 16:00  hourly.1
 57% (32%)    0% ( 0%)  Jan 12 12:00  hourly.2
 64% (32%)    0% ( 0%)  Jan 12 08:00  hourly.3
 70% (32%)    0% ( 0%)  Jan 12 00:00  nightly.0
 74% (36%)    0% ( 0%)  Jan 11 20:00  hourly.4
 77% (32%)    0% ( 0%)  Jan 11 16:00  hourly.5
 79% (32%)    0% ( 0%)  Jan 11 00:00  nightly.1

 

If you wanted to automate the deletion of hourly snapshots greater than a threshold (i've used 4) to retain hourly.0-3 then the following script will do that. I'd imagine your configuration is somewhat similar with a differenent snapshot naming standard for you 254 snapshots (you might want to consider setting the snapshot threshold variable to a lower value, eg 250 to ensure manual snapshots can be taken if required).

 

#'------------------------------------------------------------------------------
Import-Module DataONTAP
[String]$controllerName = "testns01"
[String]$vfilerName     = "testnv01"
[String]$snapshotPrefix = "hourly"
[String]$volumeName     = "volume_01"
[Int]$snapshotThreshold = 4
$credentials            = Get-Credential -Credential root
#'------------------------------------------------------------------------------
#'Connect to the controller and vfiler.
#'------------------------------------------------------------------------------
Try{
   Connect-NaController -Name $controllerName -Vfiler $vfilerName -HTTPS -Credential $credentials | Out-Null
   Write-Host "Connected to controller ""$controllerName"" vfiler ""$vfilerName"""
}Catch{
   Throw $("Failed connecting to controller ""$controllerName"" vfiler ""$vfilerName"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------------
#'Enumerate the snapshots for the vfilers volume matching the snapshot prefix.
#'------------------------------------------------------------------------------
Try{
   $snapshots = Get-NaSnapshot $volumeName "$snapshotPrefix*" -Terse | Select-Object -Property Name, Created
   Write-Host "Enumerated snapshots for volume ""$volumeName"" matching ""$snapshotPrefix`*"""
}Catch{
   Throw $("Failed enumerating snapshots for volume ""$VolumeName"" matching snapshot prefix ""$snapshotPrefix"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------------
#'Exit if the snapshot count is less than or equal to the threshold.
#'------------------------------------------------------------------------------
If($snapshots.Count -le $snapshotThreshold){
   Write-Host $("There are " + $snapshots.Count + " snapshots on volume ""$volumeName"" on vfiler ""$vFilerName"". Exiting")
   Break;
}
#'------------------------------------------------------------------------------
#'Delete the snapshots. 
#'------------------------------------------------------------------------------
[Int]$errorCount = 0
For($i = $snapshotThreshold; $i -le ($snapshots.Count -1); $i++){
   [String]$snapshotName = $snapshots[$i].Name
   [String]$creationDate = $snapshots[$i].Created
   Write-Host "Deleting snapshot ""$snapshotName"" created on ""$creationDate"" for volume ""$volumeName"" on vfiler ""$vFilerName"""
   <#
   Do{
      Try{
         Remove-NaSnapshot $volumeName $snapshotName -ErrorAction Stop
         Write-Host "Deleted snapshot ""$snapshotName"" created on ""$creationDate"" for volume ""$volumeName"" on vfiler ""$vFilerName"""
      }Catch{
         Write-Warning -Message $("Failed deleting snapshot ""$snapshotName"" created on ""$creationDate"" for volume ""$volumeName"" on vfiler ""$vFilerName"". Error " + $_.Exception.Message)
         [Int]$errorCount = $errorCount + 1
      }
   }Until($True)
   #>
}
If($errorCount -ne 0){
   Throw "Failed deleting snapshots"
}
#'------------------------------------------------------------------------------

The output will look like:

 

Connected to controller "testns01" vfiler "testnv01"
Enumerated snapshots for volume "volume_01" matching "hourly*"
Deleting snapshot "hourly.4" created on "01/11/2016 20:00:04" for volume "volume_01" on vfiler "testnv01"
Deleting snapshot "hourly.5" created on "01/11/2016 16:00:34" for volume "volume_01" on vfiler "testnv01"

 

Have a look at the autodelete options for the volume. EG

 

TESTNS01> vfiler run testnv01 snap autodelete volume_01

===== testnv01
snapshot autodelete settings for volume_01:
state                           : off
commitment                      : try
trigger                         : volume
target_free_space               : 20%
delete_order                    : oldest_first
defer_delete                    : user_created
prefix                          : (not specified)
destroy_list                    : none

 

You can use the "defer_delete" and "prefix" options to specify which snapshots to delete last (not first)

 

/matt

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

View solution in original post

11 REPLIES 11
Public