* Version $Id$
*/
/*
- Copyright (C) 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2001-2004 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
/* Global variables */
STORES *me;
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
int win32_client = 1;
#else
int win32_client = 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;
"Usage: bscan [-d debug_level] <bacula-archive>\n"
" -b bootstrap specify a bootstrap file\n"
" -c <file> specify configuration file\n"
-" -dnn set debug level to nn\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"
+" -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"
+" -h <host> specify database host (default NULL)\n"
" -r list records\n"
" -s synchronize or store in database\n"
" -v verbose\n"
-" -V specify Volume names (separated by |)\n"
-" -w dir specify working directory (default from conf file)\n"
+" -V <Volumes> specify Volume names (separated by |)\n"
+" -w <dir> specify working directory (default from conf file)\n"
" -? print this message\n\n"));
exit(1);
}
init_msg(NULL, NULL);
- while ((ch = getopt(argc, argv, "b:c:d:mn:p:rsu:vV:w:?")) != -1) {
+ while ((ch = getopt(argc, argv, "b:c:d:h:mn:p:rsu:vV:w:?")) != -1) {
switch (ch) {
case 'b':
bsr = parse_bsr(NULL, optarg);
debug_level = 1;
break;
+ case 'h':
+ db_host = optarg;
+ break;
+
case 'm':
update_vol_info = 1;
break;
exit(1);
}
- if ((db=db_init_database(NULL, db_name, db_user, db_password, NULL, 0, NULL)) == NULL) {
+ if ((db=db_init_database(NULL, db_name, db_user, db_password, db_host, 0, NULL)) == NULL) {
Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
}
if (!db_open_database(NULL, db)) {
{
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;
if (verbose) {
Pmsg1(000, _("Create JobMedia for Job %s\n"), mjcr->Job);
}
if (dev->state & ST_TAPE) {
- mjcr->EndBlock = dev->EndBlock;
- mjcr->EndFile = dev->EndFile;
+ dcr->EndBlock = dev->EndBlock;
+ dcr->EndFile = dev->EndFile;
} else {
- mjcr->EndBlock = (uint32_t)dev->file_addr;
- mjcr->StartBlock = (uint32_t)(dev->file_addr >> 32);
+ dcr->EndBlock = (uint32_t)dev->file_addr;
+ dcr->StartBlock = (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"),
detach_jcr_from_device(dev, bjcr);
read_records(bjcr, dev, record_cb, bscan_mount_next_read_volume);
- release_device(bjcr, dev);
+ release_device(bjcr);
free_attr(attr);
term_dev(dev);
static int record_cb(JCR *bjcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
{
JCR *mjcr;
+ DCR *dcr;
char ec1[30];
if (rec->data_len > 0) {
}
/* Reset some JCR variables */
for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
- mjcr->VolFirstIndex = mjcr->FileIndex = 0;
- mjcr->StartBlock = mjcr->EndBlock = 0;
- mjcr->StartFile = mjcr->EndFile = 0;
+ dcr = mjcr->dcr;
+ dcr->VolFirstIndex = dcr->FileIndex = 0;
+ dcr->StartBlock = dcr->EndBlock = 0;
+ dcr->StartFile = dcr->EndFile = 0;
}
Pmsg1(000, _("VOL_LABEL: OK for Volume: %s\n"), mr.VolumeName);
}
}
/* Create Client record if not already there */
- strcpy(cr.Name, label.ClientName);
+ bstrncpy(cr.Name, label.ClientName, sizeof(cr.Name));
create_client_record(db, &cr);
jr.ClientId = cr.ClientId;
/* process label, if Job record exists don't update db */
mjcr = create_job_record(db, &jr, &label, rec);
+ dcr = mjcr->dcr;
update_db = save_update_db;
jr.PoolId = pr.PoolId;
/* Set start positions into JCR */
if (dev->state & ST_TAPE) {
- mjcr->StartBlock = dev->block_num;
- mjcr->StartFile = dev->file;
+ dcr->StartBlock = dev->block_num;
+ dcr->StartFile = dev->file;
} else {
- mjcr->StartBlock = (uint32_t)dev->file_addr;
- mjcr->StartFile = (uint32_t)(dev->file_addr >> 32);
+ dcr->StartBlock = (uint32_t)dev->file_addr;
+ dcr->StartFile = (uint32_t)(dev->file_addr >> 32);
}
mjcr->start_time = jr.StartTime;
mjcr->JobLevel = jr.Level;
unser_session_label(&elabel, rec);
/* Create FileSet record */
- strcpy(fsr.FileSet, label.FileSetName);
- strcpy(fsr.MD5, label.FileSetMD5);
+ bstrncpy(fsr.FileSet, label.FileSetName, sizeof(fsr.FileSet));
+ bstrncpy(fsr.MD5, label.FileSetMD5, sizeof(fsr.MD5));
create_fileset_record(db, &fsr);
jr.FileSetId = fsr.FileSetId;
* them.
*/
if (update_db) {
- for (mjcr=NULL; (mjcr=next_attached_jcr(dev, mjcr)); ) {
+ mjcr=next_attached_jcr(dev, NULL);
+ for ( ; mjcr; ) {
+ JCR *njcr;
jr.JobId = mjcr->JobId;
jr.JobStatus = JS_ErrorTerminated;
jr.JobFiles = mjcr->JobFiles;
jr.VolSessionTime = mjcr->VolSessionTime;
jr.JobTDate = (utime_t)mjcr->start_time;
jr.ClientId = mjcr->ClientId;
- free_jcr(mjcr);
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;
+ free_jcr(mjcr);
+ mjcr = njcr;
}
}
mr.VolFiles = rec->File;
}
return 1;
}
- if (mjcr->VolFirstIndex == 0) {
- mjcr->VolFirstIndex = block->FirstIndex;
+ dcr = mjcr->dcr;
+ if (dcr->VolFirstIndex == 0) {
+ dcr->VolFirstIndex = block->FirstIndex;
}
/* File Attributes stream */
}
fr.JobId = mjcr->JobId;
fr.FileId = 0;
- if (db_get_file_attributes_record(bjcr, db, attr->fname, &fr)) {
+ 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);
}
* Called from main free_jcr() routine in src/lib/jcr.c so
* that we can do our Director specific cleanup of the jcr.
*/
-static void dird_free_jcr(JCR *jcr)
+static void bscan_free_jcr(JCR *jcr)
{
Dmsg0(200, "Start dird free_jcr\n");
if (jcr->RestoreBootstrap) {
free(jcr->RestoreBootstrap);
}
+ if (jcr->dcr) {
+ free_dcr(jcr->dcr);
+ jcr->dcr = NULL;
+ }
Dmsg0(200, "End dird free_jcr\n");
}
char *fname, char *lname, int type,
char *ap, DEV_RECORD *rec)
{
-
+ DCR *dcr = mjcr->dcr;
ar.fname = fname;
ar.link = lname;
ar.ClientId = mjcr->ClientId;
ar.Stream = rec->Stream;
ar.FileIndex = rec->FileIndex;
ar.attr = ap;
- if (mjcr->VolFirstIndex == 0) {
- mjcr->VolFirstIndex = rec->FileIndex;
+ if (dcr->VolFirstIndex == 0) {
+ dcr->VolFirstIndex = rec->FileIndex;
}
- mjcr->FileIndex = rec->FileIndex;
+ dcr->FileIndex = rec->FileIndex;
mjcr->JobFiles++;
if (!update_db) {
struct date_time dt;
struct tm tm;
- strcpy(mr->VolStatus, "Full");
+ /* We mark Vols as Archive to keep them from being re-written */
+ bstrncpy(mr->VolStatus, "Archive", sizeof(mr->VolStatus));
mr->VolRetention = 365 * 3600 * 24; /* 1 year */
if (vl->VerNum >= 11) {
mr->FirstWritten = btime_to_utime(vl->write_btime);
jr->Type = label->JobType;
jr->Level = label->JobLevel;
jr->JobStatus = JS_Created;
- strcpy(jr->Name, label->JobName);
- strcpy(jr->Job, label->Job);
+ bstrncpy(jr->Name, label->JobName, sizeof(jr->Name));
+ bstrncpy(jr->Job, label->Job, sizeof(jr->Job));
if (label->VerNum >= 11) {
jr->SchedTime = btime_to_unix(label->write_btime);
} else {
static int create_jobmedia_record(B_DB *db, JCR *mjcr)
{
JOBMEDIA_DBR jmr;
+ DCR *dcr = mjcr->dcr;
if (dev->state & ST_TAPE) {
- mjcr->EndBlock = dev->EndBlock;
- mjcr->EndFile = dev->EndFile;
+ dcr->EndBlock = dev->EndBlock;
+ dcr->EndFile = dev->EndFile;
} else {
- mjcr->EndBlock = (uint32_t)dev->file_addr;
- mjcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+ dcr->EndBlock = (uint32_t)dev->file_addr;
+ dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
}
memset(&jmr, 0, sizeof(jmr));
jmr.JobId = mjcr->JobId;
jmr.MediaId = mr.MediaId;
- jmr.FirstIndex = mjcr->VolFirstIndex;
- jmr.LastIndex = mjcr->FileIndex;
- jmr.StartFile = mjcr->StartFile;
- jmr.EndFile = mjcr->EndFile;
- jmr.StartBlock = mjcr->StartBlock;
- jmr.EndBlock = mjcr->EndBlock;
+ jmr.FirstIndex = dcr->VolFirstIndex;
+ jmr.LastIndex = dcr->FileIndex;
+ jmr.StartFile = dcr->StartFile;
+ jmr.EndFile = dcr->EndFile;
+ jmr.StartBlock = dcr->StartBlock;
+ jmr.EndBlock = dcr->EndBlock;
if (!update_db) {
* Transfer as much as possible to the Job JCR. Most important is
* the JobId and the ClientId.
*/
- jobjcr = new_jcr(sizeof(JCR), dird_free_jcr);
+ jobjcr = new_jcr(sizeof(JCR), bscan_free_jcr);
jobjcr->JobType = jr->Type;
jobjcr->JobLevel = jr->Level;
jobjcr->JobStatus = jr->JobStatus;
- strcpy(jobjcr->Job, jr->Job);
+ bstrncpy(jobjcr->Job, jr->Job, sizeof(jobjcr->Job));
jobjcr->JobId = JobId; /* this is JobId on tape */
jobjcr->sched_time = jr->SchedTime;
jobjcr->start_time = jr->StartTime;
jobjcr->VolSessionTime = rec->VolSessionTime;
jobjcr->ClientId = jr->ClientId;
attach_jcr_to_device(dev, jobjcr);
+ new_dcr(jobjcr, dev);
return jobjcr;
}
/* 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, VOLUME_CAT_INFO *vol, int relabel) { 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_mount_next_volume(JCR *jcr, DEVICE *dev) { 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;}
int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev)
{
- fprintf(stderr, _("Mount Volume %s on device %s and press return when ready: "),
+ fprintf(stderr, _("Mount Volume \"%s\" on device \"%s\" and press return when ready: "),
jcr->VolumeName, dev_name(dev));
getchar();
return 1;