]> git.sur5r.net Git - bacula/bacula/commitdiff
Implement cleaning prefix
authorKern Sibbald <kern@sibbald.com>
Mon, 7 Apr 2003 14:21:41 +0000 (14:21 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 7 Apr 2003 14:21:41 +0000 (14:21 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@427 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/make_mysql_tables.in
bacula/src/dird/dird_conf.c
bacula/src/dird/dird_conf.h
bacula/src/dird/ua_label.c

index ae962c483e0d3498ed3c36152397585f1be37ad1..a6ffa0a139a87749b904ed8a843f8c2946b869ef 100644 (file)
@@ -105,7 +105,7 @@ CREATE TABLE Media (
    MaxVolBytes BIGINT UNSIGNED NOT NULL,
    VolCapacityBytes BIGINT UNSIGNED NOT NULL,
    VolStatus ENUM('Full', 'Archive', 'Append', 'Recycle', 'Purged',
-    'Read-Only', 'Disabled', 'Error', 'Busy', 'Used') NOT NULL,
+    'Read-Only', 'Disabled', 'Error', 'Busy', 'Used', 'Cleaning') NOT NULL,
    Recycle TINYINT NOT NULL,
    VolRetention BIGINT UNSIGNED NOT NULL,
    VolUseDuration BIGINT UNSIGNED NOT NULL,
index ac4a71447ac203280b117cb1e50d2a44ada55616..afd306b1bf6d478a68fd192e43e60c9733b64597 100644 (file)
@@ -240,6 +240,7 @@ static struct res_items pool_items[] = {
    {"description",     store_str,     ITEM(res_pool.hdr.desc),      0, 0,     0},
    {"pooltype",        store_strname, ITEM(res_pool.pool_type),     0, ITEM_REQUIRED, 0},
    {"labelformat",     store_strname, ITEM(res_pool.label_format),  0, 0,     0},
+   {"cleaningprefix",  store_strname, ITEM(res_pool.cleaning_prefix),  0, 0,     0},
    {"usecatalog",      store_yesno, ITEM(res_pool.use_catalog),     1, ITEM_DEFAULT,  1},
    {"usevolumeonce",   store_yesno, ITEM(res_pool.use_volume_once), 1, 0,        0},
    {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
@@ -576,6 +577,8 @@ next_run:
                 res->res_pool.VolRetention);
          sendit(sock, "      recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
                 NPRT(res->res_pool.label_format));
+         sendit(sock, "      CleaningPrefix=%s\n",
+                NPRT(res->res_pool.cleaning_prefix));
          sendit(sock, "      recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
                 res->res_pool.recycle_oldest_volume, 
                 res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
@@ -737,6 +740,9 @@ void free_resource(int type)
         if (res->res_pool.label_format) {
            free(res->res_pool.label_format);
         }
+        if (res->res_pool.cleaning_prefix) {
+           free(res->res_pool.cleaning_prefix);
+        }
         break;
       case R_SCHEDULE:
         if (res->res_sch.run) {
index 4cd6fba0bf2fbc4b60a1a26c5f8ac4c8c928bef7..fc73409996357da7d34b52e065138971f28971a4 100644 (file)
@@ -271,6 +271,7 @@ struct s_res_pool {
    struct s_res_counter counter;      /* Counter resources */
    char *pool_type;                   /* Pool type */
    char *label_format;                /* Label format string */
+   char *cleaning_prefix;             /* Cleaning label prefix */
    int   use_catalog;                 /* maintain catalog for media */
    int   catalog_files;               /* maintain file entries in catalog */
    int   use_volume_once;             /* write on volume only once */
index a27a844dd1f4b483276f0ae2817732f831e834b7..c967f920858c30301205b6474fbc6fb4eeaa9973 100644 (file)
@@ -45,6 +45,7 @@ static int is_legal_volume_name(UAContext *ua, char *name);
 static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr, 
               POOL_DBR *pr, int relabel);
 static vol_list_t *get_slot_list_from_SD(UAContext *ua);
+static int is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr);
 
 
 /*
@@ -310,7 +311,6 @@ static void label_from_barcodes(UAContext *ua)
 
    vol_list = get_slot_list_from_SD(ua);
 
-
    if (!vol_list) {
       bsendmsg(ua, _("No Volumes found to label, or no barcodes.\n"));
       goto bail_out;
@@ -344,6 +344,16 @@ static void label_from_barcodes(UAContext *ua)
             vl->Slot, mr.VolumeName);
          continue;
       }
+      if (is_cleaning_tape(ua, &mr, &pr)) {
+        set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
+        if (db_create_media_record(ua->jcr, ua->db, &mr)) {
+            bsendmsg(ua, _("Catalog record for cleaning tape \"%s\" successfully created.\n"),
+              mr.VolumeName);
+        } else {
+            bsendmsg(ua, "Catalog error on cleaning tape: %s", db_strerror(ua->db));
+        }
+        continue;
+      }
       bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
       if (ua->jcr->store_bsock) {
         bnet_sig(ua->jcr->store_bsock, BNET_TERMINATE);
@@ -423,7 +433,8 @@ static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
    } else {
       bnet_fsend(sd, _("label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d"), 
         dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
-      bsendmsg(ua, _("Sending label command for Volume \"%s\" ...\n"), mr->VolumeName);
+      bsendmsg(ua, _("Sending label command for Volume \"%s\" Slot %d ...\n"), 
+        mr->VolumeName, mr->Slot);
       Dmsg5(200, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d\n", 
         dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
    }
@@ -441,8 +452,8 @@ static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
    if (ok) {
       set_pool_dbr_defaults_in_media_dbr(mr, pr);
       if (db_create_media_record(ua->jcr, ua->db, mr)) {
-         bsendmsg(ua, _("Media record for Volume \"%s\" successfully created.\n"),
-           mr->VolumeName);
+         bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d  successfully created.\n"),
+           mr->VolumeName, mr->Slot);
       } else {
          bsendmsg(ua, "%s", db_strerror(ua->db));
         ok = FALSE;
@@ -524,3 +535,25 @@ static vol_list_t *get_slot_list_from_SD(UAContext *ua)
    }
    return vol_list;
 }
+
+/*
+ * Check if this is a cleaning tape by comparing the Volume name
+ *  with the Cleaning Prefix. If they match, this is a cleaning 
+ *  tape.
+ */
+static int is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
+{
+   if (!ua->jcr->pool) {
+      /* Find Pool resource */
+      ua->jcr->pool = (POOL *)GetResWithName(R_POOL, pr->Name);
+      if (!ua->jcr->pool) {
+         bsendmsg(ua, _("Pool %s resource not found!\n"), pr->Name);
+        return 1;
+      }
+   }
+   if (ua->jcr->pool->cleaning_prefix == NULL) {
+      return 0;
+   }
+   return strncmp(mr->VolumeName, ua->jcr->pool->cleaning_prefix,
+                 strlen(ua->jcr->pool->cleaning_prefix)) == 0;
+}