ONTAP Discussions

Powershell Help

axsys
4,676 Views

Hey Guys,

 

Have a powershell question, if you could help me?

I have a volume and clone volume in the same svm. the svm is in a snapmirror relationship every 15 minutes. At some point after a month or two I remove the clone, create a new one and want to get rid of the unneeded data = remove old snapshot.

 

situation before:

> Connect-NcController –name filer1 -Vserver svmtest

> get-ncvol | foreach-object {$ParentName=$_.Name;get-ncsnapshot $_.Name clone*}

 

Name                      Volume               Vserver                   Created      Total Cumulative Dependency

----                      ------               -------                   -------      ----- ---------- ----------

clone_volftest.0          volftest             svmtest                 3/27/2017   800.0 KB   888.0 KB

clone_volftest.1          voltest              svmtest                 3/27/2017   456.0 KB     1.4 MB snapmirror

clone_volftest.0          voltest              svmtest                 3/27/2017    84.0 KB   180.0 KB busy,vclone

 

I'm running this cmdlet to get rid of the obsolete snapshots:

get-ncvol | foreach-object {$ParentName=$_.Name;get-ncsnapshot $_.Name clone*} | where-object {$_.Dependency -eq $null} | remove-ncsnapshot -Confirm:0 -ErrorAction SilentlyContinue

 

 

situation after:

Name                      Volume               Vserver                   Created      Total Cumulative Dependency

----                      ------               -------                   -------      ----- ---------- ----------

clone_volftest.0          voltest              svmtest                 3/27/2017    84.0 KB   280.0 KB busy,vclone

 

Can anyone tell me why it's removing the snapshot that still has Dependency "snapmirror" in it? Dependency is not empty in this case, why is he removing that one too?

Problem is that this one is breaking my mirror and completely replicates my clone volumes which turns out to fill up my space in the DR.

 

Thanks,

axsys

 

6 REPLIES 6

JGPSHNTAP
4,657 Views

I personally would have tackled this different.

 

I'm not a fan of using ; in any powershell string if I don't have to.

 

 

If you know the snapshot can be deleted based on a date, then you should be querying the name and off this date.

 

For example

 

PS C:\powershell> get-ncvol  | get-ncsnapshot | ? {$_.name -like "*hourly*"} | ? {$_.created -lt (get-date).adddays(-80)} | remove-ncsnapshot -confirm:$false

 

I chose hourly in my example, but if you have a specific name pattern in there, put it there, and then where I have -80, just put your date target there.

 

 

axsys
4,647 Views

Thanks for the answer but I don't know the date. the clone could be 2 years old or 1 week and I don't want to go and check when it was created.
What I'd like to achieve is to get rid of all clone snapshots, not snapshots in general, on the whole system that are not busy. Question stands: why is the remove-ncsnapshot removing the snapshot with "snapmirror" dependency? It should only remove the ones that are empty....

JGPSHNTAP
4,639 Views

Can you do me a favor, and show me the scenario where you remove the clone and have a new clone in a snapshot list.

 

That will help me out

axsys
4,592 Views

Name                      Volume               Vserver                   Created      Total Cumulative Dependency

----                      ------               -------                   -------      ----- ---------- ----------

clone_volftest.0          volftest             svmtest                 3/27/2017   800.0 KB   888.0 KB

clone_volftest.1          voltest              svmtest                 3/27/2017   456.0 KB     1.4 MB snapmirror

clone_volftest.0          voltest              svmtest                 3/27/2017    84.0 KB   180.0 KB busy,vclone

 

 

it's all there already? The one which says "snapmirror" under Dependency is not a busy clone - it's the old clone that I have offlined and removed. If I run the remove-ncsnapshot above cmdlet above it will remove that one too besides the one without an empty Dependency. Hope that makes sense?

JGPSHNTAP
4,588 Views

Ok, I'm not trying to be difficult here.

 

Are you trying to remove this one

clone_volftest.1          voltest              svmtest                 3/27/2017   456.0 KB     1.4 MB snapmirror

 

Or not?

 

Run a basic query instead of using $null use ""

 

For example, try this

 

get-ncvol volname | get-ncsnapshot | ? {$_.dependency -ne ""}

 

Can you highlight in bold the one you want to delete that will help me

axsys
4,572 Views

That's it. I only want to remove the clone snapshots that are empty in the field dependency. I query that with $null. I remember from the past trying it with "" but replaced it later with $null, can't remember why tho.

 

I do ask where-object {$_.Dependency -eq $null}. to me this means Dependecy has to be empty in order to remove the snapshot? or am I wrong?

 

Thank you!

Carlos

Public