]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/next_vol.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / dird / next_vol.c
index 043fd1ac93ad646d07b9e53c5630432b3853a7bf..a27a0ad865b9f9e76df73a20dfd78928c49be2c7 100644 (file)
@@ -69,6 +69,9 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int create)
            }
         }
 
+        /* 
+          * Don't do a purge if called from a command i.e. create == 0.
+         */ 
         if (!ok && (jcr->pool->purge_oldest_volume ||
                     jcr->pool->recycle_oldest_volume)) {
             Dmsg2(200, "No next volume found. PurgeOldest=%d\n RecyleOldest=%d",
@@ -81,10 +84,10 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int create)
                Dmsg0(400, "Try purge.\n");
               /* Try to purge oldest volume */
               ua = new_ua_context(jcr);
-              if (jcr->pool->purge_oldest_volume) {
+              if (jcr->pool->purge_oldest_volume && create) {
                   Jmsg(jcr, M_INFO, 0, _("Purging oldest volume \"%s\"\n"), mr->VolumeName);
                  ok = purge_jobs_from_volume(ua, mr);
-              } else {
+              } else if (jcr->pool->recycle_oldest_volume) {
                   Jmsg(jcr, M_INFO, 0, _("Pruning oldest volume \"%s\"\n"), mr->VolumeName);
                  ok = prune_volume(ua, mr);
               }
@@ -100,11 +103,6 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int create)
       if (ok) {
         /* If we can use the volume, check if it is expired */
         if (has_volume_expired(jcr, mr)) {
-           /* Need to update media */
-           if (!db_update_media_record(jcr, jcr->db, mr)) {
-               Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
-                   mr->VolumeName, db_strerror(jcr->db));
-           }           
            if (retry++ < 200) {            /* sanity check */
               continue;                    /* try again from the top */
            } else {
@@ -172,6 +170,13 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr)
         }
       }
    }
+   if (expired) {
+      /* Need to update media */
+      if (!db_update_media_record(jcr, jcr->db, mr)) {
+         Jmsg(jcr, M_ERROR, 0, _("Catalog error updating volume \"%s\". ERR=%s"),
+             mr->VolumeName, db_strerror(jcr->db));
+      }          
+   }  
    return expired;
 }
 
@@ -181,39 +186,44 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr)
  *  Returns: on failure - reason = NULL
  *          on success - reason - pointer to reason
  */
-bool is_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, char **reason)
+void check_if_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, char **reason)
 {
    int ok;
 
    *reason = NULL;
 
    /*  Check if a duration or limit has expired */
-   has_volume_expired(jcr, mr);
+   if (has_volume_expired(jcr, mr)) {
+      *reason = "volume has expired";
+      /* Keep going because we may be able to recycle volume */
+   }
 
    /*
     * Now see if we can use the volume as is
     */
    if (strcmp(mr->VolStatus, "Append") == 0 ||
        strcmp(mr->VolStatus, "Recycle") == 0) {
-      return true;
+      *reason = NULL;
+      return;
    }
                                                                                        
    /*
-    * Check if the Volume is alreay marked for recycling
+    * Check if the Volume is already marked for recycling
     */
    if (strcmp(mr->VolStatus, "Purged") == 0) {
       if (recycle_volume(jcr, mr)) {
          Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
-        return true;
+        *reason = NULL;
+        return;
       } else {
          /* In principle this shouldn't happen */
-         *reason = "recycling of current volume failed";
-        return false;
+         *reason = "and recycling of current volume failed";
+        return;
       }
    }
                                                                                        
    /* At this point, the volume is not valid for writing */
-   *reason = "not Append, Purged or Recycle";
+   *reason = "but should be Append, Purged or Recycle";
                                                                                        
    /*
     * What we're trying to do here is see if the current volume is
@@ -239,15 +249,14 @@ bool is_volume_valid_or_recyclable(JCR *jcr, MEDIA_DBR *mr, char **reason)
         /* If fully purged, recycle current volume */
         if (recycle_volume(jcr, mr)) {
             Jmsg(jcr, M_INFO, 0, "Recycled current volume \"%s\"\n", mr->VolumeName);
-           return true;               /* Good volume */
+           *reason = NULL;
         } else {
-            *reason = "not Append, Purged or Recycle (recycling of the "
+            *reason = "but should be Append, Purged or Recycle (recycling of the "
                "current volume failed)";
         }
       } else {
-         *reason = "not Append, Purged or Recycle (cannot automatically "
+         *reason = "but should be Append, Purged or Recycle (cannot automatically "
             "recycle current volume, as it still contains unpruned data)";
       }
    }
-   return *reason ? false : true;
 }