]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/restore.c
update configure
[bacula/bacula] / bacula / src / dird / restore.c
index ec40ef9f2f7c0f2dbdc662c41e8dd27a42bc431d..a04e1ac3bdef119c05c01f741092b1c5d546159d 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 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.
@@ -119,7 +119,7 @@ struct bootstrap_info
  * it should be used for next operations, and need to be closed
  * at the end.
  */
-static bool open_bootstrap_file(JCR *jcr, struct bootstrap_info &info)
+static bool open_bootstrap_file(JCR *jcr, bootstrap_info &info)
 {
    FILE *bs;
    UAContext *ua;
@@ -136,7 +136,7 @@ static bool open_bootstrap_file(JCR *jcr, struct bootstrap_info &info)
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
          jcr->RestoreBootstrap, be.bstrerror());
-      set_jcr_job_status(jcr, JS_ErrorTerminated);
+      jcr->setJobStatus(JS_ErrorTerminated);
       return false;
    }
 
@@ -171,7 +171,7 @@ static bool is_on_same_storage(JCR *jcr, char *new_one)
    if (jcr->FDVersion < 2) {
       return true;
    }
-   /* we are in init loop ? shoudn't fall here */
+   /* we are in init loop ? shoudn't fail here */
    if (!*new_one) {
       return true;
    }
@@ -181,9 +181,8 @@ static bool is_on_same_storage(JCR *jcr, char *new_one)
    }
    new_store = (STORE *)GetResWithName(R_STORAGE, new_one);
    if (!new_store) {
-      Jmsg(jcr, M_FATAL, 0,
+      Jmsg(jcr, M_WARNING, 0,
            _("Could not get storage resource '%s'.\n"), new_one);
-      set_jcr_job_status(jcr, JS_ErrorTerminated);
       return false;
    }
    /* if Port and Hostname/IP are same, we are talking to the same
@@ -205,7 +204,7 @@ static bool is_on_same_storage(JCR *jcr, char *new_one)
  * Returns true if we need to change the storage, and it set the new
  * Storage resource name in "storage" arg. 
  */
-static bool check_for_new_storage(JCR *jcr, struct bootstrap_info &info)
+static bool check_for_new_storage(JCR *jcr, bootstrap_info &info)
 {
    UAContext *ua = info.ua;
    parse_ua_args(ua);
@@ -229,7 +228,7 @@ static bool check_for_new_storage(JCR *jcr, struct bootstrap_info &info)
  * Send bootstrap file to Storage daemon section by section.
  */
 static bool send_bootstrap_file(JCR *jcr, BSOCK *sock,
-                                struct bootstrap_info &info)
+                                bootstrap_info &info)
 {
    boffset_t pos;
    const char *bootstrap = "bootstrap\n";
@@ -257,37 +256,69 @@ static bool send_bootstrap_file(JCR *jcr, BSOCK *sock,
    return true;
 }
 
+#define MAX_TRIES 6 * 360   /* 6 hours */
+
 /**
  * Change the read storage resource for the current job.
  */
-static void select_rstore(JCR *jcr, struct bootstrap_info &info)
+static bool select_rstore(JCR *jcr, bootstrap_info &info)
 {
    USTORE ustore;
+   int i;
+
 
    if (!strcmp(jcr->rstore->name(), info.storage)) {
-      return;
+      return true;                 /* same SD nothing to change */
    }
 
    if (!(ustore.store = (STORE *)GetResWithName(R_STORAGE,info.storage))) {
       Jmsg(jcr, M_FATAL, 0,
            _("Could not get storage resource '%s'.\n"), info.storage);
-      set_jcr_job_status(jcr, JS_ErrorTerminated);
-      return;
+      jcr->setJobStatus(JS_ErrorTerminated);
+      return false;
    }
    
+   /*
+    * What does this do???????????  KES
+    */
    if (jcr->store_bsock) {
       jcr->store_bsock->destroy();
       jcr->store_bsock = NULL;
    }
    
+   /*
+    * release current read storage and get a new one 
+    */
+   dec_read_store(jcr);
    free_rstorage(jcr);
    set_rstorage(jcr, &ustore);
+   jcr->setJobStatus(JS_WaitSD);
+   /*
+    * Wait for up to 6 hours to increment read stoage counter 
+    */
+   for (i=0; i < MAX_TRIES; i++) {
+      /* try to get read storage counter incremented */
+      if (inc_read_store(jcr)) {
+         jcr->setJobStatus(JS_Running);
+         return true;
+      }
+      bmicrosleep(10, 0);       /* sleep 10 secs */
+      if (job_canceled(jcr)) {
+         free_rstorage(jcr);
+         return false;
+      }
+   }
+   /* Failed to inc_read_store() */
+   free_rstorage(jcr);
+   Jmsg(jcr, M_FATAL, 0, 
+      _("Could not acquire read storage lock for \"%s\""), info.storage);
+   return false;
 }
 
 /* 
- * Clean the struct bootstrap_info struct
+ * Clean the bootstrap_info struct
  */
-static void close_bootstrap_file(struct bootstrap_info &info)
+static void close_bootstrap_file(bootstrap_info &info)
 {
    if (info.bs) {
       fclose(info.bs);
@@ -311,7 +342,7 @@ bool restore_bootstrap(JCR *jcr)
    BSOCK *fd = NULL;
    BSOCK *sd;
    bool first_time = true;
-   struct bootstrap_info info;
+   bootstrap_info info;
    POOL_MEM restore_cmd(PM_MESSAGE);
    bool ret = false;
 
@@ -325,7 +356,9 @@ bool restore_bootstrap(JCR *jcr)
    /* Read the bootstrap file */
    while (!feof(info.bs)) {
       
-      select_rstore(jcr, info);
+      if (!select_rstore(jcr, info)) {
+         goto bail_out;
+      }
 
       /**
        * Open a message channel connection with the Storage
@@ -334,7 +367,7 @@ bool restore_bootstrap(JCR *jcr)
        *
        */
       Dmsg0(10, "Open connection with storage daemon\n");
-      set_jcr_job_status(jcr, JS_WaitSD);
+      jcr->setJobStatus(JS_WaitSD);
       /*
        * Start conversation with Storage daemon
        */
@@ -353,7 +386,7 @@ bool restore_bootstrap(JCR *jcr)
          /*
           * Start conversation with File daemon
           */
-         set_jcr_job_status(jcr, JS_WaitFD);
+         jcr->setJobStatus(JS_WaitFD);
          jcr->keep_sd_auth_key = true; /* don't clear the sd_auth_key now */
          if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) {
             goto bail_out;
@@ -361,7 +394,7 @@ bool restore_bootstrap(JCR *jcr)
          fd = jcr->file_bsock;
       }
 
-      set_jcr_job_status(jcr, JS_WaitSD);
+      jcr->setJobStatus(JS_WaitSD);
 
       /*
        * Send the bootstrap file -- what Volumes/files to restore
@@ -572,7 +605,7 @@ void restore_cleanup(JCR *jcr, int TermCode)
    jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
    jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));
 
-   Jmsg(jcr, msg_type, 0, _("%s %s %s (%s): %s\n"
+   Jmsg(jcr, msg_type, 0, _("%s %s %s (%s):\n"
 "  Build OS:               %s %s %s\n"
 "  JobId:                  %d\n"
 "  Job:                    %s\n"
@@ -587,7 +620,7 @@ void restore_cleanup(JCR *jcr, int TermCode)
 "  FD termination status:  %s\n"
 "  SD termination status:  %s\n"
 "  Termination:            %s\n\n"),
-        BACULA, my_name, VERSION, LSMDATE, edt,
+        BACULA, my_name, VERSION, LSMDATE,
         HOST_OS, DISTNAME, DISTVER,
         jcr->jr.JobId,
         jcr->jr.Job,