Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Exception on CleanupWEeklySnapshots #4

Open
MTatersKT738 opened this issue Nov 24, 2014 · 8 comments
Open

Runtime Exception on CleanupWEeklySnapshots #4

MTatersKT738 opened this issue Nov 24, 2014 · 8 comments

Comments

@MTatersKT738
Copy link

When I run the script the backups will work and I can see them in my console, however I get the following error. I need to be sure that despite the error that the cleanup part of the script will work as well.

11/24/2014 9:29:16 PM xxxx-AWS Production Daily Backup Starting
11/24/2014 9:29:16 PM Instance xxxx-AWS-DC (i-xxxxxxxb) Creating Snapshot
11/24/2014 9:29:16 PM Snapshot xxxx-AWS-DC vol-xxxxxxx Daily 20141124092916 Created for xxx-AWS-DC (i-xxxxxxxx)
11/24/2014 9:29:31 PM Cleaning up daily snapshots
11/24/2014 9:29:31 PM CleanupWeeklySnapshots : System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.
at System.Management.Automation.ParameterBinderBase.CoerceTypeAsNeeded(CommandParameterInternal argument, String parameterName, Type toType, ParameterCollectionTypeInformation collectionTypeInfo, Object currentValue)
11/24/2014 9:29:31 PM WriteToLog : System.NotSupportedException: Specified method is not supported.

The last error repeats for probably 300 times then stops.

Any assistance would be appreciated.

Thanks,
Jason

@noahlh
Copy link
Owner

noahlh commented Nov 25, 2014

Interesting. Off the top of my head, I'm not sure what's causing that, but a few guesses / things to check:

  • Can you confirm that you have the latest SDK installed?
  • What OS and version are you using (2012 R2?)
  • Is this being run by an Administrator?

@MTatersKT738
Copy link
Author

I updated to the most recent version that I downloaded today. I am running 2012 R2 and I ran it as administrator and still got the error above.

Any other thoughts? It seems to be trying to delete and run through loop based on an array that is empty?

Thanks,
Jason

@MTatersKT738
Copy link
Author

I performed additional troubleshooting and found where the error was. The script checks the description field of all snapshots for the string "Daily" or "Weekly". If the account has snapshots which do not have a description, the script will fail with the Null value exception. I would suggest building into the script a check for the NULL value in the description field and just ignore this snapshot.

@noahlh
Copy link
Owner

noahlh commented Dec 7, 2014

Excellent suggestion Jason - thank you! Want to take a stab at adding & testing this and submitting as a pull request? I'll happily guide you through that process if you'd like.

@MTatersKT738
Copy link
Author

I will try to put this on the schedule to look at eventually but I can not commit to anything near term, due to the large number of projects and ongoing deadlines. I will reach out when I have a chance and need assistance. Talk to you soon.

@noahlh
Copy link
Owner

noahlh commented Dec 8, 2014

No rush or obligation Jason - just if you have the time/interest. Many thanks!

@wgknowles
Copy link

Figured it out. Don't know how to submit code though...
First off... The catch [exception] for function CleanupDailySnapshots says $function = "CleanupWeeklySnapshots"
So that's misleading as heck!

then the fix:

function CleanupDailySnapshots
{
try
{
WriteToLog "Cleaning up daily snapshots"
$deleteCount = 0
$snapshots = GetAllSnapshots
foreach($snapshot in $snapshots)
{
$description = $snapshot.Description
$snapshotID = $snapshot.SnapshotId
if ($description -eq $null)
{
WriteToLog "$snapshot.SnapshotId has a null Description"
$description = "null"
}
elseif($snapshot.Description.Contains("Daily"))
{
WriteToLog "checking if '$description' ($snapshotID) is expired"
$backupDateTime = get-date $snapshot.StartTime
$expired = IsDailySnapshotExpired $backupDateTime
if($expired)
{
WriteToLog "$description ($snapshotID) Expired"
DeleteSnapshot $snapshot.SnapshotId
$deleteCount ++
}
}
}
#WriteToLog "Total of $deleteCount daily snapshots deleted"
}
catch [Exception]
{
$function = "CleanupDailySnapshots"
$exception = $_.Exception.ToString()
WriteToLogAndEmail "$function : $exception" -isException $true
return false
}
}

@wgknowles
Copy link

Note, you porobably need to fix this in function CleanupWeeklySnapshots as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants