ONTAP Discussions

Using powershell to enabled scheduled snapshots

zenmatrix83
5,043 Views

I can't seem to get scheduled snapshots enabled through powershell. I can assign a policy, but auto snapshots is not enabling, the below script says its sucessful, but the box remains unchecked and no snapshots are created. I tried setting nosnap directly but that says

 

Set-NcVolOption : Modification of the following fields: auto-snapshots-enabled not allowed for volumes of the type "Flexible Volume - Read-Write volume".

At line:1 char:1

+ Set-NcVolOption -Key "nosnap" -Value "off" -Name UCS_SAS_APP02_PROD01 ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (172.25.200.217:NcController) [Set-NcVolOption], EONTAPI_EVOLOPNOTSUPP

    + FullyQualifiedErrorId : ApiException,DataONTAP.C.PowerShell.SDK.Cmdlets.Volume.SetNcVolOption

 

Is there a way to do this? Below is the code I'm using.

 

$vols=Get-NcVol | ?{
# get non-root volumes
$_.VolumeStateAttributes.IsNodeRoot -eq $false `
-and
# which are rw (this will exclude SnapMirror, etc.)
$_.VolumeIdAttributes.Type -eq "rw" `
-and
(
# with "nosnap" turned on
(($_ | Get-NcVolOption -Hashtable).value.nosnap -eq "on") `
-or
# or with snapshot policy set to Target Policy
($_.VolumeSnapshotAttributes.SnapshotPolicy -eq "Daily_SS")
)
}

foreach($vol in $vols)
{
$volName=$vol.Name
$policyName="Daily_SS"
$query = @{
Name = $volName
}

$attributes = @{
VolumeSnapshotAttributes = @{
SnapshotPolicy = $policyName
}
}

$a=Get-NcVol -Template
Initialize-NcObjectProperty $a VolumeSnapshotAttributes

$a.VolumeSnapshotAttributes.AutoSnapshotsEnabled=$true

Update-NcVol -Query $query -Attributes $a


}

4 REPLIES 4

Ontapforrum
5,027 Views

Hi,

Disclaimer: I am not an expert on powershell stuff.

 

I think the "AutoSnapshotEnabled" property is set depending upon the policy.

 

If the policy is none -> AutoSnapshotEnabled = false
If the policy is set to say 'default' AutoSnapshotEnabled = True

 

Could you just try setting the 'policy' only, don't change anything else ?

Thanks!

zenmatrix83
5,021 Views

I did that originally, I looked for any policy that was set to none, and change it the DAILY_SS polciy thats in the code. It looks like the policy did change, but no snapshots are being created and the box is unchecked in the gui. The odd thing is we have another cluster I did the same thing in and it seems to work there, but I'm not sure what I did to get it to apply correctly there.  Its the nosnap option in the volume that I can see change when I check the box in the gui, but powershell won't let me modify that directly for somereason.

 

Ontapforrum
5,018 Views

Interesting case, I used this script to test mine. Attached here. We have some PS experts in the forums, they will know.

zenmatrix83
4,887 Views

I think your example works because its going from a policy to a no policy, its trying to go from a non to a policy which I can't seem to do reliably. I think I did it at one point but I can't replicate it, like I mentioned before, it looks to have applied on one cluster, but our DR cluster I couldn't get it work in any of the methods I mentioned. I eneded up just enabling them manually but I'm very interested in the proper method.

Public