Microsoft Virtualization Discussions

Script for Volumes not Taking snapshots

ahmada
4,140 Views
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
4,072 Views

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
4,073 Views

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.

ahmada
4,027 Views

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

Public