]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/dbcheck.c
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / tools / dbcheck.c
index 2c13325892e94118b99ca17c6b6c00237e0f5584..6ed8a7c3e0b44ca82e2fb65356997a5aab63c308 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2009 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
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -109,17 +109,18 @@ static int check_idx_handler(void *ctx, int num_fields, char **row);
 /* Global variables */
 static const char *idx_tmp_name;
 
-
 static void usage()
 {
    fprintf(stderr,
-"Usage: dbcheck [-c config] [-C catalog name] [-d debug_level] <working-directory> <bacula-database> <user> <password> [<dbhost>] [<dbport>]\n"
+"Usage: dbcheck [-c config ] [-B] [-C catalog name] [-d debug_level] <working-directory> <bacula-database> <user> <password> [<dbhost>] [<dbport>]\n"
 "       -b              batch mode\n"
 "       -C              catalog name in the director conf file\n"
 "       -c              Director conf filename\n"
+"       -B              print catalog configuration and exit\n"
 "       -d <nn>         set debug level to <nn>\n"
-"       -dt             print timestamp in debug output\n"
+"       -dt             print timestamp in debug output\n"
 "       -f              fix inconsistencies\n"
+"       -t              test if client library is thread-safe\n"
 "       -v              verbose\n"
 "       -?              print this message\n\n");
    exit(1);
@@ -130,6 +131,8 @@ int main (int argc, char *argv[])
    int ch;
    const char *user, *password, *db_name, *dbhost;
    int dbport = 0;
+   bool test_thread=false;
+   bool print_catalog=false;
    char *configfile = NULL;
    char *catalogname = NULL;
    char *endptr;
@@ -137,6 +140,7 @@ int main (int argc, char *argv[])
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
+   lmgr_init_thread();
 
    my_name_is(argc, argv, "dbcheck");
    init_msg(NULL, NULL);              /* setup message handler */
@@ -144,8 +148,12 @@ int main (int argc, char *argv[])
    memset(&id_list, 0, sizeof(id_list));
    memset(&name_list, 0, sizeof(name_list));
 
-   while ((ch = getopt(argc, argv, "bc:C:d:fv?")) != -1) {
+   while ((ch = getopt(argc, argv, "bc:C:d:fvBt?")) != -1) {
       switch (ch) {
+      case 'B':
+         print_catalog = true;     /* get catalog information from config */
+         break;
+
       case 'b':                    /* batch */
          batch = true;
          break;
@@ -176,6 +184,9 @@ int main (int argc, char *argv[])
       case 'v':
          verbose++;
          break;
+      case 't':
+         test_thread=true;
+         break;
 
       case '?':
       default:
@@ -187,6 +198,16 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
+   if (test_thread) {
+      /* When we will load the SQL backend with ldopen, this check would be
+       * moved after the database initialization. It will need a valid config
+       * file.
+       */
+      db_check_backend_thread_safe();
+      Pmsg0(0, _("OK - DB backend seems to be thread-safe.\n"));
+      exit(0);
+   }
+
    if (configfile) {
       CAT *catalog = NULL;
       int found = 0;
@@ -223,6 +244,16 @@ int main (int argc, char *argv[])
             exit(1);
          }
          set_working_directory(director->working_directory);
+
+         /* Print catalog information and exit (-B) */
+         if (print_catalog) {
+            POOLMEM *buf = get_pool_memory(PM_MESSAGE);
+            printf("%sdb_type=%s\nworking_dir=%s\n", catalog->display(buf),
+                   db_get_type(), working_directory);
+            free_pool_memory(buf);
+            exit(0);
+         }
+
          db_name = catalog->db_name;
          user = catalog->db_user;
          password = catalog->db_password;
@@ -310,6 +341,7 @@ int main (int argc, char *argv[])
    db_close_database(NULL, db);
    close_msg(NULL);
    term_msg();
+   lmgr_cleanup_main();
    return 0;
 }
 
@@ -327,7 +359,7 @@ static void do_interactive_mode()
    else
       printf(_(" Verbose is off.\n"));
 
-   printf(_("Please select the fuction you want to perform.\n"));
+   printf(_("Please select the function you want to perform.\n"));
 
    while (!quit) {
       if (fix) {
@@ -1328,7 +1360,7 @@ static bool check_idx(const char *col_name)
    int found = false;
 
    memset(&idx_list, 0, sizeof(idx_list));
-   char *query = "SHOW INDEX FROM File";
+   const char *query = "SHOW INDEX FROM File";
    if (!db_sql_query(db, query, check_idx_handler, (void *)col_name)) {
       printf("%s\n", db_strerror(db));
    }