/* Forward referenced functions */
static void do_scan(void);
-static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
+static bool record_cb(DCR *dcr, DEV_RECORD *rec);
static int create_file_attributes_record(B_DB *db, JCR *mjcr,
char *fname, char *lname, int type,
char *ap, DEV_RECORD *rec);
static bool list_records = false;
static int ignored_msgs = 0;
+static uint64_t currentVolumeSize;
+static int64_t last_pct = -1;
+static bool showProgress = false;
static int num_jobs = 0;
static int num_pools = 0;
static int num_media = 0;
static void usage()
{
fprintf(stderr, _(
+"Copyright (C) 2001-2004 Kern Sibbald and John Walker.\n"
"\nVersion: " VERSION " (" BDATE ")\n\n"
"Usage: bscan [ options ] <bacula-archive>\n"
" -b bootstrap specify a bootstrap file\n"
init_msg(NULL, NULL);
- while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsu:vV:w:?")) != -1) {
+ while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsSu:vV:w:?")) != -1) {
switch (ch) {
+ case 'S' :
+ showProgress = true;
+ break;
case 'b':
bsr = parse_bsr(NULL, optarg);
break;
working_directory);
}
- bjcr = setup_jcr("bscan", argv[0], bsr, VolumeName);
- dev = setup_to_access_device(bjcr, 1); /* read device */
- if (!dev) {
+ bjcr = setup_jcr("bscan", argv[0], bsr, VolumeName, 1); /* read device */
+ if (!bjcr) {
exit(1);
}
+ dev = bjcr->dcr->dev;
+ if (showProgress) {
+ struct stat sb;
+ fstat(dev->fd, &sb);
+ currentVolumeSize = sb.st_size;
+ Pmsg1(000, _("Current Volume Size = %" llu "\n"), currentVolumeSize);
+ }
- if ((db=db_init_database(NULL, db_name, db_user, db_password, db_host, 0, NULL)) == NULL) {
+ if ((db=db_init_database(NULL, db_name, db_user, db_password,
+ db_host, 0, NULL, 0)) == NULL) {
Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
}
if (!db_open_database(NULL, db)) {
num_media, num_pools, num_jobs, num_files);
free_jcr(bjcr);
+ term_dev(dev);
return 0;
}
* the end of writing a tape by wiffling through the attached
* jcrs creating jobmedia records.
*/
-static bool bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
+static bool bscan_mount_next_read_volume(DCR *dcr)
{
+ DEVICE *dev = dcr->dev;
+ DCR *mdcr;
Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
- for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
- DCR *dcr = mjcr->dcr;
+ foreach_dlist(mdcr, dev->attached_dcrs) {
+ JCR *mjcr = mdcr->jcr;
+ if (mjcr->JobId == 0) {
+ continue;
+ }
if (verbose) {
Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
}
if (dev->state & ST_TAPE) {
- dcr->EndBlock = dev->EndBlock;
- dcr->EndFile = dev->EndFile;
+ mdcr->EndBlock = dev->EndBlock;
+ mdcr->EndFile = dev->EndFile;
} else {
- dcr->EndBlock = (uint32_t)dev->file_addr;
- dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+ mdcr->EndBlock = (uint32_t)dev->file_addr;
+ mdcr->EndFile = (uint32_t)(dev->file_addr >> 32);
}
if (!create_jobmedia_record(db, mjcr)) {
Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"),
* we call mount_next... with bscan's jcr because that is where we
* have the Volume list, but we get attached.
*/
- bool stat = mount_next_read_volume(jcr, dev, block);
- /* we must once more detach ourselves (attached by mount_next ...) */
- detach_jcr_from_device(dev, jcr); /* detach bscan jcr */
+ bool stat = mount_next_read_volume(dcr);
+
+ if (showProgress) {
+ struct stat sb;
+ fstat(dev->fd, &sb);
+ currentVolumeSize = sb.st_size;
+ Pmsg1(000, _("Current Volume Size = %" llu "\n"), currentVolumeSize);
+ }
return stat;
}
memset(&fr, 0, sizeof(fr));
/* Detach bscan's jcr as we are not a real Job on the tape */
- detach_jcr_from_device(dev, bjcr);
- read_records(bjcr, dev, record_cb, bscan_mount_next_read_volume);
- release_device(bjcr);
+ read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume);
free_attr(attr);
- term_dev(dev);
}
/*
- * Returns: true if OK
+ * Returns: true if OK
* false if error
*/
-static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
+static bool record_cb(DCR *dcr, DEV_RECORD *rec)
{
JCR *mjcr;
- DCR *dcr;
char ec1[30];
+ DEVICE *dev = dcr->dev;
+ JCR *bjcr = dcr->jcr;
+ DEV_BLOCK *block = dcr->block;
if (rec->data_len > 0) {
mr.VolBytes += rec->data_len + WRITE_RECHDR_LENGTH; /* Accumulate Volume bytes */
+ if (showProgress) {
+ int64_t pct = (mr.VolBytes * 100) / currentVolumeSize;
+ if (pct != last_pct) {
+ fprintf(stdout, "done: %" lld "\n", pct);
+ fflush(stdout);
+ last_pct = pct;
+ }
+ }
}
+
if (list_records) {
Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"),
rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
}
/* Reset some JCR variables */
- for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
- dcr = mjcr->dcr;
+ foreach_dlist(dcr, dev->attached_dcrs) {
dcr->VolFirstIndex = dcr->FileIndex = 0;
dcr->StartBlock = dcr->EndBlock = 0;
dcr->StartFile = dcr->EndFile = 0;
}
unser_session_label(&label, rec);
memset(&jr, 0, sizeof(jr));
- jr.JobId = label.JobId;
+ bstrncpy(jr.Job, label.Job, sizeof(jr.Job));
if (db_get_job_record(bjcr, db, &jr)) {
/* Job record already exists in DB */
update_db = false; /* don't change db in create_job_record */
mjcr->JobLevel = jr.JobLevel;
mjcr->client_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->client_name, label.ClientName);
- mjcr->pool_type = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->pool_type, label.PoolType);
+ pm_strcpy(mjcr->client_name, label.ClientName);
mjcr->fileset_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->fileset_name, label.FileSetName);
- mjcr->pool_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&mjcr->pool_name, label.PoolName);
+ pm_strcpy(mjcr->fileset_name, label.FileSetName);
+ bstrncpy(dcr->pool_type, label.PoolType, sizeof(dcr->pool_type));
+ bstrncpy(dcr->pool_name, label.PoolName, sizeof(dcr->pool_name));
if (rec->VolSessionId != jr.VolSessionId) {
Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
/* Create JobMedia record */
create_jobmedia_record(db, mjcr);
- detach_jcr_from_device(dev, mjcr);
+ dev->attached_dcrs->remove(mjcr->dcr);
free_jcr(mjcr);
break;
* them.
*/
if (update_db) {
- mjcr=next_attached_jcr(dev, NULL);
- for ( ; mjcr; ) {
- JCR *njcr;
+ DCR *mdcr;
+ foreach_dlist(mdcr, dev->attached_dcrs) {
+ JCR *mjcr = mdcr->jcr;
+ if (!mjcr || mjcr->JobId == 0) {
+ continue;
+ }
jr.JobId = mjcr->JobId;
+ /* Mark Job as Error Terimined */
jr.JobStatus = JS_ErrorTerminated;
jr.JobFiles = mjcr->JobFiles;
jr.JobBytes = mjcr->JobBytes;
if (!db_update_job_end_record(bjcr, db, &jr)) {
Pmsg1(0, _("Could not update job record. ERR=%s\n"), db_strerror(db));
}
- njcr = mjcr->next_dev;
+ mjcr->dcr = NULL;
free_jcr(mjcr);
- mjcr = njcr;
}
}
mr.VolFiles = rec->File;
edit_uint64_with_commas(rec->Block, ed3),
edit_uint64_with_commas(mr.VolBytes, ed4));
}
- if (db_get_file_attributes_record(bjcr, db, attr->fname, NULL, &fr)) {
- if (verbose > 1) {
- Pmsg1(000, _("File record already exists for: %s\n"), attr->fname);
- }
- } else {
- create_file_attributes_record(db, mjcr, attr->fname, attr->lname,
+ create_file_attributes_record(db, mjcr, attr->fname, attr->lname,
attr->type, attr->attr, rec);
- }
free_jcr(mjcr);
break;
return 0;
}
if (verbose) {
- Pmsg1(000, _("Updated Job termination record for new JobId=%u\n"), jr->JobId);
+ Pmsg2(000, _("Updated Job termination record for JobId=%u TermStat=%c\n"), jr->JobId,
+ jr->JobStatus);
}
if (verbose > 1) {
const char *term_msg;
return 0;
}
- if (!update_db) {
+ if (!update_db || mjcr->FileId == 0) {
free_jcr(mjcr);
return 1;
}
jobjcr->VolSessionId = rec->VolSessionId;
jobjcr->VolSessionTime = rec->VolSessionTime;
jobjcr->ClientId = jr->ClientId;
- attach_jcr_to_device(dev, jobjcr);
+// attach_jcr_to_device(dev, jobjcr);
new_dcr(jobjcr, dev);
return jobjcr;
}
/* Dummies to replace askdir.c */
-bool dir_get_volume_info(JCR *jcr, enum get_vol_info_rw writing) { return 1;}
-bool dir_find_next_appendable_volume(JCR *jcr) { return 1;}
-bool dir_update_volume_info(JCR *jcr, bool relabel) { return 1; }
-bool dir_create_jobmedia_record(JCR *jcr) { return 1; }
-bool dir_ask_sysop_to_create_appendable_volume(JCR *jcr) { return 1; }
-bool dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;}
+bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { return 1;}
+bool dir_find_next_appendable_volume(DCR *dcr) { return 1;}
+bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; }
+bool dir_create_jobmedia_record(DCR *dcr) { return 1; }
+bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; }
+bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;}
bool dir_send_job_status(JCR *jcr) {return 1;}
-bool dir_ask_sysop_to_mount_volume(JCR *jcr)
+bool dir_ask_sysop_to_mount_volume(DCR *dcr)
{
- DEVICE *dev = jcr->dcr->dev;
+ DEVICE *dev = dcr->dev;
+ JCR *jcr = dcr->jcr;
fprintf(stderr, _("Mount Volume \"%s\" on device \"%s\" and press return when ready: "),
jcr->VolumeName, dev_name(dev));
getchar();