]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/dbcheck.c
ebl Add program to validate TCDBM lib with accurate mode
[bacula/bacula] / bacula / src / tools / dbcheck.c
index 4e5eee8aabbf7133e8bbe443f480aea9fd551992..07a501e4f7cb944c7635afbfd4c86cfb775c67af 100644 (file)
@@ -1,13 +1,3 @@
-/*
- *
- *  Program to check a Bacula database for consistency and to
- *   make repairs
- *
- *   Kern E. Sibbald, August 2002
- *
- *   Version $Id$
- *
- */
 /*
    Bacula® - The Network Backup Solution
 
@@ -17,8 +7,8 @@
    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.
 */
+/*
+ *
+ *  Program to check a Bacula database for consistency and to
+ *   make repairs
+ *
+ *   Kern E. Sibbald, August 2002
+ *
+ *   Version $Id$
+ *
+ */
 
 #include "bacula.h"
 #include "cats/cats.h"
@@ -105,7 +105,8 @@ static void usage()
 "       -b              batch mode\n"
 "       -C              catalog name in the director conf file\n"
 "       -c              director conf filename\n"
-"       -dnn            set debug level to nn\n"
+"       -d <nn>         set debug level to <nn>\n"
+"       -dt             print timestamp in debug output\n"
 "       -f              fix inconsistencies\n"
 "       -v              verbose\n"
 "       -?              print this message\n\n");
@@ -145,9 +146,14 @@ int main (int argc, char *argv[])
          break;
 
       case 'd':                    /* debug level */
-         debug_level = atoi(optarg);
-         if (debug_level <= 0)
-            debug_level = 1;
+         if (*optarg == 't') {
+            dbg_timestamp = true;
+         } else {
+            debug_level = atoi(optarg);
+            if (debug_level <= 0) {
+               debug_level = 1;
+            }
+         }
          break;
 
       case 'f':                    /* fix inconsistencies */
@@ -611,7 +617,7 @@ static void eliminate_duplicate_filenames()
       /* Loop through list of duplicate names */
       for (int i=0; i<name_list.num_ids; i++) {
          /* Get all the Ids of each name */
-         db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
+         db_escape_string(NULL, db, esc_name, name_list.name[i], strlen(name_list.name[i]));
          bsnprintf(buf, sizeof(buf), "SELECT FilenameId FROM Filename WHERE Name='%s'", esc_name);
          if (verbose > 1) {
             printf("%s\n", buf);
@@ -669,7 +675,7 @@ static void eliminate_duplicate_paths()
       /* Loop through list of duplicate names */
       for (int i=0; i<name_list.num_ids; i++) {
          /* Get all the Ids of each name */
-         db_escape_string(esc_name, name_list.name[i], strlen(name_list.name[i]));
+         db_escape_string(NULL, db, esc_name, name_list.name[i], strlen(name_list.name[i]));
          bsnprintf(buf, sizeof(buf), "SELECT PathId FROM Path WHERE Path='%s'", esc_name);
          if (verbose > 1) {
             printf("%s\n", buf);
@@ -732,6 +738,8 @@ static void eliminate_orphaned_jobmedia_records()
       if (fix && id_list.num_ids > 0) {
          printf(_("Deleting %d orphaned JobMedia records.\n"), id_list.num_ids);
          delete_id_list("DELETE FROM JobMedia WHERE JobMediaId=%s", &id_list);
+      } else {
+         break;                       /* get out if not updating db */
       }
       if (!make_id_list(query, &id_list)) {
          exit(1);
@@ -773,6 +781,8 @@ static void eliminate_orphaned_file_records()
       if (fix && id_list.num_ids > 0) {
          printf(_("Deleting %d orphaned File records.\n"), id_list.num_ids);
          delete_id_list("DELETE FROM File WHERE FileId=%s", &id_list);
+      } else {
+         break;                       /* get out if not updating db */
       }
       if (!make_id_list(query, &id_list)) {
          exit(1);
@@ -810,6 +820,8 @@ static void eliminate_orphaned_path_records()
       if (fix && id_list.num_ids > 0) {
          printf(_("Deleting %d orphaned Path records.\n"), id_list.num_ids);
          delete_id_list("DELETE FROM Path WHERE PathId=%s", &id_list);
+      } else {
+         break;                       /* get out if not updating db */
       }
       if (!make_id_list(query, &id_list)) {
          exit(1);
@@ -847,6 +859,8 @@ static void eliminate_orphaned_filename_records()
       if (fix && id_list.num_ids > 0) {
          printf(_("Deleting %d orphaned Filename records.\n"), id_list.num_ids);
          delete_id_list("DELETE FROM Filename WHERE FilenameId=%s", &id_list);
+      } else {
+         break;                       /* get out if not updating db */
       }
       if (!make_id_list(query, &id_list)) {
          exit(1);
@@ -1095,7 +1109,7 @@ static void repair_bad_filenames()
             esc_name[1] = 0;
          } else {
             name[len-1] = 0;
-            db_escape_string(esc_name, name, len);
+            db_escape_string(NULL, db, esc_name, name, len);
          }
          bsnprintf(buf, sizeof(buf),
             "UPDATE Filename SET Name='%s' WHERE FilenameId=%s",
@@ -1154,7 +1168,7 @@ static void repair_bad_paths()
          }
          /* Add trailing slash */
          len = pm_strcat(&name, "/");
-         db_escape_string(esc_name, name, len);
+         db_escape_string(NULL, db, esc_name, name, len);
          bsnprintf(buf, sizeof(buf), "UPDATE Path SET Path='%s' WHERE PathId=%s",
             esc_name, edit_int64(id_list.Id[i], ed1));
          if (verbose > 1) {