ONTAP Discussions

Setting Snaplock min/max retention periods using Powershell

Jim_Robertson
4,948 Views

We are currently implenting a new instance of Snaplock on OnTap 9.1 and need to set the minimum and maxiumum retention periods on any new volumes that are created.  From the CLI, you can use the vol snaplock modify command to set this, but we use WFA to provision all our volumes.  So, we would ideally be able to use a Powershell command to set this. 

Set-NcSnaplockRetentionTime seems like it would be the way to go, but there doesn't seem to be any options for setting the min/max.  Does anyone know of any way to do this?

1 ACCEPTED SOLUTION

mbeattie
4,918 Views

Hi Jim,

 

The API is "volume-set-snaplock-attrs" which relates to the "Set-NcSnaplockVolAttr" cmdlet. EG

Set-NcSnaplockVolAttr -Volume locked -MaximumRetentionPeriod "31 years" -VserverContext primary1

SYNTAX
    Set-NcSnaplockVolAttr [-Volume] <String> [-MinimumRetentionPeriod <String>] [-DefaultRetentionPeriod <String>]
    [-MaximumRetentionPeriod <String>] [-AutocommitPeriod <String>] [-VserverContext <String>] [-Controller
    <NcController[]>] [-ZapiRetryCount <Int32>] [<CommonParameters>]

-MinimumRetentionPeriod <String>
    Specifies the allowed minimum retention period for files to be committed to WORM state on the volume. Must be
    specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'"

 -MaximumRetentionPeriod <String>
     Specifies the allowed minimum retention period for files to be committed to WORM state on the volume. Must be
     specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'


The CLI process can be found here: https://library.netapp.com/ecm/ecm_download_file/ECMLP2507748

cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -maximum-retention-period 10years
cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -minimum-retention-period 365days
cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -default-retention-period min


From a WFA perspective you'd need to create a command. For example:

 

#'------------------------------------------------------------------------------
Param(
   [Parameter(Mandatory=$True, HelpMessage="The cluster name or IP Address")]
   [String]$ClusterName,
   [Parameter(Mandatory=$True, HelpMessage="The vserver name")]
   [String]$VserverName,
   [Parameter(Mandatory=$True, HelpMessage="The volume name")]
   [String]$VolumeName,
   [Parameter(Mandatory=$False, HelpMessage="The default retention period that will be applied to files when committed to WORM state if files has no explicit retention retention time set. Can be set to 'min', 'max', 'infinite' or a specific time in <number><suffix> format")]
   [String]$DefaultRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The allowed minimum retention period for files to be committed to WORM state on the volume. Must be specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'")]
   [String]$MinimumRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The allowed minimum retention period for files to be committed to WORM state on the volume. Must be specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'")]
   [String]$MaximumRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The autocommit-period for the snaplock volume; any file unmodified for greater than this period will be committed to WORM state. Can be specified as <number><suffix>")]
   [String]$AutocommitPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The autocommit-period for the snaplock volume; any file unmodified for greater than this period will be committed to WORM state. Can be specified as <number><suffix>")]
   [Int]$ZapiRetryCount
)
#'------------------------------------------------------------------------------
#'Create the command for setting the volumes snaplock retention
#'------------------------------------------------------------------------------
[String]$command = "Set-NcSnaplockVolAttr -Volume $VolumeName " 
If($MinimumRetentionPeriod){
   [String]$command += "-MinimumRetentionPeriod $MinimumRetentionPeriod "
}
If($DefaultRetentionPeriod){
   [String]$command += "-DefaultRetentionPeriod $DefaultRetentionPeriod "
}
If($MaximumRetentionPeriod){ 
   [String]$command += "-MaximumRetentionPeriod $MaximumRetentionPeriod "
}
If($AutocommitPeriod){
   [String]$command += "-AutocommitPeriod $AutocommitPeriod "
}
If($ZapiRetryCount){
   [String]$command += "-ZapiRetryCount $ZapiRetryCount "
}
If($VserverName){
   [String]$command += "-VserverContext $VserverName "
}
[String]$command += "-ErrorAction Stop"
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Connect-WFACluster $ClusterName
#'------------------------------------------------------------------------------
#'Invoke the command to set the snaplock retention for the volume.
#'------------------------------------------------------------------------------
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Get-WFALogger -Info -Message "Executed Command`: $command"
   Get-WFALogger -Info -Message "Set snaplock retention for volume ""$Volume"" on vserver ""$VserverName"""
}Catch{
   Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Throw "Failed Setting Snaplock retention for volume ""$VolumeName"" on vserver ""$VserverName"""
}
#'------------------------------------------------------------------------------

Note: I haven't tested this code. It's just an example to get you started.

 

/Matt

 

 

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

View solution in original post

3 REPLIES 3

mbeattie
4,919 Views

Hi Jim,

 

The API is "volume-set-snaplock-attrs" which relates to the "Set-NcSnaplockVolAttr" cmdlet. EG

Set-NcSnaplockVolAttr -Volume locked -MaximumRetentionPeriod "31 years" -VserverContext primary1

SYNTAX
    Set-NcSnaplockVolAttr [-Volume] <String> [-MinimumRetentionPeriod <String>] [-DefaultRetentionPeriod <String>]
    [-MaximumRetentionPeriod <String>] [-AutocommitPeriod <String>] [-VserverContext <String>] [-Controller
    <NcController[]>] [-ZapiRetryCount <Int32>] [<CommonParameters>]

-MinimumRetentionPeriod <String>
    Specifies the allowed minimum retention period for files to be committed to WORM state on the volume. Must be
    specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'"

 -MaximumRetentionPeriod <String>
     Specifies the allowed minimum retention period for files to be committed to WORM state on the volume. Must be
     specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'


The CLI process can be found here: https://library.netapp.com/ecm/ecm_download_file/ECMLP2507748

cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -maximum-retention-period 10years
cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -minimum-retention-period 365days
cluster1::> volume snaplock modify -vserver vs1 -volume vol1 -default-retention-period min


From a WFA perspective you'd need to create a command. For example:

 

#'------------------------------------------------------------------------------
Param(
   [Parameter(Mandatory=$True, HelpMessage="The cluster name or IP Address")]
   [String]$ClusterName,
   [Parameter(Mandatory=$True, HelpMessage="The vserver name")]
   [String]$VserverName,
   [Parameter(Mandatory=$True, HelpMessage="The volume name")]
   [String]$VolumeName,
   [Parameter(Mandatory=$False, HelpMessage="The default retention period that will be applied to files when committed to WORM state if files has no explicit retention retention time set. Can be set to 'min', 'max', 'infinite' or a specific time in <number><suffix> format")]
   [String]$DefaultRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The allowed minimum retention period for files to be committed to WORM state on the volume. Must be specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'")]
   [String]$MinimumRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The allowed minimum retention period for files to be committed to WORM state on the volume. Must be specified as <number><suffix>. Valid suffixes are 'seconds', 'minutes', 'hours', 'days', and 'years'")]
   [String]$MaximumRetentionPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The autocommit-period for the snaplock volume; any file unmodified for greater than this period will be committed to WORM state. Can be specified as <number><suffix>")]
   [String]$AutocommitPeriod,
   [Parameter(Mandatory=$False, HelpMessage="The autocommit-period for the snaplock volume; any file unmodified for greater than this period will be committed to WORM state. Can be specified as <number><suffix>")]
   [Int]$ZapiRetryCount
)
#'------------------------------------------------------------------------------
#'Create the command for setting the volumes snaplock retention
#'------------------------------------------------------------------------------
[String]$command = "Set-NcSnaplockVolAttr -Volume $VolumeName " 
If($MinimumRetentionPeriod){
   [String]$command += "-MinimumRetentionPeriod $MinimumRetentionPeriod "
}
If($DefaultRetentionPeriod){
   [String]$command += "-DefaultRetentionPeriod $DefaultRetentionPeriod "
}
If($MaximumRetentionPeriod){ 
   [String]$command += "-MaximumRetentionPeriod $MaximumRetentionPeriod "
}
If($AutocommitPeriod){
   [String]$command += "-AutocommitPeriod $AutocommitPeriod "
}
If($ZapiRetryCount){
   [String]$command += "-ZapiRetryCount $ZapiRetryCount "
}
If($VserverName){
   [String]$command += "-VserverContext $VserverName "
}
[String]$command += "-ErrorAction Stop"
#'------------------------------------------------------------------------------
#'Connect to the cluster
#'------------------------------------------------------------------------------
Connect-WFACluster $ClusterName
#'------------------------------------------------------------------------------
#'Invoke the command to set the snaplock retention for the volume.
#'------------------------------------------------------------------------------
Try{
   Invoke-Expression -Command $command -ErrorAction Stop
   Get-WFALogger -Info -Message "Executed Command`: $command"
   Get-WFALogger -Info -Message "Set snaplock retention for volume ""$Volume"" on vserver ""$VserverName"""
}Catch{
   Get-WFALogger -Error -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Throw "Failed Setting Snaplock retention for volume ""$VolumeName"" on vserver ""$VserverName"""
}
#'------------------------------------------------------------------------------

Note: I haven't tested this code. It's just an example to get you started.

 

/Matt

 

 

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

Jim_Robertson
4,798 Views

Thanks, Matt, that's exactly what I needed!

In case anyone else is looking at this, it looks like these commands are only available in the Powershell Toolkit v4.2 and later.

mbeattie
4,780 Views

Thanks Jim,

 

From a WFA perspective you would need a minimum version of 4.0GA (latest 4.1GA release recommended) with the cDOT pack 1.3.2 to ensure the powershell toolkit includes the cmdlets:

 

https://automationstore.netapp.com/pack-detail.shtml?packUuid=WFA_pack_for_managing_Clustered_Data_ONTAP&packVersion=1.3.2

 

You can check the PowerShell toolkit version include with WFA using the following commands on your WFA server:

 

PS C:\> cd 'C:\Program Files\NetApp\WFA\PoSH'
PS C:\Program Files\NetApp\WFA\PoSH> .\profile.ps1
PS C:\Program Files\NetApp\WFA\PoSH> Get-NaToolkitVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      2      0      0

/Matt

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