Microsoft Virtualization Discussions

Why doesn't Set-NcSnapshotSnaplockExpTime set the snapshot snaplock expiry?

Beardmann
3,301 Views

I am trying to set the "snaplock-expiry-time" of a bunch of snapshots using the ONTAP Powershell toolkit...

Ontap 9.13.1P2, Powershell Toolkit 9.13.1.2306

I get the snapshot created value with the Get-NcSnapshot, then add 30 days with the $snapexpdate = $snapshot.Created.adddays(30)

I verify that the variables have been set correctly.

I then use the Set-NcSnapshotSnaplockExpTime with the -ExpiryTime $snapexpdate and the command executes OK.

Only thing is that this sets the "expiry-time" of the snapshot and not the "snaplock-expiry-time" which is not the same thing...

How do I set the "snaplock-expiry-time" of my snapshots?

Of cause I have the correct license (ONTAP One), snaplock compliance clock has been set, and snaplock has been set on the volume... and I am able to set the snaplock-expiry-time from both the commandline and GUI...  not apparently not via Powershell... ?

Is this a bug?  And is there other ways to set this?

8 REPLIES 8

TzwaynY
3,152 Views

Hi there,

no, this is not a bug.

In order to set the desired time you want for the snaplock expiration, you need to create a new object from 

DataONTAP.C.Types.Volume.Snaplock
With that Object you can set the time and settings for the snaplocked Snapshots.
Hope that helps!
 
Best regards
Kai

Beardmann
3,138 Views

Hi

Looking at the PowerShell Toolkit help document, I fail to see this.

All I want to do is to set the equivalent of "snapshot modify-snaplock-expiry-time -vserver vserver -volume vol -snapshot snap -expiry-time "MM/DD/YYYY HH:MM:SS" "

Pretty sure this is what the cmdlet "Set-NcSnapshotSnaplockExpTime" is supposed to set?

"Funny enough" if you look at the "Catagories" and "Snaplock" in the Toolkit manual, it doesn't mention this cmdlet because it is placed inder "Snapshot" with the description of "Modifies snaplock expiry time of a snapshot copy."  The manual does not mention anything about the object you refer to?

Please be aware that there is a difference in the "Snapshot Snaplock" and "normal" Snaplock on a volume...   But if you have a code-example I would be happy to try it out... 

TzwaynY
3,132 Views

Hi,

you will not find this, that is true. I figgured this out myself a while ago, because there is no documentary for this. I need to look it up later in my script how its done right, but here is a quick example:

 

$Snaplock = New-Object DataONTAP.C.Types.Volume.Snaplock

$Snaplock.Retention.Default = #Time Here
$Snaplock.Retention.minimum = #Time Here
$Snaplock.Retention.maximum = #Time Here
 
With that, you create a table with the needed values for snaplocking. You can (if i remember this correctly)  also use this, for setting the snaplock times on a snapshot itself or volume.
 
The other way would be, to set the time via RESTAPI. Also possible with powershell.
 
Best regards
Kai

Beardmann
3,006 Views

Hi Kai

Thanks for the details.  I still fail to see how you would integrate this object into the "Set-NcSnapshotSnaplockExpTime" cmdlet... ?

Also the object you describe isn't documented anywhere in the documentation, and there are no examples as to how to use it.

Would it be too much to ask for a simple example code where you set a specific snapshot's snaplock-expiry time?

TzwaynY
2,909 Views

Hi,

sorry for the late answer. I think its best, to do it via RestApi Post.

There you will have no problems at all.

What you will need:

 

 

 

            $BASEURL = "https://$NetAppIP/api" #URL FOR THE REST API POST 
            $VOLUMEURL = "$BaseUrl/storage/volumes/VOLUMEUUIDHERE" #VOL UUID
            $BASE64AUTHINFO = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username, $Password))) #This is just for authentication

            $HEADERS = @{
                "Authorization" = "Basic $BASE64AUTHINFO"
                "Content-Type"  = "application/json"
            }

 

 

 

 
And then you need the Base filled. Like this:
 
$PAYLOAD = @{
"snaplock": { "retention": { "default": "P0Y", "minimum": "P0Y", "maximum": "P30Y" } }
}
 Then do the invoke.
 
 

 

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method Post -Headers $HEADERS -Body $PAYLOAD -ErrorAction Stop -SkipCertificateCheck

$RESPONSE | ConvertTo-Json

 

 
Keep in mind, that you need the volume UUID first and insert it into the URL.
 
Hope this helps.
 
Best regards
Kai

ACWCalvinWong
2,384 Views

anyway to do it via native function? thanks!

TzwaynY
2,824 Views

Hi there,

its me again. Ive dug through my script and here is how I set the expiry for a speicifc snapshot (ive done it over the invoke-restmethod from powershell, not the powershell toolkit)

 

 

$VOLUMEURL = "https://NETAPPURL/api/storage/volumes/VOLUMEUUID/snapshots/SNAPSHOTUUID"
$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$PAYLOAD = @{
  "snaplock_expiry_time" = "2069-06-04T19:00:00+00:00" #Edit this to the desired expiration
} | ConvertTo-Json

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method Patch -Body $PAYLOAD -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

$RESPONSE = Invoke-RestMethod -Uri $VOLUMEURL -Method GET -Credential (Get-Credential) -SkipHeaderValidation -ErrorAction Stop -SkipCertificateCheck

 


Feel free to give feedback if it worked of not. I tested it, and it worked fine for me test netapp.

 

Here is a before and after screenshot:

Before:

TzwaynY_0-1700046265947.png

After:

TzwaynY_1-1700046314536.png

 

Best regards

Kai

Beardmann
2,821 Views

Hi Kai,

 

Thanks for the examples.  I will give it a try once I find time for it.  It would have been a whole lot easier if the PS would just work as expected...    It just makes everything more complex if you have to use PS mixed with REST...  And because I have to use different expiry times, I have to figure out if it is possible just to insert a PS variable into the payload... my guess is that it will not work, in which case I have to do some reformating.... 

What I do, it so pull the snapmirror label from the snapshots, and dependant on which label this is, I add x-dayes to the snapshot creation time.. say if the label was "monthly" I would add 120 days... 

We have over 1.000 snapshots on each system, so it would take awhile, and it has to work without too much "hackery" 😉

Public