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.
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.
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[3], row[6], row[7], row[8]);
+ /* 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]);
- fd->fsend("%s", row[1]); /* send Fname */
-// Dmsg1(000, "Send obj: %s\n", fd->msg);
+ Dmsg1(010, "Send obj hdr=%s", fd->msg);
- fd->fsend("%s", row[2]); /* send Path */
-// Dmsg1(000, "Send obj: %s\n", fd->msg);
+ fd->msglen = pm_strcpy(fd->msg, row[7]);
+ fd->send(); /* send Object name */
- msg_save = fd->msg;
- fd->msg = row[4]; /* object */
- fd->msglen = str_to_uint64(row[3]); /* 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;
}
{
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,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);
/* 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;
}