/* Forward referenced functions */
static void do_scan(void);
-static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
+static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, 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 int create_media_record(B_DB *db, MEDIA_DBR *mr, VOLUME_LABEL *vl);
-static int update_media_record(B_DB *db, MEDIA_DBR *mr);
+static bool update_media_record(B_DB *db, MEDIA_DBR *mr);
static int create_pool_record(B_DB *db, POOL_DBR *pr);
static JCR *create_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *label, DEV_RECORD *rec);
static int update_job_record(B_DB *db, JOB_DBR *mr, SESSION_LABEL *elabel,
static time_t lasttime = 0;
-static char *db_name = "bacula";
-static char *db_user = "bacula";
-static char *db_password = "";
-static char *db_host = NULL;
-static char *wd = NULL;
-static int update_db = 0;
-static int update_vol_info = 0;
-static int list_records = 0;
+static const char *db_name = "bacula";
+static const char *db_user = "bacula";
+static const char *db_password = "";
+static const char *db_host = NULL;
+static const char *wd = NULL;
+static bool update_db = false;
+static bool update_vol_info = false;
+static bool list_records = false;
static int ignored_msgs = 0;
+static int num_jobs = 0;
+static int num_pools = 0;
+static int num_media = 0;
+static int num_files = 0;
+
#define CONFIG_FILE "bacula-sd.conf"
char *configfile;
-
+bool forge_on = false;
static void usage()
{
fprintf(stderr, _(
"\nVersion: " VERSION " (" BDATE ")\n\n"
-"Usage: bscan [-d debug_level] <bacula-archive>\n"
+"Usage: bscan [ options ] <bacula-archive>\n"
" -b bootstrap specify a bootstrap file\n"
" -c <file> specify configuration file\n"
" -d <nn> set debug level to nn\n"
" -m update media info in database\n"
" -n <name> specify the database name (default bacula)\n"
" -u <user> specify database user name (default bacula)\n"
-" -p <password specify database password (default none)\n"
+" -P <password specify database password (default none)\n"
" -h <host> specify database host (default NULL)\n"
+" -p proceed inspite of I/O errors\n"
" -r list records\n"
" -s synchronize or store in database\n"
" -v verbose\n"
init_msg(NULL, NULL);
- while ((ch = getopt(argc, argv, "b:c:d:h:mn:p:rsu:vV:w:?")) != -1) {
+ while ((ch = getopt(argc, argv, "b:c:d:h:mn:pP:rsu:vV:w:?")) != -1) {
switch (ch) {
case 'b':
bsr = parse_bsr(NULL, optarg);
break;
case 'm':
- update_vol_info = 1;
+ update_vol_info = true;
break;
case 'n':
db_user = optarg;
break;
- case 'p':
+ case 'P':
db_password = optarg;
break;
+ case 'p':
+ forge_on = true;
+ break;
+
case 'r':
- list_records = 1;
+ list_records = true;
break;
case 's':
- update_db = 1;
+ update_db = true;
break;
case 'v':
}
do_scan();
+ printf("Records %sadded to catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+ update_db?"":"would have been ",
+ num_media, num_pools, num_jobs, num_files);
free_jcr(bjcr);
return 0;
* the end of writing a tape by wiffling through the attached
* jcrs creating jobmedia records.
*/
-static int bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
+static bool bscan_mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
{
Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName);
for (JCR *mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
dcr->EndFile = dev->EndFile;
} else {
dcr->EndBlock = (uint32_t)dev->file_addr;
- dcr->StartBlock = (uint32_t)(dev->file_addr >> 32);
+ dcr->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.
*/
- int stat = mount_next_read_volume(jcr, dev, block);
+ 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 */
return stat;
/* 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);
+ read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume);
release_device(bjcr);
free_attr(attr);
term_dev(dev);
}
-static int record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
+/*
+ * Returns: true if OK
+ * false if error
+ */
+static bool record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
{
JCR *mjcr;
DCR *dcr;
*
*/
if (rec->FileIndex < 0) {
- int save_update_db = update_db;
+ bool save_update_db = update_db;
if (verbose > 1) {
dump_label_record(dev, rec, 1);
switch (rec->FileIndex) {
case PRE_LABEL:
Pmsg0(000, _("Volume is prelabeled. This tape cannot be scanned.\n"));
- return 1;
+ return false;
break;
case VOL_LABEL:
/* Check Pool info */
bstrncpy(pr.Name, dev->VolHdr.PoolName, sizeof(pr.Name));
bstrncpy(pr.PoolType, dev->VolHdr.PoolType, sizeof(pr.PoolType));
+ num_pools++;
if (db_get_pool_record(bjcr, db, &pr)) {
if (verbose) {
Pmsg1(000, _("Pool record for %s found in DB.\n"), pr.Name);
if (strcmp(pr.PoolType, dev->VolHdr.PoolType) != 0) {
Pmsg2(000, _("VOL_LABEL: PoolType mismatch. DB=%s Vol=%s\n"),
pr.PoolType, dev->VolHdr.PoolType);
- return 1;
+ return true;
} else if (verbose) {
Pmsg1(000, _("Pool type \"%s\" is OK.\n"), pr.PoolType);
}
memset(&mr, 0, sizeof(mr));
bstrncpy(mr.VolumeName, dev->VolHdr.VolName, sizeof(mr.VolumeName));
mr.PoolId = pr.PoolId;
+ num_media++;
if (db_get_media_record(bjcr, db, &mr)) {
if (verbose) {
Pmsg1(000, _("Media record for %s found in DB.\n"), mr.VolumeName);
if (strcmp(mr.MediaType, dev->VolHdr.MediaType) != 0) {
Pmsg2(000, _("VOL_LABEL: MediaType mismatch. DB=%s Vol=%s\n"),
mr.MediaType, dev->VolHdr.MediaType);
- return 1;
+ return true; /* ignore error */
} else if (verbose) {
Pmsg1(000, _("Media type \"%s\" is OK.\n"), mr.MediaType);
}
case SOS_LABEL:
mr.VolJobs++;
+ num_jobs++;
if (ignored_msgs > 0) {
Pmsg1(000, _("%d \"errors\" ignored before first Start of Session record.\n"),
ignored_msgs);
jr.JobId = label.JobId;
if (db_get_job_record(bjcr, db, &jr)) {
/* Job record already exists in DB */
- update_db = 0; /* don't change db in create_job_record */
+ update_db = false; /* don't change db in create_job_record */
if (verbose) {
Pmsg1(000, _("SOS_LABEL: Found Job record for JobId: %d\n"), jr.JobId);
}
jr.PoolId = pr.PoolId;
/* Set start positions into JCR */
if (dev->state & ST_TAPE) {
- dcr->StartBlock = dev->block_num;
+ /*
+ * Note, we have already advanced past current block,
+ * so the correct number is block_num - 1
+ */
+ dcr->StartBlock = dev->block_num - 1;
dcr->StartFile = dev->file;
} else {
dcr->StartBlock = (uint32_t)dev->file_addr;
dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
}
mjcr->start_time = jr.StartTime;
- mjcr->JobLevel = jr.Level;
+ mjcr->JobLevel = jr.JobLevel;
mjcr->client_name = get_pool_memory(PM_FNAME);
pm_strcpy(&mjcr->client_name, label.ClientName);
Pmsg3(000, _("SOS_LABEL: VolSessId mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.VolSessionId, rec->VolSessionId);
- return 1;
+ return true; /* ignore error */
}
if (rec->VolSessionTime != jr.VolSessionTime) {
Pmsg3(000, _("SOS_LABEL: VolSessTime mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.VolSessionTime, rec->VolSessionTime);
- return 1;
+ return true; /* ignore error */
}
if (jr.PoolId != pr.PoolId) {
Pmsg3(000, _("SOS_LABEL: PoolId mismatch for JobId=%u. DB=%d Vol=%d\n"),
jr.JobId,
jr.PoolId, pr.PoolId);
- return 1;
+ return true; /* ignore error */
}
break;
default:
break;
} /* end switch */
- return 1;
+ return true;
}
mjcr = get_jcr_by_session(rec->VolSessionId, rec->VolSessionTime);
} else {
ignored_msgs++;
}
- return 1;
+ return true;
}
dcr = mjcr->dcr;
if (dcr->VolFirstIndex == 0) {
}
fr.JobId = mjcr->JobId;
fr.FileId = 0;
+ num_files++;
+ if (verbose && (num_files & 0x7FFF) == 0) {
+ char ed1[30], ed2[30], ed3[30], ed4[30];
+ Pmsg4(000, _("%s file records. At file:blk=%s:%s bytes=%s\n"),
+ edit_uint64_with_commas(num_files, ed1),
+ edit_uint64_with_commas(rec->File, ed2),
+ 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);
Pmsg2(0, _("Unknown stream type!!! stream=%d data=%s\n"), rec->Stream, rec->data);
break;
}
- return 1;
+ return true;
}
/*
/*
* Called at end of media to update it
*/
-static int update_media_record(B_DB *db, MEDIA_DBR *mr)
+static bool update_media_record(B_DB *db, MEDIA_DBR *mr)
{
if (!update_db && !update_vol_info) {
- return 1;
+ return true;
}
mr->LastWritten = lasttime;
if (!db_update_media_record(bjcr, db, mr)) {
Pmsg1(0, _("Could not update media record. ERR=%s\n"), db_strerror(db));
- return 0;
+ return false;;
}
if (verbose) {
Pmsg1(000, _("Updated Media record at end of Volume: %s\n"), mr->VolumeName);
}
- return 1;
+ return true;
}
struct tm tm;
jr->JobId = label->JobId;
- jr->Type = label->JobType;
- jr->Level = label->JobLevel;
+ jr->JobType = label->JobType;
+ jr->JobLevel = label->JobLevel;
jr->JobStatus = JS_Created;
bstrncpy(jr->Name, label->JobName, sizeof(jr->Name));
bstrncpy(jr->Job, label->Job, sizeof(jr->Job));
Pmsg1(000, _("Updated Job termination record for new JobId=%u\n"), jr->JobId);
}
if (verbose > 1) {
- char *term_msg;
+ const char *term_msg;
static char term_code[70];
char sdt[50], edt[50];
char ec1[30], ec2[30], ec3[30];
* the JobId and the ClientId.
*/
jobjcr = new_jcr(sizeof(JCR), bscan_free_jcr);
- jobjcr->JobType = jr->Type;
- jobjcr->JobLevel = jr->Level;
+ jobjcr->JobType = jr->JobType;
+ jobjcr->JobLevel = jr->JobLevel;
jobjcr->JobStatus = jr->JobStatus;
bstrncpy(jobjcr->Job, jr->Job, sizeof(jobjcr->Job));
jobjcr->JobId = JobId; /* this is JobId on tape */
}
/* Dummies to replace askdir.c */
-int dir_get_volume_info(JCR *jcr, enum get_vol_info_rw writing) { return 1;}
-int dir_find_next_appendable_volume(JCR *jcr) { return 1;}
-int dir_update_volume_info(JCR *jcr, DEVICE *dev, int relabel) { return 1; }
-int dir_create_jobmedia_record(JCR *jcr) { return 1; }
-int dir_ask_sysop_to_create_appendable_volume(JCR *jcr, DEVICE *dev) { return 1; }
-int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec) { return 1;}
-int dir_send_job_status(JCR *jcr) {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;}
-int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
+bool dir_ask_sysop_to_mount_volume(DCR *dcr)
{
+ 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();