Microsoft Virtualization Discussions

Script to list snapshot copies of all volumes

justin_smith
23,347 Views

Im looking for a script that will give me the snapshot copies names, date/time, size, etc for each individual volume on a filer.

Preferably I'd like something exported to excel that would show me:

Volume Name

     Snapshot copy name

     Snapshot copy name

Based on the screen shot the output would be this:

testSM

     hourly.0   

     hourly.1

     nightly.0

     hourly.2

Etc....

Doable?

1 ACCEPTED SOLUTION

olson
23,345 Views

sorry about that syntax for the cdot is slightly different.

This should do it for you.

Import-Module dataontap

Connect-NaController [filer] -Credential root

get-navol|get-nasnapshot|Export-Csv mysnapshots.csv

View solution in original post

11 REPLIES 11

olson
23,176 Views

Justin,

One way to do this is with the data ontap powershell toolkit

Import-Module dataontap

Connect-NcController Mycluster or

          connect-nacontroller filer

Get-NcSnapshot|Export-Csv mysnapshots.csv  or

           Get-NaSnapshot|Export-Csv mysnapshots.csv

You could also limit down the output by specifiy the volume or the svm(vserver) volume name pattern.

Regards

John

justin_smith
23,176 Views

Im familiar with the OnTap toolkit.

It doesnt like the Get-NcSnapshot command:

Get-NcSnapshot : Value cannot be null.

Parameter name: Controller parameter neither specified nor set in $global:CurrentNcController

Here's my script:

Import-Module dataontap

Connect-nacontroller REALFILERNAME -Credential jsmith

Get-NcSnapshot|Export-Csv mysnapshots.csv

justin_smith
23,176 Views

Looks like thats a cluster mode command?

I think Im figuring it out, Im using the get-nasnapshot command which is for 7 mode. The only thing is, I need it to grab ALL volumes.

Import-Module dataontap

Connect-nacontroller REALFILERNAME -Credential jsmith

Get-NaSnapshot|Export-Csv 'H:\NetApp Scripts\snapshots.csv'

What happens is it asks me for a TargetName for the volumes.

olson
23,346 Views

sorry about that syntax for the cdot is slightly different.

This should do it for you.

Import-Module dataontap

Connect-NaController [filer] -Credential root

get-navol|get-nasnapshot|Export-Csv mysnapshots.csv

justin_smith
23,176 Views

That seemed to work....

Only thing is it gives me the info bassackwards.

Is there a way to get the TargetName on the first column of the spreadsheet?

olson
23,176 Views

Your welcome!

You can format the output with the select command.

get-navol|get-nasnapshot |select TargetName,name,Created|Export-Csv mysnapshots.csv

You can select any of the rows in the header.


Created

Cumulative

AccessTime

AccessTimeDT

Busy

ContainsLunClones

CumulativePercentageOfTotalBlocks

CumulativePercentageOfUsedBlocks

CumulativeTotal

Dependency

Name

PercentageOfTotalBlocks

PercentageOfUsedBlocks

SnapshotOwnersList

TargetName

TargetType

Total

ContainsLunClonesSpecified

Regards,

John

justin_smith
23,176 Views

Thanks, that worked too... last question.

Here's my current script:

Import-Module dataontap

$Controller = @('filername')

Foreach ($filer in $controller)

{

Connect-nacontroller $filer -Credential jsmith

get-navol | get-nasnapshot | select TargetName,name,Created | Export-Csv 'H:\NetApp Scripts\$filer.snapshots.csv'

}

Im looking for it to save the file with the filername.snapshot. I've tried filername_snapshot and filername.snapshot, but it only gives it the $filer.snapshot name.....

Neal1703
13,806 Views

Hi justin_smith 

 

 

Could you please let me know how you have saved file "filername' for command $Controller = @('filername').

 

If possible could you please share script as well

asulliva
13,774 Views

Hello @Neal1703,

 

He is simply using "filername" as a place holder here.  The "@()" turns it into an array so that  if there are multiple the bits of script below can loop over them.

 

$Controller = @('myNetApp.local.com', 'myOtherNetApp.local.com', 'myDRNetApp.remove.com')

 

@justin_smith,

 

You asked:  "m looking for it to save the file with the filername.snapshot. I've tried filername_snapshot and filername.snapshot, but it only gives it the $filer.snapshot name....."  You're seeing that behavior because of the single quotes around the value.  If you replace with double quotes it should work...

 

Get-NaVol | Get-NaSnapshot | select TargetName,name,Created | Export-Csv "H:\NetApp Scripts\$($filer).snapshots.csv"

 

If you're curious, there is a lot of information about variable expansion in string output here.

 

Hope that helps.

 

Andrew

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

mythily
20,983 Views

I need script for deleting snapshot more than 32 days in the cluster in CMode.


@justin_smith wrote:

Im looking for a script that will give me the snapshot copies names, date/time, size, etc for each individual volume on a filer.

 

Preferably I'd like something exported to excel that would show me:

 

Volume Name

     Snapshot copy name

     Snapshot copy name

 

Based on the screen shot the output would be this:

 

testSM

     hourly.0   

     hourly.1

     nightly.0

     hourly.2

 

Etc....

 

Doable?


 

asulliva
20,965 Views

You should start a new topic to get the best visibility.  With that being said, this should work for you:

 

Get-NcSnapshot | ?{ $_.Created -lt (Get-Date).AddDays(-33) }

Hope that helps.

 

Andrew

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