From: Kern Sibbald Date: Mon, 7 Apr 2003 14:21:41 +0000 (+0000) Subject: Implement cleaning prefix X-Git-Tag: Release-1.30~40 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3f2ccea11cf36146acb593e34693bc2b121a13d4;p=bacula%2Fbacula Implement cleaning prefix git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@427 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index ae962c483e..a6ffa0a139 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -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, diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index ac4a71447a..afd306b1bf 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -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) { diff --git a/bacula/src/dird/dird_conf.h b/bacula/src/dird/dird_conf.h index 4cd6fba0bf..fc73409996 100644 --- a/bacula/src/dird/dird_conf.h +++ b/bacula/src/dird/dird_conf.h @@ -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 */ diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c index a27a844dd1..c967f92085 100644 --- a/bacula/src/dird/ua_label.c +++ b/bacula/src/dird/ua_label.c @@ -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; +}