]> git.sur5r.net Git - bacula/bacula/commitdiff
Make SD automatically fix the Volume size in the Catalog when out of sync
authorKern Sibbald <kern@sibbald.com>
Sat, 10 Jul 2010 16:22:56 +0000 (18:22 +0200)
committerKern Sibbald <kern@sibbald.com>
Sun, 11 Jul 2010 11:03:48 +0000 (13:03 +0200)
bacula/src/stored/block.c
bacula/src/stored/mount.c

index 83c70b2c02ca143161bff9018331afac5a790b77..9941e06b61424129fba800294a0162429ad64f02 100644 (file)
@@ -381,6 +381,9 @@ bool write_block_to_device(DCR *dcr)
 
    if (!write_block_to_dev(dcr)) {
        if (job_canceled(jcr) || jcr->getJobType() == JT_SYSTEM) {
+          if (jcr->getJobType() != JT_SYSTEM) {
+             terminate_writing_volume(dcr);
+          }
           stat = false;
        } else {
           stat = fixup_device_block_write_error(dcr);
@@ -416,6 +419,7 @@ bool write_block_to_dev(DCR *dcr)
    return true;
 #endif
    if (job_canceled(jcr)) {
+      terminate_writing_volume(dcr);
       return false;
    }
 
@@ -730,6 +734,10 @@ static bool terminate_writing_volume(DCR *dcr)
    DEVICE *dev = dcr->dev;
    bool ok = true;
 
+   if (dev->at_eot()) {
+      return true;
+  }
+
    /* Create a JobMedia record to indicated end of tape */
    dev->VolCatInfo.VolCatFiles = dev->file;
    if (!dir_create_jobmedia_record(dcr)) {
index 60d5d715625a301adf7b9c185615ab750e5bee72..456f074c659139f8fe3bfe25f9c08f19a04480ce 100644 (file)
@@ -613,6 +613,18 @@ bool DCR::is_eod_valid()
       if (dev->VolCatInfo.VolCatFiles == dev->get_file()) {
          Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\" at file=%d.\n"),
               VolumeName, dev->get_file());
+      } else if (dev->get_file() > dev->VolCatInfo.VolCatFiles) {
+         Jmsg(jcr, M_WARNING, 0, _("For Volume \"%s\":\n"
+              "The number of files mismatch! Volume=%u Catalog=%u\n"
+              "Correcting Catalog\n"),
+              VolumeName, dev->get_file(), dev->VolCatInfo.VolCatFiles);
+         dev->VolCatInfo.VolCatFiles = dev->get_file();
+         dev->VolCatInfo.VolCatBlocks = dev->get_block_num();
+         if (!dir_update_volume_info(this, false, true)) {
+            Jmsg(jcr, M_WARNING, 0, _("Error updating Catalog\n"));
+            mark_volume_in_error();
+            return false;
+         }
       } else {
          Jmsg(jcr, M_ERROR, 0, _("Bacula cannot write on tape Volume \"%s\" because:\n"
               "The number of files mismatch! Volume=%u Catalog=%u\n"),
@@ -628,6 +640,19 @@ bool DCR::is_eod_valid()
          Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\""
               " size=%s\n"), VolumeName, 
               edit_uint64(dev->VolCatInfo.VolCatBytes, ed1));
+      } else if ((uint64_t)pos > dev->VolCatInfo.VolCatBytes) {
+         Jmsg(jcr, M_WARNING, 0, _("For Volume \"%s\":\n"
+              "The sizes do not mismatch! Volume=%s Catalog=%s\n"
+              "Correcting Catalog\n"),
+              VolumeName, edit_uint64(pos, ed1), 
+              edit_uint64(dev->VolCatInfo.VolCatBytes, ed2));
+         dev->VolCatInfo.VolCatBytes = (uint64_t)pos;
+         dev->VolCatInfo.VolCatFiles = (uint32_t)(pos >> 32);
+         if (!dir_update_volume_info(this, false, true)) {
+            Jmsg(jcr, M_WARNING, 0, _("Error updating Catalog\n"));
+            mark_volume_in_error();
+            return false;
+         }
       } else {
          Mmsg(jcr->errmsg, _("Bacula cannot write on disk Volume \"%s\" because: "
               "The sizes do not match! Volume=%s Catalog=%s\n"),