In the previous post we worked out how to acquire the data we need for our snapshot report (steps 1 to 6). Now we have just 3 more steps, but these steps (7-9) will require the greatest thought.
What we need is to be able to effectively compare:
- A database like entity of real, existing snapshots to
- A database like entity of expected snapshots
Creating a database of the real snapshots is easy enough (we already have the data). The expected snapshots though!?
From a volume, we know the snapshot policy and from that, using the prefix, cron schedule, date and time, we can create the snapshots names:
vserver1,volume1, hourly.2025-04-06_1405
vserver1,volume1, hourly.2025-04-06_1305
vserver1,volume1, hourly.2025-04-06_1205
Maybe I'll try with a class for these expected snapshots ...
class x_snapshot:
def __init__(self, svm, volume, snapshot):
self.svm = svm
self.volume = volume
self.snapshot = snapshot
def __init__(self, svm, volume, snapshot):
self.svm = svm
self.volume = volume
self.snapshot = snapshot
xs1 = x_snapshot("vserver1","volume1","hourly.2025-04-05_1405")
Hmmm... how we are to do this!? This requires some thought...
Using Nested Dictionary Object for Expected Snapshots DB
We'll use a nested dictionary object. Here's a rough example of how we construct it using nested dictionaries (I'm better experienced with PowerShell Hash Tables - which I'd be using if doing this in PowerShell - dicts feel like Python's version of them). The cool thing about dictionary objects in Python is that we can use .keys(), .values() and directly search for something's existence using those keys.
expSnapsDB = {}
expSnapsDB['cluster1'] = 0
expSnapsDB['cluster1'] = {'svm1' : 0}
expSnapsDB['cluster1']['svm2'] = 0
expSnapsDB['cluster1']['svm1'] = {'vol1' : 0}
expSnapsDB['cluster1']['svm1']['vol2'] = 0
expSnapsDB['cluster1']['svm1']['vol1'] = {'hourly.2025-04-05_1405' : 1}
expSnapsDB['cluster1']['svm1']['vol1']['hourly.2025-04-05_1305'] = 1
expSnapsDB
{'cluster1': {'svm1': {'vol1': {'hourly.2025-04-05_1405': 1, 'hourly.2025-04-05_1305': 1}, 'vol2': 0}, 'svm2': 0}}
Now we know how we are going to store out expected snapshots DB. Next we need to construct this from cluster, vserver, volumes, snapshot policy and cron schedules (then we'll just need to compare what we've got with this DB, to tell use if we're missing any snapshots).
Constructing the DB of Expected Snapshots
Next task. We need to create a program that creates a list of expected snapshots based on snapshot policy.
Comments
Post a Comment