]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/job.c
kes Implement build and install of bpipe-fd.so plugin.
[bacula/bacula] / bacula / src / filed / job.c
index 23921df0c86f3093efddedf71af28554352ba402..98f7318184d67991cae34f37bbc9204bec65d9a2 100644 (file)
@@ -20,7 +20,7 @@
    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.
@@ -49,6 +49,7 @@ extern CLIENT *me;                    /* our client resource */
 /* Imported functions */
 extern int status_cmd(JCR *jcr);
 extern int qstatus_cmd(JCR *jcr);
+extern int accurate_cmd(JCR *jcr);
 
 /* Forward referenced functions */
 static int backup_cmd(JCR *jcr);
@@ -106,6 +107,7 @@ static struct s_cmds cmds[] = {
    {"RunBeforeJob", runbefore_cmd, 0},
    {"RunAfterJob",  runafter_cmd,  0},
    {"Run",          runscript_cmd, 0},
+   {"accurate",     accurate_cmd,  0},
    {NULL,       NULL}                  /* list terminator */
 };
 
@@ -227,7 +229,7 @@ void *handle_client_request(void *dirp)
    for (quit=false; !quit;) {
 
       /* Read command */
-      if (bnet_recv(dir) < 0) {
+      if (dir->recv() < 0) {
          break;               /* connection terminated */
       }
       dir->msg[dir->msglen] = 0;
@@ -237,14 +239,14 @@ void *handle_client_request(void *dirp)
          if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
             found = true;         /* indicate command found */
             if (!jcr->authenticated && cmds[i].func != hello_cmd) {
-               bnet_fsend(dir, no_auth);
-               bnet_sig(dir, BNET_EOD);
+               dir->fsend(no_auth);
+               dir->signal(BNET_EOD);
                break;
             }
             if ((jcr->authenticated) && (!cmds[i].monitoraccess) && (jcr->director->monitor)) {
                Dmsg1(100, "Command \"%s\" is invalid.\n", cmds[i].cmd);
-               bnet_fsend(dir, invalid_cmd);
-               bnet_sig(dir, BNET_EOD);
+               dir->fsend(invalid_cmd);
+               dir->signal(BNET_EOD);
                break;
             }
             Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
@@ -256,7 +258,7 @@ void *handle_client_request(void *dirp)
          }
       }
       if (!found) {              /* command not found */
-         bnet_fsend(dir, errmsg);
+         dir->fsend(errmsg);
          quit = true;
          break;
       }
@@ -264,7 +266,7 @@ void *handle_client_request(void *dirp)
 
    /* Inform Storage daemon that we are done */
    if (jcr->store_bsock) {
-      bnet_sig(jcr->store_bsock, BNET_TERMINATE);
+      jcr->store_bsock->signal(BNET_TERMINATE);
    }
 
    /* Run the after job */
@@ -273,7 +275,7 @@ void *handle_client_request(void *dirp)
    if (jcr->JobId) {            /* send EndJob if running a job */
       char ed1[50], ed2[50];
       /* Send termination status back to Dir */
-      bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
+      dir->fsend(EndJob, jcr->JobStatus, jcr->JobFiles,
                  edit_uint64(jcr->ReadBytes, ed1),
                  edit_uint64(jcr->JobBytes, ed2), jcr->Errors, jcr->VSS,
                  jcr->crypto.pki_encrypt);
@@ -303,6 +305,12 @@ void *handle_client_request(void *dirp)
             for (k=0; k<fo->regex.size(); k++) {
                regfree((regex_t *)fo->regex.get(k));
             }
+            for (k=0; k<fo->regexdir.size(); k++) {
+               regfree((regex_t *)fo->regexdir.get(k));
+            }
+            for (k=0; k<fo->regexfile.size(); k++) {
+               regfree((regex_t *)fo->regexfile.get(k));
+            }
             fo->regex.destroy();
             fo->regexdir.destroy();
             fo->regexfile.destroy();
@@ -313,6 +321,9 @@ void *handle_client_request(void *dirp)
             fo->base.destroy();
             fo->fstype.destroy();
             fo->drivetype.destroy();
+            if (fo->ignoredir != NULL) {
+               free(fo->ignoredir);
+            }
          }
          incexe->opts_list.destroy();
          incexe->name_list.destroy();
@@ -672,7 +683,7 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese
       }
       break;
    case '<':
-      Dmsg0(100, "Doing < include on client.\n");
+      Dmsg1(100, "Doing < of '%s' include on client.\n", p + 1);
       p++;                      /* skip over < */
       if ((ffd = fopen(p, "rb")) == NULL) {
          berrno be;
@@ -738,7 +749,7 @@ static void add_fileset(JCR *jcr, const char *item)
     */
    if (subcode != ' ') {
       state = state_error;
-      Dmsg0(100, "Set state=error\n"); 
+      Dmsg0(100, "Set state=error or double code.\n");
    }
    switch (code) {
    case 'I':
@@ -838,6 +849,11 @@ static void add_fileset(JCR *jcr, const char *item)
       set_options(current_opts, item);
       state = state_options;
       break;
+   case 'Z':
+      current_opts = start_options(ff);
+      current_opts->ignoredir = bstrdup(item);
+      state = state_options;
+      break;
    case 'D':
       current_opts = start_options(ff);
 //    current_opts->reader = bstrdup(item);
@@ -899,6 +915,9 @@ static bool term_fileset(JCR *jcr)
          for (k=0; k<fo->drivetype.size(); k++) {
             Dmsg1(400, "XD %s\n", (char *)fo->drivetype.get(k));
          }
+         if (fo->ignoredir) {
+            Dmsg1(400, "Z %s\n", fo->ignoredir);
+         }
       }
       dlistString *node;
       foreach_dlist(node, &incexe->name_list) {
@@ -1057,6 +1076,16 @@ static void set_options(findFOPTS *fo, const char *opts)
          }
          fo->VerifyOpts[j] = 0;
          break;
+      case 'C':                  /* accurate options */
+         /* Copy Accurate Options */
+         for (j=0; *p && *p != ':'; p++) {
+            fo->AccurateOpts[j] = *p;
+            if (j < (int)sizeof(fo->AccurateOpts) - 1) {
+               j++;
+            }
+         }
+         fo->AccurateOpts[j] = 0;
+         break;
       case 'P':                  /* strip path */
          /* Get integer */
          p++;                    /* skip P */
@@ -1087,6 +1116,9 @@ static void set_options(findFOPTS *fo, const char *opts)
       case 'c':
          fo->flags |= FO_CHKCHANGES;
          break;
+      case 'N':
+         fo->flags |= FO_HONOR_NODUMP;
+         break;
       default:
          Emsg1(M_ERROR, 0, _("Unknown include/exclude option: %c\n"), *p);
          break;
@@ -1171,7 +1203,7 @@ static int bootstrap_cmd(JCR *jcr)
    }
 
    while (dir->recv() >= 0) {
-       Dmsg1(200, "filed<dird: bootstrap file %s\n", dir->msg);
+       Dmsg1(200, "filed<dird: bootstrap: %s", dir->msg);
        fputs(dir->msg, bs);
    }
    fclose(bs);
@@ -1194,24 +1226,27 @@ static int level_cmd(JCR *jcr)
    int mtime_only;
 
    level = get_memory(dir->msglen+1);
-   Dmsg1(110, "level_cmd: %s", dir->msg);
+   Dmsg1(100, "level_cmd: %s", dir->msg);
+   if (strstr(dir->msg, "accurate")) {
+      jcr->accurate = true;
+   }
    if (sscanf(dir->msg, "level = %s ", level) != 1) {
       goto bail_out;
    }
    /* Base backup requested? */
    if (strcmp(level, "base") == 0) {
-      jcr->JobLevel = L_BASE;
+      jcr->set_JobLevel(L_BASE);
    /* Full backup requested? */
    } else if (strcmp(level, "full") == 0) {
-      jcr->JobLevel = L_FULL;
-   } else if (strcmp(level, "differential") == 0) {
-      jcr->JobLevel = L_DIFFERENTIAL;
+      jcr->set_JobLevel(L_FULL);
+   } else if (strstr(level, "differential")) {
+      jcr->set_JobLevel(L_DIFFERENTIAL);
       free_memory(level);
       return 1;
-   } else if (strcmp(level, "incremental") == 0) {
-      jcr->JobLevel = L_INCREMENTAL;
+   } else if (strstr(level, "incremental")) {
+      jcr->set_JobLevel(L_INCREMENTAL);
       free_memory(level);
-      return 1;   
+      return 1;
    /*
     * We get his UTC since time, then sync the clocks and correct it
     *   to agree with our clock.
@@ -1220,8 +1255,8 @@ static int level_cmd(JCR *jcr)
       buf = get_memory(dir->msglen+1);
       utime_t since_time, adj;
       btime_t his_time, bt_start, rt=0, bt_adj=0;
-      if (jcr->JobLevel == L_NONE) {
-         jcr->JobLevel = L_SINCE;     /* if no other job level set, do it now */
+      if (jcr->get_JobLevel() == L_NONE) {
+         jcr->set_JobLevel(L_SINCE);     /* if no other job level set, do it now */
       }
       if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
                  buf, &mtime_only) != 2) {
@@ -1283,7 +1318,7 @@ static int level_cmd(JCR *jcr)
    if (buf) {
       free_memory(buf);
    }
-   generate_plugin_event(jcr, bEventLevel, (void *)jcr->JobLevel);
+   generate_plugin_event(jcr, bEventLevel, (void *)jcr->get_JobLevel());
    return dir->fsend(OKlevel);
 
 bail_out:
@@ -1313,7 +1348,7 @@ static int session_cmd(JCR *jcr)
       return 0;
    }
 
-   return bnet_fsend(dir, OKsession);
+   return dir->fsend(OKsession);
 }
 
 /*
@@ -1383,7 +1418,7 @@ static int backup_cmd(JCR *jcr)
 #endif
 
    set_jcr_job_status(jcr, JS_Blocked);
-   jcr->JobType = JT_BACKUP;
+   jcr->set_JobType(JT_BACKUP);
    Dmsg1(100, "begin backup ff=%p\n", jcr->ff);
 
    if (sd == NULL) {
@@ -1465,6 +1500,7 @@ static int backup_cmd(JCR *jcr)
          berrno be;
          Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled. ERR=%s\n"), be.bstrerror());
       } 
+      run_scripts(jcr, jcr->RunScripts, "ClientAfterVSS");
    }
 #endif
 
@@ -1556,22 +1592,22 @@ static int verify_cmd(JCR *jcr)
    BSOCK *sd  = jcr->store_bsock;
    char level[100];
 
-   jcr->JobType = JT_VERIFY;
+   jcr->set_JobType(JT_VERIFY);
    if (sscanf(dir->msg, verifycmd, level) != 1) {
       dir->fsend(_("2994 Bad verify command: %s\n"), dir->msg);
       return 0;
    }
 
    if (strcasecmp(level, "init") == 0) {
-      jcr->JobLevel = L_VERIFY_INIT;
+      jcr->set_JobLevel(L_VERIFY_INIT);
    } else if (strcasecmp(level, "catalog") == 0){
-      jcr->JobLevel = L_VERIFY_CATALOG;
+      jcr->set_JobLevel(L_VERIFY_CATALOG);
    } else if (strcasecmp(level, "volume") == 0){
-      jcr->JobLevel = L_VERIFY_VOLUME_TO_CATALOG;
+      jcr->set_JobLevel(L_VERIFY_VOLUME_TO_CATALOG);
    } else if (strcasecmp(level, "data") == 0){
-      jcr->JobLevel = L_VERIFY_DATA;
+      jcr->set_JobLevel(L_VERIFY_DATA);
    } else if (strcasecmp(level, "disk_to_catalog") == 0) {
-      jcr->JobLevel = L_VERIFY_DISK_TO_CATALOG;
+      jcr->set_JobLevel(L_VERIFY_DISK_TO_CATALOG);
    } else {
       dir->fsend(_("2994 Bad verify level: %s\n"), dir->msg);
       return 0;
@@ -1580,12 +1616,12 @@ static int verify_cmd(JCR *jcr)
    dir->fsend(OKverify);
 
    generate_daemon_event(jcr, "JobStart");
-   generate_plugin_event(jcr, bEventLevel, (void *)jcr->JobLevel);
+   generate_plugin_event(jcr, bEventLevel, (void *)jcr->get_JobLevel());
    generate_plugin_event(jcr, bEventStartVerifyJob);
 
    Dmsg1(110, "bfiled>dird: %s", dir->msg);
 
-   switch (jcr->JobLevel) {
+   switch (jcr->get_JobLevel()) {
    case L_VERIFY_INIT:
    case L_VERIFY_CATALOG:
       do_verify(jcr);
@@ -1681,7 +1717,7 @@ static int restore_cmd(JCR *jcr)
    dir->fsend(OKrestore);
    Dmsg1(110, "bfiled>dird: %s", dir->msg);
 
-   jcr->JobType = JT_RESTORE;
+   jcr->set_JobType(JT_RESTORE);
 
    set_jcr_job_status(jcr, JS_Blocked);
 
@@ -1742,7 +1778,7 @@ static int open_sd_read_session(JCR *jcr)
    /*
     * Open Read Session with Storage daemon
     */
-   bnet_fsend(sd, read_open, "DummyVolume",
+   sd->fsend(read_open, "DummyVolume",
       jcr->VolSessionId, jcr->VolSessionTime, jcr->StartFile, jcr->EndFile,
       jcr->StartBlock, jcr->EndBlock);
    Dmsg1(110, ">stored: %s", sd->msg);
@@ -1769,7 +1805,7 @@ static int open_sd_read_session(JCR *jcr)
    /*
     * Start read of data with Storage daemon
     */
-   bnet_fsend(sd, read_data, jcr->Ticket);
+   sd->fsend(read_data, jcr->Ticket);
    Dmsg1(110, ">stored: %s", sd->msg);
 
    /*
@@ -1788,7 +1824,7 @@ static int open_sd_read_session(JCR *jcr)
 static void filed_free_jcr(JCR *jcr)
 {
    if (jcr->store_bsock) {
-      bnet_close(jcr->store_bsock);
+      jcr->store_bsock->close();
    }
    free_bootstrap(jcr);
    if (jcr->last_fname) {
@@ -1855,12 +1891,12 @@ static int send_bootstrap_file(JCR *jcr)
       goto bail_out;
    }
    sd->msglen = pm_strcpy(sd->msg, bootstrap);
-   bnet_send(sd);
+   sd->send();
    while (fgets(buf, sizeof(buf), bs)) {
       sd->msglen = Mmsg(sd->msg, "%s", buf);
-      bnet_send(sd);
+      sd->send();
    }
-   bnet_sig(sd, BNET_EOD);
+   sd->signal(BNET_EOD);
    fclose(bs);
    if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);