]> 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 94b58dd2200b6abd1ab97b5d49b3617cd5f75dbf..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.
@@ -668,30 +668,56 @@ 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;
-   POOLMEM *msg_save;
 
    fd = jcr->file_bsock;
    if (jcr->is_job_canceled()) {
       return 1;
    }
-   fd->fsend("restoreobject JobId=%s ObjLen=%s ObjInx=%s ObjType=%s FI=%s\n",
-      row[0], row[1], row[2], row[3], row[4]);
+   /* 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]);
 
-   msg_save = fd->msg;
-   fd->msg = row[5] ? row[5] : (char *)"";
-   fd->msglen = strlen(fd->msg);
+   Dmsg1(010, "Send obj hdr=%s", fd->msg);
+
+   fd->msglen = pm_strcpy(fd->msg, row[7]);
    fd->send();                            /* send Object name */
-// Dmsg1(000, "Send obj: %s\n", fd->msg);
 
-   fd->msg = row[6] ? row[6] : (char *)""; /* object */
-   fd->msglen = str_to_uint64(row[1]);   /* object length */
+   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 */
-// Dmsg1(000, "Send obj: %s\n", fd->msg);
-   fd->msg = msg_save;
+   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;
 }
@@ -700,25 +726,35 @@ bool send_restore_objects(JCR *jcr)
 {
    POOL_MEM query(PM_MESSAGE);
    BSOCK *fd;
+   OBJ_CTX octx;
 
-// Dmsg0(000, "Enter send_restore_objects\n");
    if (!jcr->JobIds || !jcr->JobIds[0]) {
       return true;
    }
-   Mmsg(query, "SELECT JobId,ObjectLength,ObjectIndex,ObjectType,"
-        "FileIndex,Fname,RestoreObject FROM RestoreObject "
-        "WHERE JobId IN (%s) ORDER BY ObjectIndex ASC", 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);
    
    /* restore_object_handler is called for each file found */
-   db_sql_query(jcr->db, query.c_str(), restore_object_handler, (void *)jcr);
-// Dmsg0(000, "All restore objects sent, looking for OKRestoreObject\n");
-   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;
+   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;
+      }
    }
-// Dmsg0(000, "got for OKRestoreObject\n");
    return true;
 }