If statment multiple conditions

This topic contains 2 replies, has 2 voices, and was last updated by  Jonas Dahlgren 4 weeks ago.

  • Author
    Posts
  • #80429

    Jonas Dahlgren
    Participant

    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
    	}
    
  • #80447

    Max Kozlov
    Participant

    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)
    
    • #80470

      Jonas Dahlgren
      Participant

      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)

You must be logged in to reply to this topic.