/*
* Submit general SQL query
*/
-int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx)
+int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx,
+ int verbose)
{
sendit(ctx, "SQL Queries not implemented with internal database.\n");
return 0;
void db_list_files_for_job(B_DB *db, uint32_t jobid, DB_LIST_HANDLER sendit, void *ctx);
void db_list_media_records(B_DB *mdb, MEDIA_DBR *mdbr, DB_LIST_HANDLER *sendit, void *ctx);
void db_list_jobmedia_records(B_DB *mdb, uint32_t JobId, DB_LIST_HANDLER *sendit, void *ctx);
-int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx);
+int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx, int verbose);
/* update.c */
int db_update_job_start_record(B_DB *db, JOB_DBR *jr);
int db_update_job_end_record(B_DB *db, JOB_DBR *jr);
int db_update_pool_record(B_DB *db, POOL_DBR *pr);
int db_update_media_record(B_DB *db, MEDIA_DBR *mr);
-int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5);
+int db_add_MD5_to_file_record(B_DB *mdb, FileId_t FileId, char *MD5);
int db_mark_file_record(B_DB *mdb, FileId_t FileId, int JobId);
#endif /* __SQL_PROTOS_H */
/*
* Submit general SQL query
*/
-int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx)
+int db_list_sql_query(B_DB *mdb, char *query, DB_LIST_HANDLER *sendit, void *ctx,
+ int verbose)
{
db_lock(mdb);
if (sql_query(mdb, query) != 0) {
Mmsg(&mdb->errmsg, _("Query failed: %s\n"), sql_strerror(mdb));
- sendit(ctx, mdb->errmsg);
+ if (verbose) {
+ sendit(ctx, mdb->errmsg);
+ }
db_unlock(mdb);
return 0;
}
bacula-dir: $(SVROBJS) ../lib/libbac.a ../cats/libsql.a
$(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ $(SVROBJS) \
- -lsql $(LIBS) $(DLIB) -lbac -lm
+ -lsql -lbac -lm $(LIBS) $(DLIB)
Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
cd $(topdir) \
* really fatal problems, or the number of errors is too
* large.
*/
- long file_index;
- int stream, len;
- char *attr, buf[MAXSTRING];
- char Opts[MAXSTRING]; /* either Verify opts or MD5 signature */
-
- /* ***FIXME*** check fname length */
- if ((len = sscanf(fd->msg, "%ld %d %s %s", &file_index, &stream,
- Opts, jcr->fname)) != 4) {
- Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 4 fields got %d\n\
+ long file_index;
+ int stream, len;
+ char *attr, *p, *fn;
+ char Opts_MD5[MAXSTRING]; /* either Verify opts or MD5 signature */
+ char MD5[MAXSTRING];
+
+ jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
+ if ((len = sscanf(fd->msg, "%ld %d %s", &file_index, &stream, Opts_MD5)) != 3) {
+ Jmsg(jcr, M_FATAL, 0, _("<filed: bad attributes, expected 3 fields got %d\n\
msglen=%d msg=%s\n"), len, fd->msglen, fd->msg);
- jcr->JobStatus = JS_ErrorTerminated;
- return 0;
- }
-
- if (stream == STREAM_UNIX_ATTRIBUTES) {
- jcr->JobFiles++;
- len = strlen(fd->msg); /* length before attributes */
- ar.attr = &fd->msg[len+1];
- ar.fname = jcr->fname;
- ar.FileIndex = 0; /* used as mark field during compare */
- ar.Stream = stream;
- ar.link = NULL;
- ar.JobId = jcr->JobId;
- ar.ClientId = jcr->ClientId;
- ar.PathId = 0;
- ar.FilenameId = 0;
-
- Dmsg2(11, "dird<filed: stream=%d %s\n", stream, jcr->fname);
- Dmsg1(20, "dird<filed: attr=%s\n", attr);
-
- /* ***FIXME*** fix link field */
- if (!db_create_file_attributes_record(jcr->db, &ar)) {
- Jmsg1(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
- jcr->JobStatus = JS_ErrorTerminated;
- /* This probably should not really be fatal *****FIXME****** */
- return 0;
- }
- jcr->FileIndex = file_index;
- jcr->FileId = ar.FileId;
- } else if (stream == STREAM_MD5_SIGNATURE) {
- if (jcr->FileIndex != (uint32_t)file_index) {
- Jmsg0(jcr, M_FATAL, 0, _("Got MD5 but not same block as attributes\n"));
- jcr->JobStatus = JS_ErrorTerminated;
- return 0;
- }
- db_escape_string(buf, Opts, strlen(Opts));
- Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(buf), buf);
- if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, buf)) {
- Jmsg1(jcr, M_WARNING, 0, "%s", db_strerror(jcr->db));
- }
- }
- jcr->jr.JobFiles = jcr->JobFiles = file_index;
- jcr->jr.LastIndex = file_index;
+ jcr->JobStatus = JS_ErrorTerminated;
+ return 0;
+ }
+ p = fd->msg;
+ skip_nonspaces(&p); /* skip FileIndex */
+ skip_spaces(&p);
+ skip_nonspaces(&p); /* skip Stream */
+ skip_spaces(&p);
+ skip_nonspaces(&p); /* skip Opts_MD5 */
+ p++; /* skip space */
+ fn = jcr->fname;
+ while (*p != 0) {
+ *fn++ = *p++; /* copy filename */
+ }
+ *fn = *p++; /* term filename and point to attribs */
+ attr = p;
+
+ if (stream == STREAM_UNIX_ATTRIBUTES) {
+ jcr->JobFiles++;
+ ar.attr = attr;
+ ar.fname = jcr->fname;
+ ar.FileIndex = 0; /* used as mark field during compare */
+ ar.Stream = stream;
+ ar.link = NULL;
+ ar.JobId = jcr->JobId;
+ ar.ClientId = jcr->ClientId;
+ ar.PathId = 0;
+ ar.FilenameId = 0;
+
+ Dmsg2(11, "dird<filed: stream=%d %s\n", stream, jcr->fname);
+ Dmsg1(20, "dird<filed: attr=%s\n", attr);
+
+ /* ***FIXME*** fix link field */
+ if (!db_create_file_attributes_record(jcr->db, &ar)) {
+ Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ jcr->JobStatus = JS_Error;
+ continue;
+ }
+ jcr->FileIndex = file_index;
+ jcr->FileId = ar.FileId;
+ } else if (stream == STREAM_MD5_SIGNATURE) {
+ if (jcr->FileIndex != (uint32_t)file_index) {
+ Jmsg0(jcr, M_ERROR, 0, _("Got MD5 but not same block as attributes\n"));
+ jcr->JobStatus = JS_Error;
+ continue;
+ }
+ db_escape_string(MD5, Opts_MD5, strlen(Opts_MD5));
+ Dmsg2(20, "MD5len=%d MD5=%s\n", strlen(MD5), MD5);
+ if (!db_add_MD5_to_file_record(jcr->db, jcr->FileId, MD5)) {
+ Jmsg1(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
+ jcr->JobStatus = JS_Error;
+ }
+ }
+ jcr->jr.JobFiles = jcr->JobFiles = file_index;
+ jcr->jr.LastIndex = file_index;
}
if (n < 0) {
Jmsg1(jcr, M_FATAL, 0, _("<filed: Network error getting attributes. ERR=%s\n"),
WHERE JobMedia.JobId=Job.JobId
AND JobMedia.MediaId=Media.MediaId
GROUP by VolumeName;
+#
+:List last 10 Full Backups for a Client:
+*Enter Client name:
+Select JobId,Client.Name as Client,StartTime,JobFiles,JobBytes
+ FROM Client,Job
+ WHERE Client.Name="%1"
+ AND Client.ClientId=Job.ClientId
+ AND Level='F' AND JobStatus='T'
+ LIMIT 10;
+#
+:List Volumes used by selected JobId:
+*Enter JobId:
+SELECT Job.JobId,VolumeName
+ FROM Job,JobMedia,Media
+ WHERE Job.JobId=%1
+ AND Job.JobId=JobMedia.JobId
+ AND JobMedia.MediaId=Media.MediaId;
+:List Volumes to Restore All Files:
+*Enter Client Name:
+!DROP TABLE temp;
+!DROP TABLE temp2;
+CREATE TABLE temp (JobId INTEGER UNSIGNED NOT NULL,
+ JobTDate BIGINT UNSIGNED,
+ ClientId INTEGER UNSIGNED,
+ StartTime TEXT,
+ VolumeName TEXT,
+ StartFile INTEGER UNSIGNED,
+ VolSessionId INTEGER UNSIGNED,
+ VolSessionTime INTEGER UNSIGNED);
+CREATE TABLE temp2 (JobId INTEGER UNSIGNED NOT NULL,
+ StartTime TEXT,
+ VolumeName TEXT,
+ StartFile INTEGER UNSIGNED,
+ VolSessionId INTEGER UNSIGNED,
+ VolSessionTime INTEGER UNSIGNED);
+INSERT INTO temp SELECT Job.JobId,JobTDate,Job.ClientId,StartTime,VolumeName,
+ JobMedia.StartFile,VolSessionId,VolSessionTime
+ FROM Client,Job,JobMedia,Media WHERE Client.Name="%1"
+ AND Client.ClientId=Job.ClientId
+ AND Level='F' AND JobStatus='T'
+ AND JobMedia.JobId=Job.JobId
+ AND JobMedia.MediaId=Media.MediaId
+ ORDER BY Job.JobTDate DESC LIMIT 1;
+INSERT INTO temp2 SELECT JobId,StartTime,VolumeName,StartFile,
+ VolSessionId,VolSessionTime
+ FROM temp;
+INSERT INTO temp2 SELECT Job.JobId,Job.StartTime,Media.VolumeName,
+ JobMedia.StartFile,Job.VolSessionId,Job.VolSessionTime
+ FROM Job,temp,JobMedia,Media
+ WHERE Job.JobTDate>temp.JobTDate
+ AND Job.ClientId=temp.ClientId
+ AND Level='I' AND JobStatus='T'
+ AND JobMedia.JobId=Job.JobId
+ AND JobMedia.MediaId=Media.MediaId;
+SELECT * from temp2;
+!DROP TABLE temp;
+!DROP TABLE temp2;
+#
while ((n=bget_msg(fd, 0)) > 0) {
long file_index, attr_file_index;
int stream;
- char *attr, *p;
+ char *attr, *p, *fn;
char Opts_MD5[MAXSTRING]; /* Verify Opts or MD5 signature */
fname = check_pool_memory_size(fname, fd->msglen);
jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
Dmsg1(50, "Atts+MD5=%s\n", fd->msg);
- if ((len = sscanf(fd->msg, "%ld %d %100s %s", &file_index, &stream,
- Opts_MD5, fname)) != 4) {
- Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 4 fields got %d\n\
+ if ((len = sscanf(fd->msg, "%ld %d %100s", &file_index, &stream,
+ Opts_MD5)) != 3) {
+ Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 3 fields got %d\n\
mslen=%d msg=%s\n"), len, fd->msglen, fd->msg);
goto bail_out;
}
+ p = fd->msg;
+ skip_nonspaces(&p); /* skip FileIndex */
+ skip_spaces(&p);
+ skip_nonspaces(&p); /* skip Stream */
+ skip_spaces(&p);
+ skip_nonspaces(&p); /* skip Opts_MD5 */
+ p++; /* skip space */
+ fn = fname;
+ while (*p != 0) {
+ *fn++ = *p++; /* copy filename */
+ }
+ *fn = *p++; /* term filename and point to attribs */
+ attr = p;
/*
* Got attributes stream, decode it
*/
if (stream == STREAM_UNIX_ATTRIBUTES) {
jcr->JobFiles++;
attr_file_index = file_index; /* remember attribute file_index */
- len = strlen(fd->msg);
- attr = &fd->msg[len+1];
decode_stat(attr, &statf); /* decode file stat packet */
do_MD5 = FALSE;
jcr->fn_printed = FALSE;
bacula-fd: $(SVROBJS) ../findlib/libfind.a ../lib/libbac.a @WIN32@
$(CXX) $(LDFLAGS) -L../lib -L../findlib -o $@ $(SVROBJS) \
- $(WIN32LIBS) $(FDLIBS) $(LIBS) $(DLIB) -lfind -lbac -lm
+ $(WIN32LIBS) $(FDLIBS) -lfind -lbac -lm $(LIBS) $(DLIB)
Makefile: $(srcdir)/Makefile.in $(topdir)/config.status
cd $(topdir) \
/* File Attributes stream */
if (stream == STREAM_UNIX_ATTRIBUTES) {
- char *ap, *lp;
+ char *ap, *lp, *fp;
Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
/* If extracting, it was from previous stream, so
* Link name (if file linked i.e. FT_LNK)
*
*/
- if (sscanf(sd->msg, "%d %d %s", &record_file_index, &type, fname) != 3) {
+ if (sscanf(sd->msg, "%d %d", &record_file_index, &type) != 2) {
Jmsg(jcr, M_FATAL, 0, _("Error scanning record header: %s\n"), sd->msg);
Dmsg0(0, "\nError scanning header\n");
goto bail_out;
}
- Dmsg3(30, "Got Attr: FilInx=%d type=%d fname=%s\n", record_file_index,
- type, fname);
+ Dmsg2(30, "Got Attr: FilInx=%d type=%d\n", record_file_index, type);
if (record_file_index != file_index) {
Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"),
file_index, record_file_index);
goto bail_out;
}
ap = sd->msg;
- /* Skip to attributes */
- while (*ap++ != 0) {
+ while (*ap++ != ' ') /* skip record file index */
;
+ while (*ap++ != ' ') /* skip type */
+ ;
+ /* Save filename and position to attributes */
+ fp = fname;
+ while (*ap != 0) {
+ *fp++ = *ap++;
}
+ *fp = *ap++; /* terminate filename & point to attribs */
+
/* Skip to Link name */
if (type == FT_LNK) {
lp = ap;
sprintf(con_fname, "%s/%s.conmsg", wd, my_name);
fd = open(con_fname, O_CREAT|O_RDWR|O_BINARY, 0600);
if (fd == -1) {
- Emsg2(M_ABORT, 0, "Could not open console message file %s: ERR=%s\n",
+ Emsg2(M_TERM, 0, "Could not open console message file %s: ERR=%s\n",
con_fname, strerror(errno));
}
if (lseek(fd, 0, SEEK_END) > 0) {
Dmsg2(200, "Enter dispatch_msg type=%d msg=%s\n", type, msg);
- if (type == M_ABORT) {
+ if (type == M_ABORT || type == M_TERM) {
fprintf(stdout, msg); /* print this here to INSURE that it is printed */
}
break;
case MD_STDOUT:
Dmsg1(200, "STDOUT for following err: %s\n", msg);
- if (type != M_ABORT && type != M_FATAL) /* already printed */
+ if (type != M_ABORT && type != M_TERM) /* already printed */
fprintf(stdout, msg);
break;
case MD_STDERR:
/*
* Check if we have a message destination defined.
- * We always report M_ABORT
+ * We always report M_ABORT and M_TERM
*/
- if (!daemon_msgs || (type != M_ABORT &&
+ if (!daemon_msgs || ((type != M_ABORT && type != M_TERM) &&
!bit_is_set(type, daemon_msgs->send_msg)))
return; /* no destination */
switch (type) {
sprintf(buf, "%s ABORTING due to ERROR in %s:%d\n",
my_name, file, line);
break;
+ case M_TERM:
+ sprintf(buf, "%s TERMINATING due to ERROR in %s:%d\n",
+ my_name, file, line);
+ break;
case M_FATAL:
if (level == -1) /* skip details */
sprintf(buf, "%s: Fatal Error because: ", my_name);
char *p = 0;
p[0] = 0; /* generate segmentation violation */
}
+ if (type == M_TERM) {
+ _exit(1);
+ }
}
/* *********************************************************
buf = rbuf; /* we are the Director */
/*
* Check if we have a message destination defined.
- * We always report M_ABORT
+ * We always report M_ABORT and M_TERM
*/
- if (type != M_ABORT && msgs && !bit_is_set(type, msgs->send_msg)) {
+ if ((type != M_ABORT && type != M_TERM) && msgs && !bit_is_set(type, msgs->send_msg)) {
Dmsg1(200, "No bit set for type %d\n", type);
return; /* no destination */
}
case M_ABORT:
sprintf(buf, "%s ABORTING due to ERROR\n", my_name);
break;
+ case M_TERM:
+ sprintf(buf, "%s TERMINATING due to ERROR\n", my_name);
+ break;
case M_FATAL:
sprintf(buf, "%s: Job %s Fatal error: ", my_name, job);
if (jcr) {
char *p = 0;
p[0] = 0; /* generate segmentation violation */
}
+ if (type == M_TERM) {
+ _exit(1);
+ }
}
/*
}
already_dead = sig;
if (sig == SIGTERM) {
- Emsg1(M_TERM, -1, "Shutting down Bacula service: %s ...\n", my_name);
+ Emsg1(M_INFO, -1, "Shutting down Bacula service: %s ...\n", my_name);
} else {
Emsg2(M_FATAL, -1, "Interrupted by signal %d: %s\n", sig, sig_names[sig]);
}
@echo " "
bacula-sd: $(SVROBJS) ../lib/libbac.a
- $(CXX) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(LIBS) $(DLIB) $(FDLIBS) -lbac -lm
+ $(CXX) $(LDFLAGS) -L../lib -o $@ $(SVROBJS) $(FDLIBS) -lbac -lm $(LIBS) $(DLIB)
#bpool: $(POOLOBJS) ../lib/libbac.a ../cats/libsql.a
# $(CXX) $(LDFLAGS) -L../lib -L../cats -o $@ $(POOLOBJS) -lsql $(LIBS) $(DLIB) -lbac -lm
int ch;
FILE *fd;
char line[1000];
+ int got_inc = FALSE;
my_name_is(argc, argv, "bextract");
init_msg(NULL, NULL); /* setup message handler */
add_fname_to_include_list(ff, 0, line);
}
fclose(fd);
+ got_inc = TRUE;
break;
case '?':
Dmsg0(0, "Wrong number of arguments: \n");
usage();
}
+ if (!got_inc) { /* If no include file, */
+ add_fname_to_include_list(ff, 0, "/"); /* include everything */
+ }
jcr = new_jcr(sizeof(JCR), my_free_jcr);
jcr->VolSessionId = 1;
/* File Attributes stream */
if (rec.Stream == STREAM_UNIX_ATTRIBUTES) {
- char *ap, *lp;
+ char *ap, *lp, *fp;
/* If extracting, it was from previous stream, so
* close the output file.
* Link name (if file linked i.e. FT_LNK)
*
*/
- sscanf(rec.data, "%ld %d %s", &record_file_index, &type, fname);
+ sscanf(rec.data, "%ld %d", &record_file_index, &type);
if (record_file_index != rec.FileIndex)
Emsg2(M_ABORT, 0, "Record header file index %ld not equal record index %ld\n",
rec.FileIndex, record_file_index);
ap = rec.data;
- /* Skip to attributes */
- while (*ap++ != 0)
+ while (*ap++ != ' ') /* skip record file index */
+ ;
+ while (*ap++ != ' ') /* skip type */
;
+ /* Save filename and position to attributes */
+ fp = fname;
+ while (*ap != 0) {
+ *fp++ = *ap++;
+ }
+ *fp = *ap++; /* terminate filename & point to attribs */
+
/* Skip to Link name */
if (type == FT_LNK) {
lp = ap;
/* */
#define VERSION "1.21"
#define VSTRING "1"
-#define DATE "3 June 2002"
-#define LSMDATE "03Jun02"
+#define DATE "11 June 2002"
+#define LSMDATE "11Jun02"
/* Debug flags */
#define DEBUG 1