Showing posts with label Netapp . Powershell. Show all posts
Showing posts with label Netapp . Powershell. Show all posts
Wednesday, January 29, 2014
Neatened version of snapshot reporting scrip
import-module dataontap
$HourlyResultsTooMany= @()
$HourlyResultsTooFew= @()
$HourlyResultsNone= @()
$filers = "filer1,filer2,filer3,filer4,filer5,filer6"
$filers | foreach-object {
#write-host $_
connect-nacontroller $_
$vmvols = get-NaVol | Where-Object { ($_.name -like "*vmnfs*" -or $_.name -like "*vmwaredata*") -and -not ($_.name -like "*m" -or $_.name -like "*m2" -or $_.name -like "*page" -or $_.name -like "*srmph" -or $_.name -like "*swap" -or $_.name -like "*sw" -or $_.name -like "*vdi*" -or $_.name -like "*NonProd" -or $_.name -like "*filer1syslog" -or $_.name -like "*filer2vdisys" -or $_.name -like "*filer40*") }
$vmvolc = $vmvols | measure-object
if ($vmvolc.count -gt 0) {
$vmvols | ForEach-Object {
$vmsnaps = Get-NaSnapshot $_.name | Where-Object { ($_.name -like "smvi*") -and ($_.name -like "*hourly*") -and ($_.name -notlike "*appsercvr*")} | measure-object
write-host "volume: " $_.name " Snapshots: " $vmsnaps.count
if ($vmsnaps.Count -eq 0) {
$HourlyResultsNone += New-Object psobject -Property @{
'Volume' = $_.name
}
}
if ($vmsnaps.Count -ge 25 ) {
$HourlyResultsTooMany += New-Object psobject -Property @{
'Volume' = $_.name
'No Of Snapshots' = $vmsnaps.count
}
}
if ($vmsnaps.Count -lt 24 ) {
$HourlyResultsTooFew += New-Object psobject -Property @{
'Volume' = $_.name
'No Of Snapshots' = $vmsnaps.count
}
}
}
}
}
If ( $DailyResultsNone.count -ge 0) {
Send-MailMessage -From "someone@companyname.ie" -To "someone@companyname.ie" -Subject 'Hourly Snapshot Alert , Some Volumes do not have any Hourly snapshots' -Body ( $HourlyResultsNone | Out-String )
}
If ( $DailyResultsTooFew.count -ge 0) {
Send-MailMessage -From "someone@companyname.ie" -To "someone@companyname.ie" -Subject 'Hourly Snapshot Alert , Some Volumes do not have enough Hourly snapshots' -Body ( $HourlyResultsTooFew | Out-String )
}
If ( $DailyResultsTooMany.count -ge 0) {
Send-MailMessage -From "someone@companyname.ie" -To "someone@companyname.ie" -Subject 'Hourly Snapshot Alert , Some Volumes have too many Hourly snapshots' -Body ( $HourlyResultsTooMany | Out-String )
}
Thursday, January 23, 2014
Find volumes without autodelete or autosize enabled
powershell script to loop through each of the filers looking for any VMnfs volume which did not have the autosize enabled and was not able to autogrow
import-module dataontap
$results= @()
$filers = "Filer1","Filer2","Filer3","Filer4","Filer5","Filer6"
$filers | foreach-object {
write-host $_
connect-nacontroller $_
$vmvols = get-NaVol | Where-Object { ($_.name -like "*vmnfs*" -or $_.name -like "*vmwaredata*" -or $_.name -like "*VDI*" ) -and -not ($_.name -like "*m" -or $_.name -like "*m2" -or $_.name -like "*page" -or $_.name -like "*srmph" -or $_.name -like "*swap" -or $_.name -like "*sw" -or $_.name -like "*vdi*" -or $_.name -like "*NonProd" -or $_.name -like "*filer1vmnfsvolsyslog" -or $_.name -like "*filer2vmnfsvolvdisys" -or $_.name -like "*filer3vmnfsvol0*") }
foreach ($volume in $vmvols) {
$VolumeName=$volume.name
$volumeSize=$volume.SizeTotal
$VolumeSizeAvailable=$volume.SizeAvailable
$autogrow = Get-NaVolAutosize -name $volume
$AutogrowEnabled = $autogrow.isenabled
$SnapshotAutodelete = Get-nasnapshotautodelete $volume
}
If (($AutogrowEnabled -notlike "true" ) -or ($SnapshotAutodelete[4].OptionValue -notlike "on") )
{
$results += New-Object psobject -Property @{
'Volume' = $volume
'AutogrowEnabled' = $autogrowEnabled
'SnapshotAutodelete' = $SnapshotAutodelete[4].OptionValue
}
}
}
import-module dataontap
$results= @()
$filers = "Filer1","Filer2","Filer3","Filer4","Filer5","Filer6"
$filers | foreach-object {
write-host $_
connect-nacontroller $_
$vmvols = get-NaVol | Where-Object { ($_.name -like "*vmnfs*" -or $_.name -like "*vmwaredata*" -or $_.name -like "*VDI*" ) -and -not ($_.name -like "*m" -or $_.name -like "*m2" -or $_.name -like "*page" -or $_.name -like "*srmph" -or $_.name -like "*swap" -or $_.name -like "*sw" -or $_.name -like "*vdi*" -or $_.name -like "*NonProd" -or $_.name -like "*filer1vmnfsvolsyslog" -or $_.name -like "*filer2vmnfsvolvdisys" -or $_.name -like "*filer3vmnfsvol0*") }
foreach ($volume in $vmvols) {
$VolumeName=$volume.name
$volumeSize=$volume.SizeTotal
$VolumeSizeAvailable=$volume.SizeAvailable
$autogrow = Get-NaVolAutosize -name $volume
$AutogrowEnabled = $autogrow.isenabled
$SnapshotAutodelete = Get-nasnapshotautodelete $volume
}
If (($AutogrowEnabled -notlike "true" ) -or ($SnapshotAutodelete[4].OptionValue -notlike "on") )
{
$results += New-Object psobject -Property @{
'Volume' = $volume
'AutogrowEnabled' = $autogrowEnabled
'SnapshotAutodelete' = $SnapshotAutodelete[4].OptionValue
}
}
}
Thursday, July 25, 2013
Powershell script to age out Netapp snapshots
I had a an incident where i had to recreate the SMVI jobs on one of our Filers , we have a requirement to keep 26 days of backups online.
As always space was at a premium so What i wanted to do was to delete the old version of the SMVI
Snapshot each time after the new snapshot was taken...
so i created a script which loops through decreasing the value of the number of backups we want to keep
$days = -26
for ($loops = 26;$loops -ge 0; $loops --)
{
$BackupstoKeep = (get-date).adddays($days)
Connect-nacontroller "Filer1"
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $Backupstokeep } | remove-nasnapshot
Connect-nacontroller "Filer2"
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $Backupstokeep } | remove-nasnapshot
$days++
Start-sleep 86400
}
I had a an incident where i had to recreate the SMVI jobs on one of our Filers , we have a requirement to keep 26 days of backups online.
As always space was at a premium so What i wanted to do was to delete the old version of the SMVI
Snapshot each time after the new snapshot was taken...
so i created a script which loops through decreasing the value of the number of backups we want to keep
$days = -26
for ($loops = 26;$loops -ge 0; $loops --)
{
$BackupstoKeep = (get-date).adddays($days)
Connect-nacontroller "Filer1"
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $Backupstokeep } | remove-nasnapshot
Connect-nacontroller "Filer2"
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $Backupstokeep } | remove-nasnapshot
$days++
Start-sleep 86400
}
Thursday, September 20, 2012
Netapp Powershell command to find all snapshots older than 28 days
1 Download dataontap PS module and extract to c:\windows\system32\windowspowershell\1.0\modules
2 Import the netapp powershell module
Import-Module dataontap
3 define $28days as being todays date - 28 days
$28days = (get-date).adddays(-28)
4 connect to the controller
connect-nacontroller "controllername"
5 view the list of snapshots that are older than 28 days
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days }
6 See what snapshots will be deleted
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days } | remove-nasnapshot -whatif
7 Delete the snapshots
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days } | remove-nasnapsho
2 Import the netapp powershell module
Import-Module dataontap
3 define $28days as being todays date - 28 days
$28days = (get-date).adddays(-28)
4 connect to the controller
connect-nacontroller "controllername"
5 view the list of snapshots that are older than 28 days
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days }
6 See what snapshots will be deleted
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days } | remove-nasnapshot -whatif
7 Delete the snapshots
Get-Navol | Get-NaSnapshot | where-object { $_.name -like "smvi_*" -and $_.created -lt $28days } | remove-nasnapsho
Wednesday, July 25, 2012
Powershell script to alert for missing snapshots
We had a problem with SMVI not taking backups and to make matters worse not alerting us to the fact that it was not taking backups , the software can only alert if the backup job fails or if it generates warnings which is fine.
But what happens when the job doesnt start , the SMVI service doesnt stop and nothing alerts you to the fact that no backups are taken... this was the second time this happened , the first time could be attributed to a random occurrence but the second time it happens ... well then your waiting to get caught with your pants around your ankles...
I made a short script , scheduled to run each evening , which would send a mail if there were no snapshots less than a day old.
#gets todays date , stores it in the format day-month-year in the variable $nowDate
$NowDate =get-date -uformat "%d-%m-%y"
#Loops through c:\snapshotsourcelist.txt assigning one line to the variable $snappath
For ($file = [System.IO.File]::OpenText("c:\snapshotsourcelist.txt");
!($file.EndOfStream); $snappath = $file.readline())
{
#recursively scan through all subdirectories of $snappath
$Snapshotlist = get-childitem $snappath -recurse |
#we are only interested in files and not directories
where-object {$_.mode -notmatch "d"} |
#cant scan this for some reason so excluding it from the search criteria
Where-object {$_.name -notlike "*iegwydc01*"} |
#returns files which have a datestamp of today
where-object {$_.lastwritetime -gt [datetime]::parse($nowDate)}
#if the variable is empty then send a mail
if (!$Snapshotlist) {
write-host 'Snapshot Alert , No Snapshots for' +$snappath 'were taken since 00:00 last night'
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpServer = "mailserver.domain.com"
$SmtpClient.host =
$SmtpServer
$From = "ie-dlitalerts@domain.com"
$To = "Darragh@domain.com"
$Title = 'Snapshot Alert , No Snapshots for' +$snappath
$Body = 'Snapshot Alert , No Snapshots for' +$snappath
$SmtpClient.Send($from,$to,$title,$Body) }
}
But what happens when the job doesnt start , the SMVI service doesnt stop and nothing alerts you to the fact that no backups are taken... this was the second time this happened , the first time could be attributed to a random occurrence but the second time it happens ... well then your waiting to get caught with your pants around your ankles...
I made a short script , scheduled to run each evening , which would send a mail if there were no snapshots less than a day old.
#gets todays date , stores it in the format day-month-year in the variable $nowDate
$NowDate =get-date -uformat "%d-%m-%y"
#Loops through c:\snapshotsourcelist.txt assigning one line to the variable $snappath
For ($file = [System.IO.File]::OpenText("c:\snapshotsourcelist.txt");
!($file.EndOfStream); $snappath = $file.readline())
{
#recursively scan through all subdirectories of $snappath
$Snapshotlist = get-childitem $snappath -recurse |
#we are only interested in files and not directories
where-object {$_.mode -notmatch "d"} |
#cant scan this for some reason so excluding it from the search criteria
Where-object {$_.name -notlike "*iegwydc01*"} |
#returns files which have a datestamp of today
where-object {$_.lastwritetime -gt [datetime]::parse($nowDate)}
#if the variable is empty then send a mail
if (!$Snapshotlist) {
write-host 'Snapshot Alert , No Snapshots for' +$snappath 'were taken since 00:00 last night'
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpServer = "mailserver.domain.com"
$SmtpClient.host =
$SmtpServer
$From = "ie-dlitalerts@domain.com"
$To = "Darragh@domain.com"
$Title = 'Snapshot Alert , No Snapshots for' +$snappath
$Body = 'Snapshot Alert , No Snapshots for' +$snappath
$SmtpClient.Send($from,$to,$title,$Body) }
}
Subscribe to:
Posts (Atom)