Bacula-users

Re: [Bacula-users] SQL-Query for copy job to get latest full + all following differentials & incrementals...

2013-02-13 14:11:28
Subject: Re: [Bacula-users] SQL-Query for copy job to get latest full + all following differentials & incrementals...
From: "Masopust, Christian" <christian.masopust AT siemens DOT com>
To: "Masopust, Christian" <christian.masopust AT siemens DOT com>, bacula-users <bacula-users AT lists.sourceforge DOT net>
Date: Wed, 13 Feb 2013 20:08:34 +0100
> Hi Uwe,
> 
> thanks for reminding me about the query.sql :)  Starting from 
> there I found
> now a way to create a query that includes the most recent 
> full, the latest 
> differential and all incrementals since the latest 
> differentials (see below).
> 
> It is definitly working here for me and I'm glad to share it, 
> but.... I'm 
> absolutely sure that there MUST be a better (more nifty) way 
> to get the same result :)

all right.... too less testing, the below query works only when there's
only 1 full backup.  see my modified query that now should (no more "definitly" 
:)
work.

 
> Thanks,
> Christian
> 
> P.S.: here's the query:
> 
> :List all Jobs needed for a disaster recovery for a given jobname:
> *Enter Job name:
> SELECT DISTINCT Job.JobId,StartTime
>   FROM Job WHERE Job.Name = '%1' AND (
>   (Level='F' AND JobStatus IN ('T', 'W')) OR
>   (Level='D' AND JobStatus IN ('T', 'W') AND
>     Job.StartTime >= (
>       SELECT DISTINCT StartTime
>       FROM Job
>       WHERE Job.Name = '%1'
>       AND Level='F' AND JobStatus IN ('T', 'W')
>     )
>   ) OR
>   (Level='I' AND JobStatus IN ('T', 'W') AND
>     Job.StartTime >= (
>       SELECT DISTINCT StartTime
>       FROM Job
>       WHERE Job.Name = '%1'
>       AND Level='D' AND JobStatus IN ('T', 'W') AND
>       Job.StartTime >= (
>         SELECT DISTINCT StartTime
>         FROM Job
>         WHERE Job.Name = '%1'
>         AND Level='F' AND JobStatus IN ('T', 'W')
>       )
>     )
>   )
> );

:List all Jobs needed for a disaster recovery for a jobname:
*Enter Job name:
SELECT DISTINCT Job.JobId,StartTime FROM Job  WHERE Job.Name = '%1' AND (
  (Level='F' AND JobStatus IN ('T', 'W') AND
    Job.StartTime >= (
      SELECT DISTINCT StartTime
      FROM Job
      WHERE Job.Name = '%1'
      AND Level='F' AND JobStatus IN ('T', 'W') ORDER BY StartTime DESC LIMIT 1
    )
  ) OR
  (Level='D' AND JobStatus IN ('T', 'W') AND
    Job.StartTime >= (
      SELECT DISTINCT StartTime
      FROM Job
      WHERE Job.Name = '%1'
      AND Level='F' AND JobStatus IN ('T', 'W') ORDER BY StartTime DESC LIMIT 1
    )
  ) OR
  (Level='I' AND JobStatus IN ('T', 'W') AND
    Job.StartTime >= (
      SELECT DISTINCT StartTime
      FROM Job
      WHERE Job.Name = '%1'
      AND Level='D' AND JobStatus IN ('T', 'W') AND
      Job.StartTime >= (
        SELECT DISTINCT StartTime
        FROM Job
        WHERE Job.Name = '%1'
        AND Level='F' AND JobStatus IN ('T', 'W') ORDER BY StartTime DESC LIMIT 
1
      )
    ORDER BY StartTime DESC LIMIT 1 )
  )
) ORDER BY JobId;

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users