Saturday, 7 December 2013

Data ONTAP PowerShell: Function to find the Oldest Day of Retention of a Snapshot Policy

This is actually a parked project due to the unanticipated complexity and simply not having the time available to dedicate to its cause. Still, it’s worth sharing and may help whomsoever is reading and trying to achieve the same. Here’s how far I got after an evening’s toil.

Firstly, I’ll present how far I got with the code (it’s not yet a function, just a standalone piece), then provide a sample output to see where we’ve got, then outline what’s required next to make the function all it can be, and finally end with a bit on understanding volume snapshot policies (which is essential to achieve what is desired from the completed function’s output.)

The Code

# A work to be progressed!
Import-Module DataONTAP
$cluster = "192.168.168.40"
$username = "admin"
$encrypted = Get-Content c:\scripts\encrypted_password.txt | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential($username, $encrypted)
Connect-NcController $cluster -credential $credential

$snapshotPolicies = Get-NcSnapshotPolicy

foreach ($snapshotPolicy in $snapshotPolicies) {

$snapshotPolicyName = $snapshotPolicy.policy
$getSPtotalSchedules = $snapshotPolicy.TotalSchedules
$getSPpolicySchedules = $snapshotPolicy.SnapshotPolicySchedules

"Investigating this snapshot policy: $snapshotPolicyName"

if ($getSPtotalSchedules) {
           
$i = 0

do {
       
$getSPPolicySchedule = $getSPpolicySchedules[$i]
$theCount = $getSPPolicySchedule.count
$theScheduleName = $getSPPolicySchedule.schedule
$theActualSchedule = Get-NcJobSchedule -Name $theScheduleName
$theJobSchedulesDescription = $theActualSchedule.JobScheduleDescription
"This snapshot policy has a schedule of count $theCount running at: $theJobSchedulesDescription"
           
$i++

} until ($i -eq $getSPtotalSchedules)
       
} # $getSPtotalSchedules
         
} # $snapshotPolicy

A Sample Output

Investigating this snapshot policy: default
This snapshot policy has a schedule of count 6 running at: @:05
This snapshot policy has a schedule of count 2 running at: @0:10
This snapshot policy has a schedule of count 2 running at: Sun@0:15
Investigating this snapshot policy: long
This snapshot policy has a schedule of count 50 running at: @0:10
This snapshot policy has a schedule of count 50 running at: @:05
Investigating this snapshot policy: none
Investigating this snapshot policy: testDisabled
This snapshot policy has a schedule of count 1 running at: Sun@0:15

What’s Required Next

We’ve got as far as obtaining a string which gives the job schedule. Remember, this job schedule can be in cron or interval format, and it can contain months, days, dates, hours, minutes, and seconds. Here is where I envisage this project proceeding:

1) Create a function to convert the output cron/interval job string into something usuable.
2) Once 1 is complete, the function can be completed to return an array of Snapshot Policy Schedules and the date of what should be the oldest retained snapshot on this snapshot policy.

Simple …

Second: Understanding Volume Snapshot Policies

A volume has a snapshot policy > a snapshot policy can have up to five job schedules > job schedules can be of type cron or interval and in many units of time. The easiest way to give an understanding is to simply display the create options.

When you create a volume in Clustered Data ONTAP, one of the optional fields (defaults to default if not specified) is “-snapshot-policy”:

::> volume create -snapshot-policy ?

What options are there for creating a snapshot policy?

::> volume snapshot policy create
Usage:
-policy {snapshot policy} Snapshot Policy Name
-enabled {true/false}     Snapshot Policy Enabled
-comment {text}           Comment
-schedule1 {text}         Schedule1 Name
-count1 {0..255}          Maximum Snapshot Copies for Schedule1
-prefix1 {text}           Snapshot Copy Name Prefix for Schedule1
-schedule2 {text}         Schedule2 Name
-count2 {0..255}          Maximum Snapshot Copies for Schedule2
-prefix2 {text}           Snapshot Copy Name Prefix for Schedule2
-schedule3 {text}         Schedule3 Name
-count3 {0..255}          Maximum Snapshot Copies for Schedule3
-prefix3 {text}           Snapshot Copy Name Prefix for Schedule3
-schedule4 {text}         Schedule4 Name
-count4 {0..255}          Maximum Snapshot Copies for Schedule4
-prefix4 {text}           Snapshot Copy Name Prefix for Schedule4
-schedule5 {text}         Schedule5 Name
-count5 {0..255}          Maximum Snapshot Copies for Schedule5
-prefix5 {text}           Snapshot Copy Name Prefix for Schedule5

What options are there for creating a cron type job schedule?

nc::> job schedule cron create
Usage:
-name {text}                     Name
-month {cron_month}, ...         Month
-dayofweek {cron_dayofweek}, ... Day of Week
-day {cron_dayofmonth}, ...      Day
-hour {cron_hour}, ...           Hour
-minute {cron_minute}, ...       Minute

What options are there for creating an interval type job schedule?

nc::> job schedule interval create
Usage:
-name {text}            Name
-days {integer}         Days
-hours {integer}        Hours
-minutes {integer}      Minutes
-seconds {integer}      Seconds

Parked

Parked for now! To be continued…

Image: Parked!

No comments:

Post a Comment