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);
{
JCR *jcr = (JCR *)ctx;
BSOCK *fd;
+ POOLMEM *msg_save;
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",
+ fd->fsend("restoreobject JobId=%s ObjLen=%s ObjInx=%s ObjType=%s FI=%s\n",
row[0], row[3], row[6], row[7], row[8]);
- Dmsg1(000, ">fd: %s\n", fd->msg);
+
+ fd->fsend("%s", row[1]); /* send Fname */
+// Dmsg1(000, "Send obj: %s\n", fd->msg);
+
+ fd->fsend("%s", row[2]); /* send Path */
+// Dmsg1(000, "Send obj: %s\n", fd->msg);
+
+ msg_save = fd->msg;
+ fd->msg = row[4]; /* object */
+ fd->msglen = str_to_uint64(row[3]); /* object length */
+ fd->send(); /* send object */
+// Dmsg1(000, "Send obj: %s\n", fd->msg);
+ fd->msg = msg_save;
+
return 0;
}
bool send_restore_objects(JCR *jcr)
{
-// BSOCK *fd = jcr->file_bsock;
POOL_MEM query(PM_MESSAGE);
+ BSOCK *fd;
+// Dmsg0(000, "Enter send_restore_objects\n");
if (!jcr->JobIds || !jcr->JobIds[0]) {
return true;
}
"PluginName,ObjectIndex,ObjectType,FileIndex "
"FROM RestoreObject WHERE JobId IN (%s)", jcr->JobIds);
- /* missing_handler is called for each file found */
+ /* 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;
+ }
+// Dmsg0(000, "got for OKRestoreObject\n");
return true;
}
static int runbefore_cmd(JCR *jcr);
static int runafter_cmd(JCR *jcr);
static int runbeforenow_cmd(JCR *jcr);
-static int restoreobject_cmd(JCR *jcr);
+static int restore_object_cmd(JCR *jcr);
static void set_options(findFOPTS *fo, const char *opts);
static void set_storage_auth_key(JCR *jcr, char *key);
{"fileset", fileset_cmd, 0},
{"JobId=", job_cmd, 0},
{"level = ", level_cmd, 0},
- {"restore", restore_cmd, 0},
+ {"restore ", restore_cmd, 0},
{"endrestore", end_restore_cmd, 0},
{"session", session_cmd, 0},
{"status", status_cmd, 1},
{"RunAfterJob", runafter_cmd, 0},
{"Run", runscript_cmd, 0},
{"accurate", accurate_cmd, 0},
- {"restoreobject", restoreobject_cmd, 0},
+ {"restoreobject", restore_object_cmd, 0},
{NULL, NULL} /* list terminator */
};
static char restorecmd[] = "restore replace=%c prelinks=%d where=%s\n";
static char restorecmd1[] = "restore replace=%c prelinks=%d where=\n";
static char restorecmdR[] = "restore replace=%c prelinks=%d regexwhere=%s\n";
-static char restoreobjcmd[] = "RestoreObject JobId=%u ObjLen=%d ObjInx=%d ObjType=%d FI=%d";
+static char restoreobjcmd[] = "restoreobject JobId=%u ObjLen=%d ObjInx=%d ObjType=%d FI=%d\n";
+static char endrestoreobjectcmd[] = "restoreobject end\n";
static char verifycmd[] = "verify level=%30s";
static char estimatecmd[] = "estimate listing=%d";
static char runbefore[] = "RunBeforeJob %s";
static char OKRunAfter[] = "2000 OK RunAfter\n";
static char OKRunScript[] = "2000 OK RunScript\n";
static char BADcmd[] = "2902 Bad %s\n";
+static char OKRestoreObject[] = "2000 OK ObjectRestored\n";
/* Responses received from Storage Daemon */
}
-static int restoreobject_cmd(JCR *jcr)
+static int restore_object_cmd(JCR *jcr)
{
BSOCK *dir = jcr->dir_bsock;
POOLMEM *msg = get_memory(dir->msglen+1);
uint32_t JobId;
int32_t object_len, object_index, object_type, FileIndex;
- Dmsg1(000, "restoreobject_cmd: %s", dir->msg);
+ Dmsg1(100, "Enter restoreobject_cmd: %s", dir->msg);
+ if (strcmp(dir->msg, endrestoreobjectcmd) == 0) {
+ free_memory(msg);
+ return dir->fsend(OKRestoreObject);
+ }
+
if (sscanf(dir->msg, restoreobjcmd, &JobId, &object_len, &object_index,
&object_type, &FileIndex) != 5) {
+ Dmsg0(5, "Bad restore object command\n");
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad RestoreObject command: %s\n"), jcr->errmsg);
- dir->fsend(_("2909 Bad RestoreObject command.\n"));
- free_memory(msg);
- return 0;
+ goto bail_out;
+ }
+
+// Dmsg5(000, "Recv object: JobId=%u objlen=%d objinx=%d objtype=%d FI=%d\n",
+// JobId, object_len, object_index, object_type, FileIndex);
+ /* Read Fname */
+ if (dir->recv() < 0) {
+ goto bail_out;
+ }
+// Dmsg2(000, "Recv Fname object: len=%d Fname=%s\n", dir->msglen, dir->msg);
+
+ /* Read Path */
+ if (dir->recv() < 0) {
+ goto bail_out;
}
- Dmsg5(000, "JobId=%u objlen=%d objinx=%d objtype=%d FI=%d\n",
- JobId, object_len, object_index, object_type, FileIndex);
+// Dmsg2(000, "Recv Path object: len=%d Path=%s\n", dir->msglen, dir->msg);
+
+ /* Read Object */
+ if (dir->recv() < 0) {
+ goto bail_out;
+ }
+// Dmsg2(000, "Recv Object: len=%d Object=%s\n", dir->msglen, dir->msg);
+
+ free_memory(msg);
+ Dmsg1(100, "Send: %s", OKRestoreObject);
return 1;
+
+bail_out:
+ dir->fsend(_("2909 Bad RestoreObject command.\n"));
+ free_memory(msg);
+ return 0;
+
}
return;
}
- /* We can be contacting multiple storage daemons.
+ /**
+ * We can be contacting multiple storage daemons.
* So, make sure that any old jcr->store_bsock is cleaned up.
*/
if (jcr->store_bsock) {
* So, make sure that any old jcr->sd_auth_key is cleaned up.
*/
if (jcr->sd_auth_key) {
- /* If we already have a Authorization key, director can do multi
+ /*
+ * If we already have a Authorization key, director can do multi
* storage restore
*/
Dmsg0(5, "set multi_restore=true\n");
}
jcr->sd_auth_key = bstrdup(key);
+ Dmsg0(5, "set sd auth key\n");
}
/**
/**
* Scan WHERE (base directory for restore) from command
*/
- Dmsg0(150, "restore command\n");
+ Dmsg0(100, "restore command\n");
#if defined(WIN32_VSS)
/* TODO: this should be given from the director */
* Send Close session command to Storage daemon
*/
sd->fsend(read_close, jcr->Ticket);
- Dmsg1(130, "filed>stored: %s", sd->msg);
+ Dmsg1(100, "filed>stored: %s", sd->msg);
bget_msg(sd); /* get OK */
set_jcr_job_status(jcr, JS_ErrorTerminated);
}
- Dmsg0(130, "Done in job.c\n");
+ Dmsg0(100, "Done in job.c\n");
int ret;
if (jcr->multi_restore) {
+ Dmsg0(100, OKstoreend);
dir->fsend(OKstoreend);
ret = 1; /* we continue the loop, waiting for next part */
} else {
int32_t *hdr;
bool ok = true;
- if (errors || is_terminated() || msglen > 1000000) {
+ if (errors) {
if (!m_suppress_error_msgs) {
- Qmsg6(m_jcr, M_ERROR, 0,
- _("Socket has errors=%d; is_terminated=%d; or has insane msglen=%d on call to %s:%s:%d\n"),
- errors, is_terminated(), msglen, m_who,
- m_host, m_port);
+ Qmsg4(m_jcr, M_ERROR, 0, _("Socket has errors=%d on call to %s:%s:%d\n"),
+ errors, m_who, m_host, m_port);
}
return false;
}
+ if (is_terminated()) {
+ if (!m_suppress_error_msgs) {
+ Qmsg4(m_jcr, M_ERROR, 0, _("Socket is terminated=%d on call to %s:%s:%d\n"),
+ is_terminated(), m_who, m_host, m_port);
+ }
+ return false;
+ }
+ if (msglen > 1000000) {
+ if (!m_suppress_error_msgs) {
+ Qmsg4(m_jcr, M_ERROR, 0,
+ _("Socket has insane msglen=%d on call to %s:%s:%d\n"),
+ msglen, m_who, m_host, m_port);
+ }
+ return false;
+ }
+
if (m_use_locking) P(m_mutex);
/* Compute total packet length */
if (msglen <= 0) {