Forum Discussion

mikg23's avatar
mikg23
Level 2
8 years ago

Opscenter custom script help !

Oh powerful SQL query experts, please help me with my conumdrum...

I have written the following query to produce a list of current NBU clients hand how much data is protected in a given month by week including the number of jobs ran of a given schedule. When i run the script though the data is grossly larger then actuals ... what am i doing wrong?

SELECT
domain_MasterServer.friendlyName as "Master Server",
domain_JobArchive.clientName as "Client Name",
lookup_PolicyType.name as "Policy Type" ,
domain_JobArchive.scheduleName as "Schedule",
coalesce(CAST(SUM(domain_JobArchive.preSISSize)/1024/1024/1024 AS NUMERIC (20,0)),0) AS "GB",
(count(distinct domain_JobArchive.parentJobId)) as "Jobs Ran",

DATEDIFF(WEEK, UTCBigIntToNomTime(domain_JobArchive.endTime), GETDATE()) as "Week#"

FROM
domain_JobArchive , domain_Policy, lookup_PolicyType, domain_MasterServer

WHERE
domain_JobArchive.clientName LIKE 'client1'
AND DATEDIFF(month,UTCBigIntToNomTime(domain_JobArchive.endTime), GETDATE()) <= 1
AND domain_Policy.type= lookup_PolicyType.id
AND domain_JobArchive.masterServerId = domain_MasterServer.id
AND domain_Policy.type = domain_JobArchive.policyType
AND domain_JobArchive.scheduleName != 'unknown'
AND domain_JobArchive.scheduleName != ' '
AND domain_Policy.policyDomainName = domain_JobArchive.policyDomainName
AND domain_Policy.versionNo = domain_JobArchive.policyVersionNo
AND domain_JobArchive.statusCode IN (0,1)
AND domain_JobArchive.type IN (0)
AND domain_JobArchive.presissize !=32768

GROUP BY
"domain_JobArchive"."clientName","lookup_PolicyType"."name","scheduleName","friendlyName",(DATEDIFF(WEEK, UTCBigIntToNomTime(domain_JobArchive.endTime), GETDATE()))
ORDER BY
"domain_JobArchive"."clientName",(DATEDIFF(WEEK, UTCBigIntToNomTime(domain_JobArchive.endTime), GETDATE())),"lookup_PolicyType"."name","scheduleName"

------ output ---- (sanitized to protect the innocent)

 

Master Server,  Client Name,     Policy Type,   Schedule,    GB Written,      Jobs Ran,      Week#
Master1             client1               Standard        full,              30,414              1                    0
Master1             client1               Standard        incr              4,685                4                    0
Master1             client1               Standard        full               43,361               1                   1
Master1             client1               Standard        incr              7,709                 6                   1
Master1             client1               Standard        full               45,751               1                   2
Master1             client1               Standard        incr              8,555                 5                   2
Master1             client1               Standard        full               44,000               1                   3
Master1             client1               Standard        incr               7,641                5                   3
Master1             client1               Standard        incr               7,791                5                   4

 

Sizes expected to be ~ 15 TB for fulls and ~ 2.5 TB for the incs

6 Replies

  • Hello

    My advice would be to take one step back and run it with out this 

    coalesce(CAST(SUM(domain_JobArchive.preSISSize)/1024/1024/1024 AS NUMERIC (20,0)),0) AS "GB",
    (count(distinct domain_JobArchive.parentJobId)) as "Jobs Ran",

    First check if your results are correct before doing the sum or count. I sometimes find that this helps when you're grouping stuff together and you see it comes back with 2x or 3x.

     

    HTH

    • mikg23's avatar
      mikg23
      Level 2

      • Hi,

        Then I'm sure its adding it up more than it should. Being a non-dba with a google degree in sql, i've had a few instances where i ran into issues like this :)

        hope you figure it out!

  • In your first query you included the master server name but did not group by it.

    • mikg23's avatar
      mikg23
      Level 2

      "friendlyName" is for the master and called out right before the time variable in the group by.