]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/fd_cmds.c
Keep the same keywords as in previous version
[bacula/bacula] / bacula / src / dird / fd_cmds.c
index 340ff606ffc393977d440ab2ba08da51cb3c2382..64f12ef98555518631af47d31335a2016e50e80f 100644 (file)
@@ -6,7 +6,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.
 
@@ -15,7 +15,7 @@
    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.
@@ -59,6 +59,7 @@ static char OKjob[]          = "2000 OK Job";
 static char OKlevel[]        = "2000 OK level\n";
 static char OKRunScript[]    = "2000 OK RunScript\n";
 static char OKRunBeforeNow[] = "2000 OK RunBeforeNow\n";
+static char OKRestoreObject[] = "2000 OK ObjectRestored\n";
 
 /* Forward referenced functions */
 static bool send_list_item(JCR *jcr, const char *code, char *item, BSOCK *fd);
@@ -667,38 +668,93 @@ bail_out:
    return 0;
 }
 
+struct OBJ_CTX {
+   JCR *jcr;
+   int count;
+};
+
 static int restore_object_handler(void *ctx, int num_fields, char **row)
 {
-   JCR *jcr = (JCR *)ctx;
+   OBJ_CTX *octx = (OBJ_CTX *)ctx;
+   JCR *jcr = octx->jcr;
    BSOCK *fd;
 
    fd = jcr->file_bsock;
    if (jcr->is_job_canceled()) {
       return 1;
    }
-   bash_spaces(row[2]);
-   bash_spaces(row[3]);
-   bash_spaces(row[6]);
-   fd->fsend("RestoreObject JobId=%s ObjLen=%s ObjInx=%s ObjType=%s FI=%s",
-      row[0], row[3], row[6], row[7], row[8]);
-   Dmsg1(000, ">fd: %s\n", fd->msg);
+   /* Old File Daemon doesn't handle restore objects */
+   if (jcr->FDVersion < 3) {
+      Jmsg(jcr, M_WARNING, 0, _("Client \"%s\" may not be used to restore "
+                                "this job. Please upgrade your client.\n"), 
+           jcr->client->name());
+      return 1;
+   }
+
+   fd->fsend("restoreobject JobId=%s %s,%s,%s,%s,%s,%s\n",
+      row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
+
+   Dmsg1(010, "Send obj hdr=%s", fd->msg);
+
+   fd->msglen = pm_strcpy(fd->msg, row[7]);
+   fd->send();                            /* send Object name */
+
+   Dmsg1(010, "Send obj: %s\n", fd->msg);
+
+//   fd->msglen = str_to_uint64(row[1]);   /* object length */
+//   Dmsg1(000, "obj size: %lld\n", (uint64_t)fd->msglen);
+
+   /* object */
+   db_unescape_object(jcr, jcr->db, 
+                      row[8],                /* Object  */
+                      str_to_uint64(row[1]), /* Object length */
+                      &fd->msg, &fd->msglen);
+   fd->send();                           /* send object */
+   octx->count++;
+
+   if (debug_level) {
+      for (int i=0; i < fd->msglen; i++)
+         if (!fd->msg[i]) 
+            fd->msg[i] = ' ';
+      Dmsg1(000, "Send obj: %s\n", fd->msg);
+   }
+
    return 0;
 }
 
 bool send_restore_objects(JCR *jcr)
 {
-//   BSOCK *fd = jcr->file_bsock;
    POOL_MEM query(PM_MESSAGE);
+   BSOCK *fd;
+   OBJ_CTX octx;
 
    if (!jcr->JobIds || !jcr->JobIds[0]) {
       return true;
    }
-   Mmsg(query, "SELECT JobId,Fname,Path,ObjectLength,RestoreObject,"
-        "PluginName,ObjectIndex,ObjectType,FileIndex "
-        "FROM RestoreObject WHERE JobId IN (%s)", jcr->JobIds);
+   octx.jcr = jcr;
+   octx.count = 0;
+   Mmsg(query, "SELECT JobId,ObjectLength,ObjectFullLength,ObjectIndex,"
+                      "ObjectType,ObjectCompression,FileIndex,ObjectName,"
+                      "RestoreObject "
+               "FROM RestoreObject "
+              "WHERE JobId IN (%s) "
+              "ORDER BY ObjectIndex ASC", jcr->JobIds);
    
-   /* missing_handler is called for each file found */
-   db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)jcr);
+   /* restore_object_handler is called for each file found */
+   db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)&octx);
+
+   /*
+    * Send to FD only if we have at least one restore object.
+    * This permits backward compatibility with older FDs.
+    */
+   if (octx.count > 0) {
+      fd = jcr->file_bsock;
+      fd->fsend("restoreobject end\n");
+      if (!response(jcr, fd, OKRestoreObject, "RestoreObject", DISPLAY_ERROR)) {
+         Jmsg(jcr, M_FATAL, 0, _("RestoreObject failed.\n"));
+         return false;
+      }
+   }
    return true;
 }