Baculas autolabeling feature is not fault-tolerant

When Bacula needs a new tape in a pool, it can automatically label a blank one and write to it afterwards. Unfourtunatley the database/catalog entry is created before the new tape is known to be labeled successfully. So it can happen, that when an unappropriate tape (e.g. already labeled, from another pool) is in the drive, bacula creates a catalog entry in the Media table for a new tape and waits forever to have that tape (which doesn’t really exist) to be mounted.

In this case you have to cancel the corresponding backup jobs and delete manually the catalog entry with the delete command in bconsole.Another interesting point is the algorithm how bacula calculates the new name for the volume/tape. Its is done In src/dird/newvol.c, function create_simple_name:

    for (int i=pr->NumVols+1; i<(int)pr->NumVols+11; i++) {
          MEDIA_DBR tmr;
          memset(&tmr, 0, sizeof(tmr));
          sprintf(num, "%04d", i);
          bstrncpy(tmr.VolumeName, name, sizeof(tmr.VolumeName));
          bstrncat(tmr.VolumeName, num, sizeof(tmr.VolumeName));
          if (db_get_media_record(jcr, jcr->db, &tmr)) {
             Jmsg(jcr, M_WARNING, 0,
                 _("Wanted to create Volume \"%s\", but it already exists. Trying again.\n"),
                 tmr.VolumeName);
             continue;
          }
          bstrncpy(mr->VolumeName, name, sizeof(mr->VolumeName));
          bstrncat(mr->VolumeName, num, sizeof(mr->VolumeName));
          break;                    /* Got good name */
       }
       if (mr->VolumeName[0] == 0) {
          Jmsg(jcr, M_ERROR, 0, _("Too many failures. Giving up creating Volume name.\n"));
          return false;
       }

It shows that you should never mix auto-created names like “Format-0001” with own names like “MyFavoriteTape” in a pool, because bacula uses the NumVols field of the pool and will generate then non sequential names like “Format-0003” instead of “Format-0002”. Also things get worse when you delete and add volumes in a pool, because bacula will only try the next 10 available numbers before failing.