]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Add new files
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index f565c1360eaa13af6329dbe5453a85dd87a635cc..0aa9e4ae9bae1b374fbfe7d4f2094ac399c161cb 100644 (file)
@@ -42,9 +42,10 @@ static char jobcmd[]      = "JobId=%d Job=%s SDid=%u SDtime=%u Authorization=%s\
 
 
 /* Responses received from File daemon */
-static char OKinc[]      = "2000 OK include\n";
-static char OKexc[]      = "2000 OK exclude\n";
-static char OKjob[]      = "2000 OK Job";
+static char OKinc[]       = "2000 OK include\n";
+static char OKexc[]       = "2000 OK exclude\n";
+static char OKjob[]       = "2000 OK Job";
+static char OKbootstrap[] = "2000 OK bootstrap\n";
 
 /* Forward referenced functions */
 
@@ -100,10 +101,20 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
          set_jcr_job_status(jcr, JS_ErrorTerminated);
          return 0;
        } else {
-         /***** ***FIXME***** update Client Uname */
+         CLIENT_DBR cr;
+         memset(&cr, 0, sizeof(cr));
+         bstrncpy(cr.Name, jcr->client->hdr.name, sizeof(cr.Name));
+         cr.AutoPrune = jcr->client->AutoPrune;
+         cr.FileRetention = jcr->client->FileRetention;
+         cr.JobRetention = jcr->client->JobRetention;
+         bstrncpy(cr.Uname, fd->msg+strlen(OKjob)+1, sizeof(cr.Uname));
+         if (!db_update_client_record(jcr, jcr->db, &cr)) {
+             Jmsg(jcr, M_WARNING, 0, _("Error updating Client record. ERR=%s\n"),
+               db_strerror(jcr->db));
+         }
        }
    } else {
-      Jmsg(jcr, M_FATAL, 0, _("<filed: bad response to JobId command: %s\n"),
+      Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
         bnet_strerror(fd));
       set_jcr_job_status(jcr, JS_ErrorTerminated);
       return 0;
@@ -113,7 +124,7 @@ int connect_to_file_daemon(JCR *jcr, int retry_interval, int max_retry_time,
 
 
 /*
- * Send either an Included or an Excluded list
+ * Send either an Included or an Excluded list to FD
  */
 static int send_list(JCR *jcr, int list)
 {
@@ -145,7 +156,7 @@ static int send_list(JCR *jcr, int list)
       }
       for (int j=0; j<ie->num_names; j++) {
         p = ie->name_list[j];
-        switch (*p++) {
+        switch (*p) {
          case '|':
             fd->msg = edit_job_codes(jcr, fd->msg, p, "");
             bpipe = open_bpipe(fd->msg, 0, "r");
@@ -177,6 +188,7 @@ static int send_list(JCR *jcr, int list)
            }
            break;
          case '<':
+           p++;                      /* skip over < */
             if ((ffd = fopen(p, "r")) == NULL) {
                Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
                   list==INC_LIST?"included":"excluded", p, strerror(errno));
@@ -199,6 +211,9 @@ static int send_list(JCR *jcr, int list)
            }
            fclose(ffd);
            break;
+         case '\\':
+            p++;                      /* skip over \ */
+           /* Note, fall through wanted */
         default:
            if (ie->num_opts) {
               pm_strcpy(&fd->msg, ie->opts_list[0]->opts);
@@ -206,7 +221,7 @@ static int send_list(JCR *jcr, int list)
            } else {
                pm_strcpy(&fd->msg, "0 ");
            }
-           pm_strcat(&fd->msg, ie->name_list[j]);
+           pm_strcat(&fd->msg, p);
             Dmsg1(100, "Inc/Exc name=%s\n", fd->msg);
            fd->msglen = strlen(fd->msg);
            if (!bnet_send(fd)) {
@@ -219,10 +234,10 @@ static int send_list(JCR *jcr, int list)
    }
    bnet_sig(fd, BNET_EOD);           /* end of data */
    if (list == INC_LIST) {
-      if (!response(fd, OKinc, "Include")) {
+      if (!response(jcr, fd, OKinc, "Include", DISPLAY_ERROR)) {
         goto bail_out;
       }
-   } else if (!response(fd, OKexc, "Exclude")) {
+   } else if (!response(jcr, fd, OKexc, "Exclude", DISPLAY_ERROR)) {
        goto bail_out;
    }
    return 1;
@@ -257,6 +272,45 @@ int send_exclude_list(JCR *jcr)
 }
 
 
+/*
+ * Send bootstrap file if any to the File daemon.
+ *  This is used for restore and verify VolumeToCatalog
+ */
+int send_bootstrap_file(JCR *jcr)
+{
+   FILE *bs;
+   char buf[1000];
+   BSOCK *fd = jcr->file_bsock;
+   char *bootstrap = "bootstrap\n";
+
+   Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
+   if (!jcr->RestoreBootstrap) {
+      return 1;
+   }
+   bs = fopen(jcr->RestoreBootstrap, "r");
+   if (!bs) {
+      Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
+        jcr->RestoreBootstrap, strerror(errno));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
+      return 0;
+   }
+   strcpy(fd->msg, bootstrap); 
+   fd->msglen = strlen(fd->msg);
+   bnet_send(fd);
+   while (fgets(buf, sizeof(buf), bs)) {
+      fd->msglen = Mmsg(&fd->msg, "%s", buf);
+      bnet_send(fd);      
+   }
+   bnet_sig(fd, BNET_EOD);
+   fclose(bs);
+   if (!response(jcr, fd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
+      return 0;
+   }
+   return 1;
+}
+
+
 /* 
  * Read the attributes from the File daemon for
  * a Verify job and store them in the catalog.
@@ -274,7 +328,7 @@ int get_attributes_and_put_in_catalog(JCR *jcr)
 
    Dmsg0(120, "bdird: waiting to receive file attributes\n");
    /* Pickup file attributes and signature */
-   while (!fd->errors && (n = bget_msg(fd, 0)) > 0) {
+   while (!fd->errors && (n = bget_dirmsg(fd)) > 0) {
 
    /*****FIXME****** improve error handling to stop only on 
     * really fatal problems, or the number of errors is too
@@ -307,7 +361,7 @@ msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
       *fn = *p++;                    /* term filename and point to attribs */
       attr = p;
 
-      if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_WIN32_ATTRIBUTES) {
+      if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX) {
         jcr->JobFiles++;
         jcr->FileIndex = file_index;
         ar.attr = attr;