]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
bscan: Add Restore Object handling
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Thu, 17 Sep 2020 08:13:05 +0000 (10:13 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:57 +0000 (09:02 +0100)
bacula/src/cats/cats.c
bacula/src/cats/cats.h
bacula/src/dird/catreq.c
bacula/src/stored/bscan.c

index 338b64af0ec71a880ea1e05a19680ee1a463c158..a6be9775da5b4767263031214810d6c184360fe9 100644 (file)
@@ -217,4 +217,40 @@ void parse_plugin_object_string(char **obj_str, OBJECT_DBR *obj_r)
    obj_r->ObjectSize = str_to_uint64(p);
 }
 
+
+void parse_restore_object_string(char **r_obj_str, ROBJECT_DBR *robj_r)
+{
+   char *p = *r_obj_str;
+   int len;
+
+   robj_r->FileIndex = str_to_int32(p);        /* FileIndex */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+   robj_r->FileType = str_to_int32(p);        /* FileType */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+   robj_r->object_index = str_to_int32(p);    /* Object Index */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+   robj_r->object_len = str_to_int32(p);      /* object length possibly compressed */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+   robj_r->object_full_len = str_to_int32(p); /* uncompressed object length */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+   robj_r->object_compression = str_to_int32(p); /* compression */
+   skip_nonspaces(&p);
+   skip_spaces(&p);
+
+   robj_r->plugin_name = p;                      /* point to plugin name */
+   len = strlen(robj_r->plugin_name);
+   robj_r->object_name = &robj_r->plugin_name[len+1]; /* point to object name */
+   len = strlen(robj_r->object_name);
+   robj_r->object = &robj_r->object_name[len+1];      /* point to object */
+   robj_r->object[robj_r->object_len] = 0;            /* add zero for those who attempt printing */
+   Dmsg7(100, "oname=%s stream=%d FT=%d FI=%d JobId=%ld, obj_len=%d\nobj=\"%s\"\n",
+      robj_r->object_name, robj_r->Stream, robj_r->FileType, robj_r->FileIndex, robj_r->JobId,
+      robj_r->object_len, robj_r->object);
+}
+
 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL */ 
index 68229daebd435eb6a7651453fc0b048d2d180874..8548bad99a9da7fbd21b869acaf6e75728f6f560 100644 (file)
@@ -663,5 +663,6 @@ void split_path_and_file(JCR *jcr, BDB *mdb, const char *fname);
 
 /* Helper functions */
 void parse_plugin_object_string(char **obj_str, OBJECT_DBR *obj_r);
+void parse_restore_object_string(char **obj_str, ROBJECT_DBR *r_r);
 
 #endif  /* __CATS_H_ */
index 3b1896568fba092e37fbaff49012765fc17ca38e..3663f63812875b0dcb78188f9a88f30f14d997be 100644 (file)
@@ -655,10 +655,9 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
 
    } else if (Stream == STREAM_RESTORE_OBJECT) {
       ROBJECT_DBR ro;
-
       bmemset(&ro, 0, sizeof(ro));
+
       ro.Stream = Stream;
-      ro.FileIndex = FileIndex;
       if (jcr->wjcr) {
          ro.JobId = jcr->wjcr->JobId;
          Dmsg1(100, "=== set JobId=%ld\n", ar->JobId);
@@ -668,33 +667,8 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
 
       Dmsg1(100, "Robj=%s\n", p);
 
-      skip_nonspaces(&p);                  /* skip FileIndex */
-      skip_spaces(&p);
-      ro.FileType = str_to_int32(p);        /* FileType */
-      skip_nonspaces(&p);
-      skip_spaces(&p);
-      ro.object_index = str_to_int32(p);    /* Object Index */
-      skip_nonspaces(&p);
-      skip_spaces(&p);
-      ro.object_len = str_to_int32(p);      /* object length possibly compressed */
-      skip_nonspaces(&p);
-      skip_spaces(&p);
-      ro.object_full_len = str_to_int32(p); /* uncompressed object length */
-      skip_nonspaces(&p);
-      skip_spaces(&p);
-      ro.object_compression = str_to_int32(p); /* compression */
-      skip_nonspaces(&p);
-      skip_spaces(&p);
+      parse_restore_object_string(&p, &ro);
 
-      ro.plugin_name = p;                      /* point to plugin name */
-      len = strlen(ro.plugin_name);
-      ro.object_name = &ro.plugin_name[len+1]; /* point to object name */
-      len = strlen(ro.object_name);
-      ro.object = &ro.object_name[len+1];      /* point to object */
-      ro.object[ro.object_len] = 0;            /* add zero for those who attempt printing */
-      Dmsg7(100, "oname=%s stream=%d FT=%d FI=%d JobId=%ld, obj_len=%d\nobj=\"%s\"\n",
-         ro.object_name, ro.Stream, ro.FileType, ro.FileIndex, ro.JobId,
-         ro.object_len, ro.object);
       /* Send it */
       if (!db_create_restore_object_record(jcr, jcr->db, &ro)) {
          Jmsg1(jcr, M_FATAL, 0, _("Restore object create error. %s"), db_strerror(jcr->db));
index e9e52fffa9df369f1023497ae8b670632cb00b13..d1644bf812406c1ffdcb81012688db53d4f28b8b 100644 (file)
@@ -749,9 +749,40 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
       break;
 
    case STREAM_RESTORE_OBJECT:
-   /* ****FIXME*****/
-      /* Implement putting into catalog */
-      break;
+      {
+         char *buf = rec->data;
+         ROBJECT_DBR ro;
+         bmemset(&ro, 0, sizeof(ro));
+
+         ro.Stream = rec->maskedStream;
+         parse_restore_object_string(&buf, &ro);
+
+         // Need to get new jobId if possible
+         mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
+         if (!mjcr) {
+            Pmsg2(000, _("Could not find SessId=%d SessTime=%d for RestoreObject record.\n"),
+                  rec->VolSessionId, rec->VolSessionTime);
+            break;
+         }
+
+         ro.JobId = mjcr->JobId;
+
+         if (db_get_restoreobject_record(mjcr, db, &ro)) {
+            if (verbose) {
+               Pmsg1(0, _("RESTORE_OBJECT: Found Restore Object \"%s\" in the catalog\n"), ro.object_name);
+            }
+         } else if (update_db) {
+            /* Send it */
+            Pmsg1(0, _("RESTORE_OBJECT: Inserting Restore Object \"%s\" into the catalog\n"), ro.object_name);
+            if (!db_create_restore_object_record(mjcr, db, &ro)) {
+               Jmsg1(mjcr, M_FATAL, 0, _("Restore object create error. %s"), db_strerror(db));
+            }
+         } else {
+            Pmsg1(0, _("RESTORE_OBJECT: Found Restore Object \"%s\" on the volume\n"), ro.object_name);
+         }
+
+         break;
+      }
 
    case STREAM_PLUGIN_OBJECT:
       {