]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/job.c
Stop restore if job is canceled
[bacula/bacula] / bacula / src / filed / job.c
index 502d11439bbfa4720bec558a4904a7401948e6b6..41b9c11c2d12092a5890c21c75a86356edae4242 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
 
    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.
@@ -30,8 +30,6 @@
  *
  *    Kern Sibbald, October MM
  *
- *   Version $Id$
- *
  */
 
 #include "bacula.h"
@@ -92,6 +90,10 @@ static int runafter_cmd(JCR *jcr);
 static int runbeforenow_cmd(JCR *jcr);
 static void 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 +128,10 @@ static struct s_cmds cmds[] = {
    {"RunAfterJob",  runafter_cmd,  0},
    {"Run",          runscript_cmd, 0},
    {"accurate",     accurate_cmd,  0},
+   {"sm_dump",      sm_dump_cmd, 0},
+#ifdef DEVELOPER
+   {"exit",         exit_cmd, 0},
+#endif
    {NULL,       NULL}                  /* list terminator */
 };
 
@@ -342,13 +348,13 @@ void *handle_client_request(void *dirp)
             fo->base.destroy();
             fo->fstype.destroy();
             fo->drivetype.destroy();
-            if (fo->ignoredir != NULL) {
-               free(fo->ignoredir);
-            }
          }
          incexe->opts_list.destroy();
          incexe->name_list.destroy();
          incexe->plugin_list.destroy();
+         if (incexe->ignoredir) {
+            free(incexe->ignoredir);
+         }
       }
       fileset->include_list.destroy();
 
@@ -371,6 +377,9 @@ void *handle_client_request(void *dirp)
          incexe->opts_list.destroy();
          incexe->name_list.destroy();
          incexe->plugin_list.destroy();
+         if (incexe->ignoredir) {
+            free(incexe->ignoredir);
+         }
       }
       fileset->exclude_list.destroy();
       free(fileset);
@@ -383,10 +392,29 @@ 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.
  */
@@ -417,7 +445,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);
@@ -661,8 +689,8 @@ static findFOPTS *start_options(FF_PKT *ff)
  * Add fname to include/exclude fileset list. First check for
  * | and < and if necessary perform command.
  */
-static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset,
-                                bool is_file)
+void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset,
+                         bool is_file)
 {
    char *p;
    BPIPE *bpipe;
@@ -738,6 +766,21 @@ static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *filese
    }
 }
 
+findFILESET *new_exclude(JCR *jcr)
+{
+   FF_PKT *ff = jcr->ff;
+   findFILESET *fileset = ff->fileset;
+
+   /* New exclude */
+   fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
+   memset(fileset->incexe, 0, sizeof(findINCEXE));
+   fileset->incexe->opts_list.init(1, true);
+   fileset->incexe->name_list.init();
+   fileset->incexe->plugin_list.init();
+   fileset->exclude_list.append(fileset->incexe);
+   return fileset;
+}
+
 
 static void add_fileset(JCR *jcr, const char *item)
 {
@@ -788,13 +831,7 @@ static void add_fileset(JCR *jcr, const char *item)
       fileset->include_list.append(fileset->incexe);
       break;
    case 'E':
-      /* New exclude */
-      fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
-      memset(fileset->incexe, 0, sizeof(findINCEXE));
-      fileset->incexe->opts_list.init(1, true);
-      fileset->incexe->name_list.init();
-      fileset->incexe->plugin_list.init();
-      fileset->exclude_list.append(fileset->incexe);
+      fileset = new_exclude(jcr);
       break;
    case 'N':
       state = state_none;
@@ -876,9 +913,8 @@ static void add_fileset(JCR *jcr, const char *item)
       state = state_options;
       break;
    case 'Z':
-      current_opts = start_options(ff);
-      current_opts->ignoredir = bstrdup(item);
-      state = state_options;
+      state = state_include;
+      fileset->incexe->ignoredir = bstrdup(item);
       break;
    case 'D':
       current_opts = start_options(ff);
@@ -941,9 +977,9 @@ static bool term_fileset(JCR *jcr)
          for (k=0; k<fo->drivetype.size(); k++) {
             Dmsg1(400, "XD %s\n", (char *)fo->drivetype.get(k));
          }
-         if (fo->ignoredir) {
-            Dmsg1(400, "Z %s\n", fo->ignoredir);
-         }
+      }
+      if (incexe->ignoredir) {
+         Dmsg1(400, "Z %s\n", incexe->ignoredir);
       }
       dlistString *node;
       foreach_dlist(node, &incexe->name_list) {
@@ -1112,6 +1148,16 @@ static void set_options(findFOPTS *fo, const char *opts)
          }
          fo->AccurateOpts[j] = 0;
          break;
+      case 'J':                  /* Basejob options */
+         /* Copy BaseJob Options */
+         for (j=0; *p && *p != ':'; p++) {
+            fo->BaseJobOpts[j] = *p;
+            if (j < (int)sizeof(fo->BaseJobOpts) - 1) {
+               j++;
+            }
+         }
+         fo->BaseJobOpts[j] = 0;
+         break;
       case 'P':                  /* strip path */
          /* Get integer */
          p++;                    /* skip P */
@@ -1286,7 +1332,7 @@ static int level_cmd(JCR *jcr)
       buf = get_memory(dir->msglen+1);
       utime_t since_time, adj;
       btime_t his_time, bt_start, rt=0, bt_adj=0;
-      if (jcr->get_JobLevel() == L_NONE) {
+      if (jcr->getJobLevel() == L_NONE) {
          jcr->set_JobLevel(L_SINCE);     /* if no other job level set, do it now */
       }
       if (sscanf(dir->msg, "level = since_utime %s mtime_only=%d",
@@ -1349,7 +1395,7 @@ static int level_cmd(JCR *jcr)
    if (buf) {
       free_memory(buf);
    }
-   generate_plugin_event(jcr, bEventLevel, (void *)jcr->get_JobLevel());
+   generate_plugin_event(jcr, bEventLevel, (void *)jcr->getJobLevel());
    return dir->fsend(OKlevel);
 
 bail_out:
@@ -1574,8 +1620,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;
@@ -1716,12 +1762,12 @@ static int verify_cmd(JCR *jcr)
    dir->fsend(OKverify);
 
    generate_daemon_event(jcr, "JobStart");
-   generate_plugin_event(jcr, bEventLevel, (void *)jcr->get_JobLevel());
+   generate_plugin_event(jcr, bEventLevel, (void *)jcr->getJobLevel());
    generate_plugin_event(jcr, bEventStartVerifyJob);
 
    Dmsg1(110, "filed>dird: %s", dir->msg);
 
-   switch (jcr->get_JobLevel()) {
+   switch (jcr->getJobLevel()) {
    case L_VERIFY_INIT:
    case L_VERIFY_CATALOG:
       do_verify(jcr);
@@ -1871,6 +1917,10 @@ bail_out:
       ret = 0;     /* we stop here */
    }
 
+   if (job_canceled(jcr)) {
+      ret = 0;     /* we stop here */
+   }
+
    return ret;
 }