From 68df8dd9ff3d1368dedb168ccad12a3d3323ba10 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 10 Jul 2010 18:22:56 +0200 Subject: [PATCH] Make SD automatically fix the Volume size in the Catalog when out of sync --- bacula/src/stored/block.c | 8 ++++++++ bacula/src/stored/mount.c | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 83c70b2c02..9941e06b61 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -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)) { diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 4ad41861a5..6bb4eafb07 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -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"), -- 2.39.5