Effective December 3, NetApp adopts Microsoft’s Business-to-Customer (B2C) identity management to simplify and provide secure access to NetApp resources.
For accounts that did not pre-register (prior to Dec 3), access to your NetApp data may take up to 1 hour as your legacy NSS ID is synchronized to the new B2C identity.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Microsoft Virtualization Discussions

Script for Volumes not Taking snapshots

ahmada
Greetings,
8.2.4 7-mode
I am looking for a script that will show me which volumes didn't take snapshots last night.

All my volumes are scheduled to take snapshots at 20:00 PM
1 ACCEPTED SOLUTION

asulliva

Hello @ahmada,

 

Here is one version, though you could do a rudimentary check beforehand to see if the number of snapshots taken at the desired time matches the number of volumes.  If they don't match, then start looking for the volumes which are missing a snapshot.

 

# the reference time which we want to have a snapshot taken at
# this will return an object referencing yesterday at 8pm
$refTime = [DateTime]::Today.AddDays(-1).AddHours(20)

# get only volumes with the snapshot policy we want
Get-NcVol -Query @{ VolumeSnapshotAttributes = @{ SnapshotPolicy = "default" } } | ForEach-Object {

    # get snapshots for the volume which match the reference time
    if ( ($_ | Get-NcSnapshot | Where-Object { $_.AccessTimeDT -eq $refTime }).count -ne 1) {

        # if there wasn't one returned, state so in red
        Write-Host -ForegroundColor Red "Volume $($_.Name) does not have a snapshot at the reference time"

    } else {

        # there was one returned, say so in green
        Write-Host -ForegroundColor Green "Volume $($_.Name) has a snapshot at the reference time"

    }
}

 

Note that this is for Clustered ONTAP.  The 7-mode cmdlets used will be slightly different (I don't have a 7-mode system to test against), but the principle is the same.

 

Hope that helps.

 

Andrew

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

View solution in original post

2 REPLIES 2

asulliva

Hello @ahmada,

 

Here is one version, though you could do a rudimentary check beforehand to see if the number of snapshots taken at the desired time matches the number of volumes.  If they don't match, then start looking for the volumes which are missing a snapshot.

 

# the reference time which we want to have a snapshot taken at
# this will return an object referencing yesterday at 8pm
$refTime = [DateTime]::Today.AddDays(-1).AddHours(20)

# get only volumes with the snapshot policy we want
Get-NcVol -Query @{ VolumeSnapshotAttributes = @{ SnapshotPolicy = "default" } } | ForEach-Object {

    # get snapshots for the volume which match the reference time
    if ( ($_ | Get-NcSnapshot | Where-Object { $_.AccessTimeDT -eq $refTime }).count -ne 1) {

        # if there wasn't one returned, state so in red
        Write-Host -ForegroundColor Red "Volume $($_.Name) does not have a snapshot at the reference time"

    } else {

        # there was one returned, say so in green
        Write-Host -ForegroundColor Green "Volume $($_.Name) has a snapshot at the reference time"

    }
}

 

Note that this is for Clustered ONTAP.  The 7-mode cmdlets used will be slightly different (I don't have a 7-mode system to test against), but the principle is the same.

 

Hope that helps.

 

Andrew

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

View solution in original post

ahmada

Thanks a lot worked like a charm 🙂

 

For some reason when I converted it for 7-mode '-eq' wasn't working as expected. I replaced it with '-gt' and had to settel to a snpashot named hourly.0 was taken yesterday Smiley Very Happy

 

# the reference time which we want to have a snapshot taken at
# this will return an object referencing yesterday at 8pm
$refTime = [DateTime]::Today.AddDays(-1)
$snapName = "hourly.0"
$password = ConvertTo-SecureString "Netapp1!" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential  -ArgumentList "root",$password

#Connect to Filer
Connect-NaController 192.168.1.212 -Credential $cred


Get-NaVol| ForEach-Object {

    # get snapshots for the volume which match the reference time
    if ( ($_ | Get-NaSnapshot | Where-Object { $_.AccessTimeDT -gt $refTime -and $_.Name -eq $snapName }).count -ne 1) {

        # if there wasn't one returned, state so in red
        Write-Host -ForegroundColor Red "Volume $($_.Name) does not have a snapshot at the reference time"

    } else {

        # there was one returned, say so in green
        Write-Host -ForegroundColor Green "Volume $($_.Name) has a snapshot at the reference time"

    }
}

Thanks again, your help made my day

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public