Subscribe
Accepted Solution

Get most recent snapshot

Hi All,

I need to set a variable name to that of the most recent snapshot name in a given volume (we're gonna vol clone it).   This is likely really basic and easy but I'm just starting to work in powershell and need a hint.  Thanks for your replies.

Get most recent snapshot

I found one way of doing this, based on their appearance in the snap list and not date/timestamp:

Get-NaSnapshot vol0 | select -expandproperty name -first 1

it works, but still interested in seeing anything anyone else is doing.

Get most recent snapshot

I use the following to get the SME snap name.

Get-NaSnapshot volume exchsnap__* | select-object Name -last 1

Just learning powershell myself but hope it helps

Bren

Get most recent snapshot

Your almost there... To get the last snapshot you just need to add a sort to your pipeline.

$SnapName = Get-NaSnapshot -name vol0 |             
    Sort-Object -Property Created -Descending |             
    Select-Object -ExpandProperty Name -First 1


~Glenn

Re: Get most recent snapshot

I see this referenced all of the time...the "Created" property of a snapshot. I've got filers, with ONTAP 7.3.4 thru 8.0.2, and none of them return a "Created" property of a snapshot. I have resorted to sorting by AccessTimeDT. Am I missing something?

Example:

Get-NaVol | Get-NaSnapshot | Get-Member

Results:

Name                              MemberType Definition

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

Equals                            Method     bool Equals(System.Object obj)

GetHashCode                       Method     int GetHashCode()

GetType                           Method     type GetType()

ToString                          Method     string ToString()

Validate                          Method     System.Void Validate()

AccessTime                        Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

AccessTimeDT                      Property   System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=...

Busy                              Property   System.Nullable`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=n...

CumulativePercentageOfTotalBlocks Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

CumulativePercentageOfUsedBlocks  Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

CumulativeTotal                   Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

Dependency                        Property   System.String Dependency {get;set;}

Name                              Property   System.String Name {get;set;}

PercentageOfTotalBlocks           Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

PercentageOfUsedBlocks            Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

SnapshotOwnersList                Property   NetApp.Ontapi.Filer.Snapshot.SnapshotOwner[] SnapshotOwnersList {get;set;}

Total                             Property   System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neu...

Re: Get most recent snapshot

Hi, Brad.  You must be using an older version of the Toolkit.  We often use a shortened field name in the tabular views to conserve space, and in a recent release we added a number of alias properties so that you can always refer to fields by the column headers.  In your case, Created == AccessTimeDT.

PS C:\> get-nasnapshot vol0 weekly.0

Name                                               Created      Total Cumulative Dependency

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

weekly.0                                        10/24/2011   116.0 KB    76.1 MB

PS C:\> get-nasnapshot vol0 weekly.0 | gm

   TypeName: NetApp.Ontapi.Filer.Snapshot.SnapshotInfo

Name                              MemberType    Definition

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

Created                           AliasProperty Created = AccessTimeDT

Cumulative                        AliasProperty Cumulative = CumulativeTotal

Equals                            Method        bool Equals(System.Object obj)

GetHashCode                       Method        int GetHashCode()

GetType                           Method        type GetType()

ToString                          Method        string ToString()

Validate                          Method        System.Void Validate()

AccessTime                        Property      System.Nullable`1[[System.Int64, mscorlib, V

AccessTimeDT                      Property      System.Nullable`1[[System.DateTime, mscorlib

Busy                              Property      System.Nullable`1[[System.Boolean, mscorlib,

CumulativePercentageOfTotalBlocks Property      System.Nullable`1[[System.Int64, mscorlib, V

CumulativePercentageOfUsedBlocks  Property      System.Nullable`1[[System.Int64, mscorlib, V

CumulativeTotal                   Property      System.Nullable`1[[System.Int64, mscorlib, V

Dependency                        Property      System.String Dependency {get;set;}

Name                              Property      System.String Name {get;set;}

PercentageOfTotalBlocks           Property      System.Nullable`1[[System.Int64, mscorlib, V

PercentageOfUsedBlocks            Property      System.Nullable`1[[System.Int64, mscorlib, V

SnapshotOwnersList                Property      NetApp.Ontapi.Filer.Snapshot.SnapshotOwner[]

TargetName                        Property      System.String TargetName {get;set;}

TargetType                        Property      System.String TargetType {get;set;}

Total                             Property      System.Nullable`1[[System.Int64, mscorlib, V

Re: Get most recent snapshot

Got it. Updated DataOntap toolkit to 1.5 and I now see the alias. I appreciate the quick response.

Thanks