]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add -n option to dbcheck to adjust the number of changes done
authorEric Bollengier <eric@baculasystems.com>
Tue, 29 Sep 2020 14:03:28 +0000 (16:03 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:57 +0000 (09:02 +0100)
bacula/src/cats/mysql.c
bacula/src/cats/postgresql.c
bacula/src/cats/sqlite.c
bacula/src/tools/dbcheck.c

index 67444efcb1972903ad8d6be3c11ec60a5f61ff07..ee593403ca7709aef37e4ba1b4462f981d9e827d 100644 (file)
@@ -476,14 +476,16 @@ void BDB_MYSQL::bdb_unescape_object(JCR *jcr, char *from, int32_t expected_len,
 } 
  
 void BDB_MYSQL::bdb_start_transaction(JCR *jcr) 
-{ 
-   if (!jcr->attr) { 
-      jcr->attr = get_pool_memory(PM_FNAME); 
-   } 
-   if (!jcr->ar) { 
-      jcr->ar = (ATTR_DBR *)malloc(sizeof(ATTR_DBR)); 
-      memset(jcr->ar, 0, sizeof(ATTR_DBR));
-   } 
+{
+   if (jcr) {
+      if (!jcr->attr) {
+         jcr->attr = get_pool_memory(PM_FNAME);
+      }
+      if (!jcr->ar) {
+         jcr->ar = (ATTR_DBR *)malloc(sizeof(ATTR_DBR));
+         memset(jcr->ar, 0, sizeof(ATTR_DBR));
+      }
+   }
 } 
  
 void BDB_MYSQL::bdb_end_transaction(JCR *jcr) 
index a73dbf9fb0870280084c8bcf9e9759b4a9034136..cf6e254c8d334ed52074de181e5bc8598662d429 100644 (file)
@@ -517,12 +517,13 @@ void BDB_POSTGRESQL::bdb_start_transaction(JCR *jcr)
 {
    BDB_POSTGRESQL *mdb = this;
 
-   if (!jcr->attr) { 
-      jcr->attr = get_pool_memory(PM_FNAME); 
-   }
-   if (!jcr->ar) { 
-      jcr->ar = (ATTR_DBR *)malloc(sizeof(ATTR_DBR));
-      memset(jcr->ar, 0, sizeof(ATTR_DBR));
+   if (jcr) {
+      if (!jcr->attr) { 
+         jcr->attr = get_pool_memory(PM_FNAME); 
+      }
+      if (!jcr->ar) { 
+         jcr->ar = (ATTR_DBR *)bmalloc(sizeof(ATTR_DBR));
+      }
    }
 
    /* 
index 5c7540cacc9f4b432d066fd92f5b102fe3c20dcc..d7718606e9894531fd921608ab86a179764e549e 100644 (file)
@@ -390,14 +390,16 @@ void BDB_SQLITE::bdb_unescape_object(JCR *jcr, char *from, int32_t expected_len,
 void BDB_SQLITE::bdb_start_transaction(JCR *jcr) 
 {  
    BDB_SQLITE *mdb = this; 
-   if (!jcr->attr) { 
-      jcr->attr = get_pool_memory(PM_FNAME); 
-   } 
-   if (!jcr->ar) { 
-      jcr->ar = (ATTR_DBR *)malloc(sizeof(ATTR_DBR));
-      memset(jcr->ar, 0, sizeof(ATTR_DBR));
-   } 
+
+   if (jcr) {
+      if (!jcr->attr) {
+      jcr->attr = get_pool_memory(PM_FNAME);
+      }
+      if (!jcr->ar) {
+         jcr->ar = (ATTR_DBR *)malloc(sizeof(ATTR_DBR));
+         memset(jcr->ar, 0, sizeof(ATTR_DBR));
+      }
+   }
  
    if (!mdb->m_allow_transactions) { 
       return; 
index 1257adbedc1ddea5d0bca0da2865d335a371f3bc..00f7690823c6d961dd126b84bc7000f8ccd8fb4f 100644 (file)
@@ -58,7 +58,8 @@ static NAME_LIST name_list;
 static char buf[20000];
 static bool quit = false;
 static CONFIG *config;
-static const char *idx_tmp_name; 
+static const char *idx_tmp_name;
+static uint64_t nb_changes = 300000;
 
 #define MAX_ID_LIST_LEN 10000000
 
@@ -102,6 +103,7 @@ PROG_COPYRIGHT
 "       -c              Director conf filename\n"
 "       -B              print catalog configuration and exit\n"
 "       -d <nn>         set debug level to <nn>\n"
+"       -n <nn>         maximum number of changes\n"
 "       -dt             print a timestamp in debug output\n"
 "       -f              fix inconsistencies\n"
 "       -v              verbose\n"
@@ -134,8 +136,11 @@ 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:fvB?")) != -1) { 
+   while ((ch = getopt(argc, argv, "bc:C:d:fvB?n:")) != -1) { 
       switch (ch) {
+      case 'n':                    /* Number of changes we can make in one run */
+         nb_changes = str_to_uint64(optarg);
+         break;
       case 'B':
          print_catalog = true;     /* get catalog information from config */
          break;
@@ -606,6 +611,7 @@ static int make_id_list(const char *query, ID_LIST *id_list)
 static int delete_id_list(const char *query, ID_LIST *id_list)
 {
    char ed1[50];
+   db_start_transaction(NULL, db);
    for (int i=0; i < id_list->num_ids; i++) {
       bsnprintf(buf, sizeof(buf), query, edit_int64(id_list->Id[i], ed1));
       if (verbose) {
@@ -613,6 +619,7 @@ static int delete_id_list(const char *query, ID_LIST *id_list)
       }
       db_sql_query(db, buf, NULL, NULL);
    }
+   db_end_transaction(NULL, db);
    return 1;
 }
 
@@ -791,12 +798,14 @@ static void eliminate_duplicate_paths()
 
 static void eliminate_orphaned_jobmedia_records()
 {
-   const char *query = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
+   POOL_MEM query;
+   const char *q = "SELECT JobMedia.JobMediaId,Job.JobId FROM JobMedia "
                 "LEFT OUTER JOIN Job ON (JobMedia.JobId=Job.JobId) "
-                "WHERE Job.JobId IS NULL LIMIT 300000";
+                "WHERE Job.JobId IS NULL LIMIT %llu";
+   Mmsg(query, q, nb_changes);
 
    printf(_("Checking for orphaned JobMedia entries.\n"));
-   if (!make_id_list(query, &id_list)) {
+   if (!make_id_list(query.c_str(), &id_list)) {
       exit(1);
    }
    /* Loop doing 300000 at a time */
@@ -824,7 +833,7 @@ static void eliminate_orphaned_jobmedia_records()
       } else {
          break;                       /* get out if not updating db */
       }
-      if (!make_id_list(query, &id_list)) {
+      if (!make_id_list(query.c_str(), &id_list)) {
          exit(1);
       }
    }
@@ -832,15 +841,17 @@ static void eliminate_orphaned_jobmedia_records()
 
 static void eliminate_orphaned_file_records()
 {
-   const char *query = "SELECT File.FileId,Job.JobId FROM File "
+   POOL_MEM query;
+   const char *q = "SELECT File.FileId,Job.JobId FROM File "
                 "LEFT OUTER JOIN Job ON (File.JobId=Job.JobId) "
-               "WHERE Job.JobId IS NULL LIMIT 300000";
+               "WHERE Job.JobId IS NULL LIMIT %llu";
+   Mmsg(query, q, nb_changes);
 
    printf(_("Checking for orphaned File entries. This may take some time!\n"));
    if (verbose > 1) {
-      printf("%s\n", query);
+      printf("%s\n", query.c_str());
    }
-   if (!make_id_list(query, &id_list)) {
+   if (!make_id_list(query.c_str(), &id_list)) {
       exit(1);
    }
    /* Loop doing 300000 at a time */
@@ -867,7 +878,7 @@ static void eliminate_orphaned_file_records()
       } else {
          break;                       /* get out if not updating db */
       }
-      if (!make_id_list(query, &id_list)) {
+      if (!make_id_list(query.c_str(), &id_list)) {
          exit(1);
       }
    }
@@ -898,15 +909,17 @@ static void eliminate_orphaned_path_records()
       }
    }
 
-   const char *query = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
+   POOL_MEM query;
+   const char *q = "SELECT DISTINCT Path.PathId,File.PathId FROM Path "
                "LEFT OUTER JOIN File ON (Path.PathId=File.PathId) "
-               "WHERE File.PathId IS NULL LIMIT 300000";
+               "WHERE File.PathId IS NULL LIMIT %llu";
+   Mmsg(query, q, nb_changes);
 
    printf(_("Checking for orphaned Path entries. This may take some time!\n"));
    if (verbose > 1) {
-      printf("%s\n", query);
+      printf("%s\n", query.c_str());
    }
-   if (!make_id_list(query, &id_list)) {
+   if (!make_id_list(query.c_str(), &id_list)) {
       exit(1);
    }
    /* Loop doing 300000 at a time */
@@ -929,7 +942,7 @@ static void eliminate_orphaned_path_records()
       } else {
          break;                       /* get out if not updating db */
       }
-      if (!make_id_list(query, &id_list)) {
+      if (!make_id_list(query.c_str(), &id_list)) {
          exit(1);
       }
    }