X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffiled%2Fjob.c;h=368976d2b96dacfa30ca32c90047489627db7047;hb=8694fe83738792584b6c7c1a42a6225159dbf998;hp=2a9dca806fd6a30f0a3f6e6b45cea4b883f2c6f2;hpb=76f820c1c52f6e1bb43ff683b2511270d1dd4e90;p=bacula%2Fbacula diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 2a9dca806f..368976d2b9 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -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. @@ -91,6 +91,10 @@ static int runbeforenow_cmd(JCR *jcr); static int restore_object_cmd(JCR *jcr); static int set_options(findFOPTS *fo, const char *opts); static void set_storage_auth_key(JCR *jcr, char *key); +static int sm_dump_cmd(JCR *jcr); +#ifdef DEVELOPER +static int exit_cmd(JCR *jcr); +#endif /* Exported functions */ @@ -126,6 +130,10 @@ static struct s_cmds cmds[] = { {"Run", runscript_cmd, 0}, {"accurate", accurate_cmd, 0}, {"restoreobject", restore_object_cmd, 0}, + {"sm_dump", sm_dump_cmd, 0}, +#ifdef DEVELOPER + {"exit", exit_cmd, 0}, +#endif {NULL, NULL} /* list terminator */ }; @@ -137,7 +145,7 @@ static char sessioncmd[] = "session %127s %ld %ld %ld %ld %ld %ld\n"; 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\n"; +static char restoreobjcmd[] = "restoreobject JobId=%u %d,%d,%d,%d,%d,%d\n"; static char endrestoreobjectcmd[] = "restoreobject end\n"; static char verifycmd[] = "verify level=%30s"; static char estimatecmd[] = "estimate listing=%d"; @@ -394,9 +402,28 @@ void *handle_client_request(void *dirp) free_jcr(jcr); /* destroy JCR record */ Dmsg0(100, "Done with free_jcr\n"); Dsm_check(1); + garbage_collect_memory_pool(); return NULL; } +static int sm_dump_cmd(JCR *jcr) +{ + close_memory_pool(); + sm_dump(false, true); + jcr->dir_bsock->fsend("2000 sm_dump OK\n"); + return 1; +} + +#ifdef DEVELOPER +static int exit_cmd(JCR *jcr) +{ + jcr->dir_bsock->fsend("2000 exit OK\n"); + terminate_filed(0); + return 0; +} +#endif + + /** * Hello from Director he must identify himself and provide his * password. @@ -428,7 +455,7 @@ static int cancel_cmd(JCR *jcr) if (cjcr->store_bsock) { cjcr->store_bsock->set_timed_out(); cjcr->store_bsock->set_terminated(); - pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); + cjcr->my_thread_send_signal(TIMEOUT_SIGNAL); } generate_plugin_event(cjcr, bEventCancelCommand, NULL); set_jcr_job_status(cjcr, JS_Canceled); @@ -629,7 +656,6 @@ static int runscript_cmd(JCR *jcr) static int restore_object_cmd(JCR *jcr) { BSOCK *dir = jcr->dir_bsock; - POOLMEM *msg = get_memory(dir->msglen+1); int32_t FileIndex; restore_object_pkt rop; @@ -639,20 +665,21 @@ static int restore_object_cmd(JCR *jcr) Dmsg1(100, "Enter restoreobject_cmd: %s", dir->msg); if (strcmp(dir->msg, endrestoreobjectcmd) == 0) { generate_plugin_event(jcr, bEventRestoreObject, NULL); - free_memory(msg); return dir->fsend(OKRestoreObject); } if (sscanf(dir->msg, restoreobjcmd, &rop.JobId, &rop.object_len, - &rop.object_index, &rop.object_type, &FileIndex) != 5) { + &rop.object_full_len, &rop.object_index, + &rop.object_type, &rop.object_compression, &FileIndex) != 7) { 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); goto bail_out; } - Dmsg5(100, "Recv object: JobId=%u objlen=%d objinx=%d objtype=%d FI=%d\n", - rop.JobId, rop.object_len, rop.object_index, rop.object_type, FileIndex); + Dmsg6(100, "Recv object: JobId=%u objlen=%d full_len=%d objinx=%d objtype=%d FI=%d\n", + rop.JobId, rop.object_len, rop.object_full_len, + rop.object_index, rop.object_type, FileIndex); /* Read Object name */ if (dir->recv() < 0) { goto bail_out; @@ -664,9 +691,28 @@ static int restore_object_cmd(JCR *jcr) if (dir->recv() < 0) { goto bail_out; } + /* Transfer object from message buffer, and get new message buffer */ rop.object = dir->msg; - Dmsg2(100, "Recv Object: len=%d Object=%s\n", dir->msglen, dir->msg); - + dir->msg = get_pool_memory(PM_MESSAGE); + + /* If object is compressed, uncompress it */ + if (rop.object_compression == 1) { /* zlib level 9 */ + int stat; + int out_len = rop.object_full_len + 100; + POOLMEM *obj = get_memory(out_len); + Dmsg2(100, "Inflating from %d to %d\n", rop.object_len, rop.object_full_len); + stat = Zinflate(rop.object, rop.object_len, obj, out_len); + Dmsg1(100, "Zinflate stat=%d\n", stat); + if (out_len != rop.object_full_len) { + Jmsg3(jcr, M_ERROR, 0, ("Decompression failed. Len wanted=%d got=%d. Object=%s\n"), + rop.object_full_len, out_len, rop.object_name); + } + free_pool_memory(rop.object); /* release compressed object */ + rop.object = obj; /* new uncompressed object */ + rop.object_len = out_len; + } + Dmsg2(100, "Recv Object: len=%d Object=%s\n", rop.object_len, rop.object); + /* Special Job meta data */ if (strcmp(rop.object_name, "job_metadata.xml") == 0) { Dmsg0(100, "got job metadata\n"); free_and_null_pool_memory(jcr->job_metadata); @@ -680,17 +726,15 @@ static int restore_object_cmd(JCR *jcr) if (rop.object_name) { free(rop.object_name); } - if (!rop.object) { - dir->msg = get_pool_memory(PM_MESSAGE); + if (rop.object) { + free_pool_memory(rop.object); } - free_memory(msg); Dmsg1(100, "Send: %s", OKRestoreObject); return 1; bail_out: dir->fsend(_("2909 Bad RestoreObject command.\n")); - free_memory(msg); return 0; } @@ -717,6 +761,22 @@ static bool init_fileset(JCR *jcr) return true; } +static void append_file(JCR *jcr, findINCEXE *incexe, + const char *buf, bool is_file) +{ + if (is_file) { + incexe->name_list.append(new_dlistString(buf)); + + } else if (me->plugin_directory) { + generate_plugin_event(jcr, bEventPluginCommand, (void *)buf); + incexe->plugin_list.append(new_dlistString(buf)); + + } else { + Jmsg(jcr, M_FATAL, 0, + _("Plugin Directory not defined. Cannot use plugin: \"%s\"\n"), + buf); + } +} /** * Add fname to include/exclude fileset list. First check for @@ -751,11 +811,7 @@ void add_file_to_fileset(JCR *jcr, const char *fname, bool is_file) free_pool_memory(fn); while (fgets(buf, sizeof(buf), bpipe->rfd)) { strip_trailing_junk(buf); - if (is_file) { - fileset->incexe->name_list.append(new_dlistString(buf)); - } else { - fileset->incexe->plugin_list.append(new_dlistString(buf)); - } + append_file(jcr, fileset->incexe, buf, is_file); } if ((stat=close_bpipe(bpipe)) != 0) { berrno be; @@ -769,32 +825,19 @@ void add_file_to_fileset(JCR *jcr, const char *fname, bool is_file) p++; /* skip over < */ if ((ffd = fopen(p, "rb")) == NULL) { berrno be; - Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"), + Jmsg(jcr, M_FATAL, 0, + _("Cannot open FileSet input file: %s. ERR=%s\n"), p, be.bstrerror()); return; } while (fgets(buf, sizeof(buf), ffd)) { strip_trailing_junk(buf); - Dmsg1(100, "%s\n", buf); - if (is_file) { - fileset->incexe->name_list.append(new_dlistString(buf)); - } else { - fileset->incexe->plugin_list.append(new_dlistString(buf)); - } - } + append_file(jcr, fileset->incexe, buf, is_file); + } fclose(ffd); break; default: - if (is_file) { - fileset->incexe->name_list.append(new_dlistString(fname)); - } else { - if (me->plugin_directory) { - fileset->incexe->plugin_list.append(new_dlistString(fname)); - } else { - Jmsg(jcr, M_FATAL, 0, _("Plugin Directory not defined. Cannot use plugin: \"%\"\n"), - fname); - } - } + append_file(jcr, fileset->incexe, fname, is_file); break; } } @@ -1779,8 +1822,8 @@ static int backup_cmd(JCR *jcr) if (get_win32_driveletters(jcr->ff, szWinDriveLetters)) { Jmsg(jcr, M_INFO, 0, _("Generate VSS snapshots. Driver=\"%s\", Drive(s)=\"%s\"\n"), g_pVSSClient->GetDriverName(), szWinDriveLetters); if (!g_pVSSClient->CreateSnapshots(szWinDriveLetters)) { - Jmsg(jcr, M_WARNING, 0, _("Generate VSS snapshots failed.\n")); - jcr->JobErrors++; + berrno be; + Jmsg(jcr, M_FATAL, 0, _("Generate VSS snapshots failed. ERR=%s\n"), be.bstrerror()); } else { /* tell user if snapshot creation of a specific drive failed */ int i; @@ -1793,8 +1836,8 @@ static int backup_cmd(JCR *jcr) /* inform user about writer states */ for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++) if (g_pVSSClient->GetWriterState(i) < 1) { - Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i)); - jcr->JobErrors++; + Jmsg(jcr, M_INFO, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i)); + //jcr->JobErrors++; } } } else { @@ -1986,8 +2029,11 @@ static int restore_cmd(JCR *jcr) Dmsg0(100, "restore command\n"); #if defined(WIN32_VSS) - /* TODO: this should be given from the director */ - enable_vss = 1; + /** + * No need to enable VSS for restore if we do not have plugin + * data to restore + */ + enable_vss = jcr->job_metadata != NULL; Dmsg2(50, "g_pVSSClient = %p, enable_vss = %d\n", g_pVSSClient, enable_vss); // capture state here, if client is backed up by multiple directors @@ -2063,20 +2109,21 @@ static int restore_cmd(JCR *jcr) if (jcr->VSS) { if (g_pVSSClient->InitializeForRestore(jcr, vss_restore_init_callback, (WCHAR *)jcr->job_metadata)) { + /* inform user about writer states */ int i; for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++) { - int msg_type = M_INFO; - if (g_pVSSClient->GetWriterState(i) < 1) { - msg_type = M_WARNING; - jcr->JobErrors++; - } if (g_pVSSClient->GetWriterState(i) < 1) { - Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PreRestore): %s\n"), g_pVSSClient->GetWriterInfo(i)); - jcr->JobErrors++; + Jmsg(jcr, M_INFO, 0, _("VSS Writer (PreRestore): %s\n"), g_pVSSClient->GetWriterInfo(i)); + //jcr->JobErrors++; } } } else { +/* + int fd = open("C:\\eric.xml", O_CREAT | O_WRONLY | O_TRUNC, 0777); + write(fd, (WCHAR *)jcr->job_metadata, wcslen((WCHAR *)jcr->job_metadata) * sizeof(WCHAR)); + close(fd); +*/ berrno be; Jmsg(jcr, M_WARNING, 0, _("VSS was not initialized properly. VSS support is disabled. ERR=%s\n"), be.bstrerror()); } @@ -2116,8 +2163,8 @@ static int restore_cmd(JCR *jcr) for (int i=0; i<(int)g_pVSSClient->GetWriterCount(); i++) { int msg_type = M_INFO; if (g_pVSSClient->GetWriterState(i) < 1) { - msg_type = M_WARNING; - jcr->JobErrors++; + //msg_type = M_WARNING; + //jcr->JobErrors++; } Jmsg(jcr, msg_type, 0, _("VSS Writer (RestoreComplete): %s\n"), g_pVSSClient->GetWriterInfo(i)); }