General Discussion

Delete files automatically older than 90 days

Palmer01
1,428 Views

Hi Everyone,

 

I am looking for a script or Cronjob command that I can execute that will delete files automatically that is older than 90 days. I have a few CIFS/SMB Shares created in NetApp ONTAP 9 (Model AFF a250) that are published to windows clients via Group Policy.  Is this something that can be configured on the volume level? Can't seem to find a KB Article on this topic.

1 ACCEPTED SOLUTION

Ontapforrum
1,379 Views

You have to use your own script from the  Host-side, or any 3rd party tool to identify 'files' (names). However, you can definitely identify the snapshots that are older than 90 days. If you look up, you might find the ready script in one of our community threads. This script can be scheduled to run as cron or Windows task manager task.

View solution in original post

2 REPLIES 2

Ontapforrum
1,380 Views

You have to use your own script from the  Host-side, or any 3rd party tool to identify 'files' (names). However, you can definitely identify the snapshots that are older than 90 days. If you look up, you might find the ready script in one of our community threads. This script can be scheduled to run as cron or Windows task manager task.

Ontapforrum
1,371 Views

Following is very basic example: (This will return snapshots more than 90 days old across cluster)

PS C:\Users\Administrator> Get-NcSnapshot |?{ $_.Created -lt (Get-Date).AddDays(-90)} 

 

Depending upon result, If you want to delete those snaps (older than 90 days), then you need to use 'remove-nscsnapshot' api, and if you don't want confirmation for each snap, simply add $flase:

PS C:\Users\Administrator> Get-NcSnapshot |?{ $_.Created -lt (Get-Date).AddDays(-90)} | remove-ncsnapshot -Confirm:$false

 

Side note: "remove-ncsnapshot" works in SVM context. So you need to make sure, you have connected to SVM before you can run that command, else it will complain APINOTFOUND.

 

Ex-

PS C:\Users\Administrator> Connect-NcController [SVM_mgmt_IP], not Cluster_Mgmt_IP.

Public