Author Posts

September 25, 2017 at 6:15 am

Hi I am trying to make a script to monitor my SQL backups. Everything works fine except that we are running differential backups 6 days a week and a full backup once a week. I want to check that latest full back or latest diff backup max 28 hours old. This is my if statement so far. Can anyone point me in right direction how to get it work properly?

elseif (($recovery.recovery_model -eq 'SIMPLE') -and (($timediff.totalhours -lt "28") -or ($timefull.totalhours -lt "28")) -or $timefull.days -gt "7")
	{
		$db.name
		Write-Host "Diff "$timediff.totalhours
		Write-Host "Full "$timefull.totalhours
		$failed += $backups.database_name
	}

September 25, 2017 at 7:34 am

so what the problem ?
btw, you should use number values without quotes, it not strings

$timediff.totalhours -lt 28

you do not write, what contains in $timediff variable, it is difference between current time and time of backup or something another
if so, you need something like

($full.totaldays -gt 7 -and $full.hours -gt 28) -or ($diff.totalhours -gt 28)

September 25, 2017 at 9:04 am

Thanks for your input. Changed my statment to your suggestion and got expected result back.

($full.totaldays -gt 7 -and $full.hours -gt 28) -or ($diff.totalhours -gt 28)