]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/sql_update.c
ebl Modify disk-changer to check if slot contains something before
[bacula/bacula] / bacula / src / cats / sql_update.c
index c4174369eb08296b5586975e95fe01079917be4a..fa605998f7c20e5d08bb62f90f7252c177e93b5a 100644 (file)
@@ -1,21 +1,14 @@
-/*
- * Bacula Catalog Database Update record interface routines
- *
- *    Kern Sibbald, March 2000
- *
- *    Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ * Bacula Catalog Database Update record interface routines
+ *
+ *    Kern Sibbald, March 2000
+ *
+ *    Version $Id$
+ */
 
 /* The following is necessary so that we do not include
  * the dummy external definition of DB.
@@ -41,7 +41,7 @@
 #include "bacula.h"
 #include "cats.h"
 
-#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL
+#if    HAVE_SQLITE3 || HAVE_MYSQL || HAVE_SQLITE || HAVE_POSTGRESQL || HAVE_DBI
 
 /* -----------------------------------------------------------------------
  *
@@ -142,7 +142,7 @@ static void edit_num_or_null(char *s, size_t n, uint64_t id) {
  *           1 on success
  */
 int
-db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
+db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, bool stats_enabled)
 {
    char dt[MAX_TIME_LENGTH];
    char rdt[MAX_TIME_LENGTH];
@@ -192,11 +192,17 @@ db_update_job_end_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr)
       edit_int64(jr->JobId, ed3));
 
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
+
+   if (stat && stats_enabled) {
+      Mmsg(mdb->cmd,
+          "INSERT INTO JobStat (SELECT * FROM Job WHERE JobId=%s)",
+          edit_int64(jr->JobId, ed3));
+      INSERT_DB(jcr, mdb, mdb->cmd); /* TODO: get a message ? */
+   }
    db_unlock(mdb);
    return stat;
 }
 
-
 /*
  * Update Client record
  *   Returns: 0 on failure
@@ -251,11 +257,10 @@ int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
 }
 
 
-int
-db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
+int db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 {
    int stat;
-   char ed1[50], ed2[50], ed3[50], ed4[50];
+   char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50];
 
    db_lock(mdb);
    Mmsg(mdb->cmd, "SELECT count(*) from Media WHERE PoolId=%s",
@@ -267,14 +272,14 @@ db_update_pool_record(JCR *jcr, B_DB *mdb, POOL_DBR *pr)
 "UPDATE Pool SET NumVols=%u,MaxVols=%u,UseOnce=%d,UseCatalog=%d,"
 "AcceptAnyVolume=%d,VolRetention='%s',VolUseDuration='%s',"
 "MaxVolJobs=%u,MaxVolFiles=%u,MaxVolBytes=%s,Recycle=%d,"
-"AutoPrune=%d,LabelType=%d,LabelFormat='%s' WHERE PoolId=%s",
+"AutoPrune=%d,LabelType=%d,LabelFormat='%s',RecyclePoolId=%s WHERE PoolId=%s",
       pr->NumVols, pr->MaxVols, pr->UseOnce, pr->UseCatalog,
       pr->AcceptAnyVolume, edit_uint64(pr->VolRetention, ed1),
       edit_uint64(pr->VolUseDuration, ed2),
       pr->MaxVolJobs, pr->MaxVolFiles,
       edit_uint64(pr->MaxVolBytes, ed3),
       pr->Recycle, pr->AutoPrune, pr->LabelType,
-      pr->LabelFormat, 
+      pr->LabelFormat, edit_int64(pr->RecyclePoolId,ed5),
       ed4);
 
    stat = UPDATE_DB(jcr, mdb, mdb->cmd);
@@ -351,6 +356,14 @@ db_update_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
       UPDATE_DB(jcr, mdb, mdb->cmd);
    }
 
+   /* sanity checks for #1066 */
+   if (mr->VolReadTime < 0) {
+      mr->VolReadTime = 0;
+   }
+   if (mr->VolWriteTime < 0) {
+      mr->VolWriteTime = 0;
+   }
+
    Mmsg(mdb->cmd, "UPDATE Media SET VolJobs=%u,"
         "VolFiles=%u,VolBlocks=%u,VolBytes=%s,VolMounts=%u,VolErrors=%u,"
         "VolWrites=%u,MaxVolBytes=%s,VolStatus='%s',"