[Working Blog] ONTAP Snapshot Reporting in Python - Part 3 - Snapshot Naming Convention

Continuing from part 2, we left it at:

"We need to create a program that creates a list of expected snapshots based on snapshot policy."

Setting Up the Lab

I thought I'd start by setting up my lab with similar snapshot policies to the real-world scenario this bit of work is based on.

Apart from slight name changes, these are the cron schedules and snapshots policies:

######################################
# Cron Schedules for Snapshot Policy #
######################################

job schedule cron create -name x-daily     -minute 5 -hour 0
job schedule cron create -name x-hours4    -minute 0 -hour 0,4,8,12,16,20
job schedule cron create -name x-hours4-tp -minute 0 -hour 0,4,8,12,16,20

#####################
# Snapshot Policies #
#####################

snapshot policy create -policy x-tier1    -enable true -schedule1 x-hours4    -count1 18 -prefix1 x-hours4    -snapmirror-label1 x-hours4    -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily
snapshot policy create -policy x-tier2    -enable true -schedule1 x-hours4    -count1 18 -prefix1 x-hours4    -snapmirror-label1 x-hours4    -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily
snapshot policy create -policy x-tier1-tp -enable true -schedule1 x-hours4-tp -count1 18 -prefix1 x-hours4-tp -snapmirror-label1 x-hours4-tp -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily -retention-period1 3 days
snapshot policy create -policy x-tier2-tp -enable true -schedule1 x-hours4-tp -count1 18 -prefix1 x-hours4-tp -snapmirror-label1 x-hours4-tp -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily -retention-period1 3 days

###############################################################
# Initialize Compliance Clock for Tamperproof Snapshots (TPS) #
###############################################################

date
cluster time-service ntp server show
license show -package SnapLock

compliance-clock initialize -node NODENAME # Answer y to the prompt

#########################################################################
# Note: For TPS remember to enable snapshot locking on the volume with: #
#########################################################################

volume create -vserver VSERVER_NAME -volume VOLUME_NAME -snapshot-locking-enabled true
volume modify -vserver VSERVER_NAME -volume VOLUME_NAME -snapshot-locking-enabled true

Note: I've not used code block in Blogger before. For  the above I used:

[Medium.com] How to add code snippets in blogger posts

The only problem with the above is that it's a 30 day snapshot policy and the labs I use only last for maximum 7 days. So I'll make it a 30 hours snapshot policy instead (have to make the retention period 1 days as cannot do 30 days):

job schedule cron create -name x-daily     -minute 59 -hour 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23
job schedule cron create -name x-hours4    -minute 0,10,20,30,40,50
job schedule cron create -name x-hours4-tp -minute 0,10,20,30,40,50

snapshot policy create -policy x-tier1-tp -enable true -schedule1 x-hours4-tp -count1 18 -prefix1 x-hours4-tp -snapmirror-label1 x-hours4-tp -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily -retention-period1 1 days
snapshot policy create -policy x-tier2-tp -enable true -schedule1 x-hours4-tp -count1 18 -prefix1 x-hours4-tp -snapmirror-label1 x-hours4-tp -schedule2 x-daily -count2 30 -prefix2 x-daily -snapmirror-label2 x-daily -retention-period1 1 days

Our dailies are now hourlies and the 4 hourlies run 6 times an hour (as opposed to 6 times a day).

Creating A Vserver with Some Test Volumes

vserver create -vserver TIER1
vserver create -vserver TIER2

volume create -vserver TIER1 -volume TVOL101  -snapshot-policy x-tier1 -aggregate cluster1_01_aggr1 -size 10g
volume create -vserver TIER1 -volume TVOL102t -snapshot-policy x-tier1-tp -snapshot-locking-enabled true -aggregate cluster1_01_aggr1 -size 10g

volume create -vserver TIER2 -volume TVOL201  -snapshot-policy x-tier2 -aggregate cluster1_02_aggr1 -size 10g
volume create -vserver TIER2 -volume TVOL202t -snapshot-policy x-tier2-tp -snapshot-locking-enabled true -aggregate cluster1_02_aggr1 -size 10g

And within 30 hours we'll have volumes with a full compliment of snapshots with the correct naming convention.

Snapshot Naming Convention in ONTAP

This is fairly straightforward:

PREFIX.YYYY-MM-DD_HHMM

And to work out the name of all the scheduled snapshots on the volume, it's a case of:

  1. Get the time
  2. Go back in time for each snapshot cron schedule
    1. for the specified count
      1. generating PREFIX.YYYY-MM-DD_HHMM
And you only need to generate this list once per schedule (since all volumes under the same snapshot policy will have the same snapshot names.)


Comments