]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bbatch.c
Tweak fix MySQL quoting again :-(
[bacula/bacula] / bacula / src / tools / bbatch.c
index aa3a328bd781ed1da26fe49d096b4ba49c800de4..c7d5cab5576a3dd15ee47113866f3bed8c92cb46 100644 (file)
@@ -15,7 +15,7 @@
    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.
 
    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.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -87,6 +87,7 @@ PROG_COPYRIGHT
 "       -P <password      specify database password (default none)\n"
 "       -h <host>         specify database host (default NULL)\n"
 "       -w <working>      specify working directory\n"
+"       -r <jobids>       call restore code with given jobids\n"
 "       -v                verbose\n"
 "       -f <file>         specify data file\n"
 "       -?                print this message\n\n"), 2001, VERSION, BDATE);
@@ -96,13 +97,22 @@ PROG_COPYRIGHT
 /* number of thread started */
 int nb=0;
 
+static int list_handler(void *ctx, int num_fields, char **row)
+{
+   uint64_t *a = (uint64_t*) ctx;
+   (*a)++;
+   return 0;
+}
+
 int main (int argc, char *argv[])
 {
    int ch;
+   char *restore_list=NULL;
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
    init_stack_dump();
+   lmgr_init_thread();
    
    char **files = (char **) malloc (10 * sizeof(char *));
    int i;
@@ -111,8 +121,12 @@ int main (int argc, char *argv[])
 
    OSDependentInit();
 
-   while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
+   while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:r:?")) != -1) {
       switch (ch) {
+      case 'r':
+         restore_list=bstrdup(optarg);
+         break;
+
       case 'd':                    /* debug level */
          if (*optarg == 't') {
             dbg_timestamp = true;
@@ -149,9 +163,9 @@ int main (int argc, char *argv[])
          break;
 
       case 'f':
-        if (nb < 10 ) {
-           files[nb++] = optarg;
-        }
+         if (nb < 10 ) {
+            files[nb++] = optarg;
+         }
          break;
 
       case '?':
@@ -168,6 +182,30 @@ int main (int argc, char *argv[])
       usage();
    }
 
+   if (restore_list) {
+      uint64_t nb_file=0;
+      btime_t start, end;
+      /* To use the -r option, the catalog should already contains records */
+      
+      if ((db=db_init(NULL, NULL, db_name, db_user, db_password,
+                      db_host, 0, NULL, 0)) == NULL) {
+         Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
+      }
+      if (!db_open_database(NULL, db)) {
+         Emsg0(M_ERROR_TERM, 0, db_strerror(db));
+      }
+
+      start = get_current_btime();
+      db_get_file_list(NULL, db, restore_list, list_handler, &nb_file);
+      end = get_current_btime();
+
+      Pmsg3(0, _("Computing file list for jobid=%s files=%lld secs=%d\n"), 
+            restore_list, nb_file, (uint32_t)btime_to_unix(end-start));
+      
+      free(restore_list);
+      return 0;
+   }
+
 #ifdef HAVE_BATCH_FILE_INSERT
    printf("With new Batch mode\n");
 #else
@@ -183,8 +221,8 @@ int main (int argc, char *argv[])
       bjcr->NumReadVolumes = 0;
       bjcr->NumWriteVolumes = 0;
       bjcr->JobId = getpid();
-      bjcr->JobType = JT_CONSOLE;
-      bjcr->JobLevel = L_FULL;
+      bjcr->set_JobType(JT_CONSOLE);
+      bjcr->set_JobLevel(L_FULL);
       bjcr->JobStatus = JS_Running;
       bjcr->where = bstrdup(files[i]);
       bjcr->job_name = get_pool_memory(PM_FNAME);
@@ -197,16 +235,16 @@ int main (int argc, char *argv[])
       bjcr->fileset_md5 = get_pool_memory(PM_FNAME);
       pm_strcpy(bjcr->fileset_md5, "Dummy.fileset.md5");
       
-      if ((db=db_init_database(NULL, db_name, db_user, db_password,
-                              db_host, 0, NULL, 0)) == NULL) {
-        Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
+      if ((db=db_init(NULL, NULL, db_name, db_user, db_password,
+                      db_host, 0, NULL, 0)) == NULL) {
+         Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
       }
       if (!db_open_database(NULL, db)) {
-        Emsg0(M_ERROR_TERM, 0, db_strerror(db));
+         Emsg0(M_ERROR_TERM, 0, db_strerror(db));
       }
       Dmsg0(200, "Database opened\n");
       if (verbose) {
-        Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
+         Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
       }
       
       bjcr->db = db;
@@ -231,23 +269,23 @@ static void fill_attr(ATTR_DBR *ar, char *data)
 
    for(p = b = data; *p; p++) {
       if (*p == ';') {
-        *p = '\0';
-        switch (index) {
-        case 0:
-           ar->FileIndex = str_to_int64(b);
-           break;
-        case 1:
-           ar->fname = b;
-           break;
-        case 2:
-           ar->attr = b;
-           break;
-        case 3:
-           ar->Digest = b;
-           break;
-        }
-        index++;
-        b = ++p;
+         *p = '\0';
+         switch (index) {
+         case 0:
+            ar->FileIndex = str_to_int64(b);
+            break;
+         case 1:
+            ar->fname = b;
+            break;
+         case 2:
+            ar->attr = b;
+            break;
+         case 3:
+            ar->Digest = b;
+            break;
+         }
+         index++;
+         b = ++p;
       }
    }
 }
@@ -270,11 +308,11 @@ static void *do_batch(void *jcr)
       strip_trailing_newline(data);
       lineno++;
       if (verbose && ((lineno % 5000) == 1)) {
-        printf("\r%i", lineno);
+         printf("\r%i", lineno);
       }
       fill_attr(&ar, data);
       if (!db_create_file_attributes_record(bjcr, bjcr->db, &ar)) {
-        Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n"));
+         Emsg0(M_ERROR_TERM, 0, _("Error while inserting file\n"));
       }
    }
    fclose(fd);
@@ -284,9 +322,9 @@ static void *do_batch(void *jcr)
    P(mutex);
    char ed1[200], ed2[200];
    printf("\rbegin = %s, end = %s\n", edit_int64(begin, ed1),edit_int64(end, ed2));
-   printf("Insert time = %llims\n", (end - begin) / 10000);
+   printf("Insert time = %sms\n", edit_int64((end - begin) / 10000, ed1));
    printf("Create %u files at %.2f/s\n", lineno, 
-         (lineno / ((float)((end - begin) / 1000000))));
+          (lineno / ((float)((end - begin) / 1000000))));
    nb--;
    V(mutex);
    pthread_exit(NULL);