2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: find.c,v 1.33 2006/07/06 13:13:15 martinea Exp $
30 * controlling process for the Amanda backup system
42 int find_match(char *host, char *disk);
43 static char *find_nicedate(char *datestamp);
44 static int len_find_nicedate(char *datestamp);
45 static int find_compare(const void *, const void *);
46 static int parse_taper_datestamp_log(char *logline, char **datestamp, char **level);
47 static gboolean logfile_has_tape(char * label, char * datestamp,
50 static char *find_sort_order = NULL;
51 static GStringChunk *string_chunk = NULL;
53 find_result_t * find_dump(disklist_t* diskqp) {
54 char *conf_logdir, *logfile = NULL;
55 int tape, tape1, maxtape, logs;
58 find_result_t *output_find = NULL;
59 gboolean *tape_seen = NULL;
61 if (string_chunk == NULL) {
62 string_chunk = g_string_chunk_new(32768);
64 conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
65 maxtape = lookup_nb_tape();
66 tape_seen = g_new0(gboolean, maxtape+1);
68 for(tape = 1; tape <= maxtape; tape++) {
70 if (tape_seen[tape] == 1)
72 tp = lookup_tapepos(tape);
73 if(tp == NULL) continue;
75 /* find all tape with the same datestamp */
76 for (tape1 = tape; tape1 <= maxtape; tape1++) {
77 tp1 = lookup_tapepos(tape1);
78 if (tp1 == NULL) continue;
79 if (strcmp(tp->datestamp, tp1->datestamp) != 0)
85 /* search log files */
89 /* new-style log.<date>.<seq> */
91 for(seq = 0; 1; seq++) {
92 char seq_str[NUM_STR_SIZE];
94 g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);
95 logfile = newvstralloc(logfile,
96 conf_logdir, "/log.", tp->datestamp, ".", seq_str, NULL);
97 if(access(logfile, R_OK) != 0) break;
98 if (search_logfile(&output_find, NULL, tp->datestamp,
104 /* search old-style amflush log, if any */
106 logfile = newvstralloc(logfile, conf_logdir, "/log.",
107 tp->datestamp, ".amflush", NULL);
108 if(access(logfile,R_OK) == 0) {
109 if (search_logfile(&output_find, NULL, tp->datestamp,
115 /* search old-style main log, if any */
117 logfile = newvstralloc(logfile, conf_logdir, "/log.", tp->datestamp,
119 if(access(logfile,R_OK) == 0) {
120 if (search_logfile(&output_find, NULL, tp->datestamp,
130 search_holding_disk(&output_find, diskqp);
138 char *conf_logdir, *logfile = NULL;
139 char *pathlogfile = NULL;
140 int tape, maxtape, logs;
143 char **output_find_log = NULL;
146 conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
147 maxtape = lookup_nb_tape();
149 output_find_log = alloc((maxtape*5+10) * SIZEOF(char *));
150 current_log = output_find_log;
152 for(tape = 1; tape <= maxtape; tape++) {
154 tp = lookup_tapepos(tape);
155 if(tp == NULL) continue;
157 /* search log files */
161 /* new-style log.<date>.<seq> */
163 for(seq = 0; 1; seq++) {
164 char seq_str[NUM_STR_SIZE];
166 g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);
167 logfile = newvstralloc(logfile, "log.", tp->datestamp, ".", seq_str, NULL);
168 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
169 if (access(pathlogfile, R_OK) != 0) break;
170 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
171 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
172 *current_log = stralloc(logfile);
180 /* search old-style amflush log, if any */
182 logfile = newvstralloc(logfile, "log.", tp->datestamp, ".amflush", NULL);
183 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
184 if (access(pathlogfile, R_OK) == 0) {
185 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
186 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
187 *current_log = stralloc(logfile);
194 /* search old-style main log, if any */
196 logfile = newvstralloc(logfile, "log.", tp->datestamp, NULL);
197 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
198 if (access(pathlogfile, R_OK) == 0) {
199 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
200 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
201 *current_log = stralloc(logfile);
208 if(logs == 0 && strcmp(tp->datestamp,"0") != 0)
209 g_fprintf(stderr, _("Warning: no log files found for tape %s written %s\n"),
210 tp->label, find_nicedate(tp->datestamp));
216 return(output_find_log);
221 find_result_t **output_find,
222 disklist_t * dynamic_disklist)
224 GSList *holding_file_list;
230 holding_file_list = holding_get_files(NULL, 1);
232 if (string_chunk == NULL) {
233 string_chunk = g_string_chunk_new(32768);
236 for(e = holding_file_list; e != NULL; e = e->next) {
239 holding_file = (char *)e->data;
241 if (!holding_file_get_dumpfile(holding_file, &file))
244 if (file.dumplevel < 0 || file.dumplevel >= DUMP_LEVELS) {
245 dumpfile_free_data(&file);
250 orig_name = g_strdup(file.name);
253 if((dp = lookup_disk(file.name, file.disk)))
255 if((s = strrchr(file.name,'.')) == NULL)
259 strcpy(file.name, orig_name); /* restore munged string */
263 if (dynamic_disklist == NULL) {
264 dumpfile_free_data(&file);
267 dp = add_disk(dynamic_disklist, file.name, file.disk);
268 enqueue_disk(dynamic_disklist, dp);
271 if(find_match(file.name,file.disk)) {
272 find_result_t *new_output_find = g_new0(find_result_t, 1);
273 new_output_find->next=*output_find;
274 new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, file.datestamp);
275 new_output_find->write_timestamp = g_string_chunk_insert_const(string_chunk, "00000000000000");
276 new_output_find->hostname = g_string_chunk_insert_const(string_chunk, file.name);
277 new_output_find->diskname = g_string_chunk_insert_const(string_chunk, file.disk);
278 new_output_find->level=file.dumplevel;
279 new_output_find->label=g_string_chunk_insert_const(string_chunk, holding_file);
280 new_output_find->partnum = -1;
281 new_output_find->totalparts = -1;
282 new_output_find->filenum=0;
283 if (file.is_partial) {
284 new_output_find->status="PARTIAL";
285 new_output_find->dump_status="PARTIAL";
287 new_output_find->status="OK";
288 new_output_find->dump_status="OK";
290 new_output_find->message="";
291 new_output_find->kb = holding_file_size(holding_file, 1);
292 new_output_find->bytes = 0;
294 new_output_find->orig_kb = file.orig_size;
296 *output_find=new_output_find;
298 dumpfile_free_data(&file);
301 slist_free_full(holding_file_list, g_free);
310 find_result_t *i, *j;
312 size_t nb_compare=strlen(find_sort_order);
315 for(k=0;k<nb_compare;k++) {
316 char sort_key = find_sort_order[k];
317 if (isupper((int)sort_key)) {
319 sort_key = tolower(sort_key);
320 j = *(find_result_t **)i1;
321 i = *(find_result_t **)j1;
323 i = *(find_result_t **)i1;
324 j = *(find_result_t **)j1;
328 case 'h' : compare=strcmp(i->hostname,j->hostname);
330 case 'k' : compare=strcmp(i->diskname,j->diskname);
332 case 'd' : compare=strcmp(i->timestamp,j->timestamp);
334 case 'l' : compare=j->level - i->level;
336 case 'f' : compare=(i->filenum == j->filenum) ? 0 :
337 ((i->filenum < j->filenum) ? -1 : 1);
339 case 'b' : compare=compare_possibly_null_strings(i->label,
342 case 'w': compare=strcmp(i->write_timestamp, j->write_timestamp);
345 compare=i->partnum - j->partnum;
357 find_result_t **output_find)
359 find_result_t *output_find_result;
360 find_result_t **array_find_result = NULL;
364 find_sort_order = sort_order;
365 /* qsort core dump if nothing to sort */
366 if(*output_find==NULL)
369 /* How many result */
370 for(output_find_result=*output_find;
372 output_find_result=output_find_result->next) {
376 /* put the list in an array */
377 array_find_result=alloc(nb_result * SIZEOF(find_result_t *));
378 for(output_find_result=*output_find,no_result=0;
380 output_find_result=output_find_result->next,no_result++) {
381 array_find_result[no_result]=output_find_result;
385 qsort(array_find_result,nb_result,SIZEOF(find_result_t *),
388 /* put the sorted result in the list */
390 no_result<nb_result-1; no_result++) {
391 array_find_result[no_result]->next = array_find_result[no_result+1];
393 array_find_result[nb_result-1]->next=NULL;
394 *output_find=array_find_result[0];
395 amfree(array_find_result);
400 find_result_t *output_find)
402 find_result_t *output_find_result;
403 int max_len_datestamp = 4;
404 int max_len_hostname = 4;
405 int max_len_diskname = 4;
406 int max_len_level = 2;
407 int max_len_label =12;
408 int max_len_filenum = 4;
409 int max_len_part = 4;
410 int max_len_status = 6;
413 for(output_find_result=output_find;
415 output_find_result=output_find_result->next) {
418 len=len_find_nicedate(output_find_result->timestamp);
419 if((int)len > max_len_datestamp)
420 max_len_datestamp=(int)len;
422 len=strlen(output_find_result->hostname);
423 if((int)len > max_len_hostname)
424 max_len_hostname = (int)len;
426 len = len_quote_string(output_find_result->diskname);
427 if((int)len > max_len_diskname)
428 max_len_diskname = (int)len;
430 if (output_find_result->label != NULL) {
431 len = len_quote_string(output_find_result->label);
432 if((int)len > max_len_label)
433 max_len_label = (int)len;
436 len=strlen(output_find_result->status) + 1 + strlen(output_find_result->dump_status);
437 if((int)len > max_len_status)
438 max_len_status = (int)len;
440 s = g_strdup_printf("%d/%d", output_find_result->partnum,
441 output_find_result->totalparts);
443 if((int)len > max_len_part)
444 max_len_part = (int)len;
449 * Since status is the rightmost field, we zap the maximum length
450 * because it is not needed. The code is left in place in case
451 * another column is added later.
455 if(output_find==NULL) {
456 g_printf(_("\nNo dump to list\n"));
459 g_printf(_("\ndate%*s host%*s disk%*s lv%*s tape or file%*s file%*s part%*s status\n"),
460 max_len_datestamp-4,"",
461 max_len_hostname-4 ,"",
462 max_len_diskname-4 ,"",
464 max_len_label-12 ,"",
465 max_len_filenum-4 ,"",
467 for(output_find_result=output_find;
469 output_find_result=output_find_result->next) {
471 char * formatted_label;
475 qdiskname = quote_string(output_find_result->diskname);
476 if (output_find_result->label == NULL)
477 formatted_label = stralloc("");
479 formatted_label = quote_string(output_find_result->label);
481 if (strcmp(output_find_result->status, "OK") != 0 ||
482 strcmp(output_find_result->dump_status, "OK") != 0) {
483 status = vstralloc(output_find_result->status, " ",
484 output_find_result->dump_status, NULL);
486 status = stralloc(output_find_result->status);
490 /* sec and kb are omitted here, for compatibility with the existing
491 * output from 'amadmin' */
492 s = g_strdup_printf("%d/%d", output_find_result->partnum,
493 output_find_result->totalparts);
494 g_printf("%-*s %-*s %-*s %*d %-*s %*lld %*s %s %s\n",
496 find_nicedate(output_find_result->timestamp),
497 max_len_hostname, output_find_result->hostname,
498 max_len_diskname, qdiskname,
499 max_len_level, output_find_result->level,
500 max_len_label, formatted_label,
501 max_len_filenum, (long long)output_find_result->filenum,
504 output_find_result->message
510 amfree(formatted_label);
517 find_result_t **output_find)
519 find_result_t *output_find_result, *prev;
522 for(output_find_result=*output_find;
524 output_find_result=output_find_result->next) {
526 prev = output_find_result;
537 disk_t *dp = lookup_disk(host,disk);
538 return (dp && dp->todo);
545 static char nice[20];
546 int year, month, day;
547 int hours, minutes, seconds;
548 char date[9], atime[7];
549 int numdate, numtime;
551 strncpy(date, datestamp, 8);
553 numdate = atoi(date);
554 year = numdate / 10000;
555 month = (numdate / 100) % 100;
558 if(strlen(datestamp) <= 8) {
559 g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d",
563 strncpy(atime, &(datestamp[8]), 6);
565 numtime = atoi(atime);
566 hours = numtime / 10000;
567 minutes = (numtime / 100) % 100;
568 seconds = numtime % 100;
570 g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d %02d:%02d:%02d",
571 year, month, day, hours, minutes, seconds);
581 if(strlen(datestamp) <= 8) {
589 parse_taper_datestamp_log(
600 skip_whitespace(s, ch);
604 if(strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {
608 skip_whitespace(s, ch);
613 skip_non_whitespace(s, ch);
616 skip_whitespace(s, ch);
620 if(strncmp_const_skip(s - 1, "label", s, ch) != 0) {
624 skip_whitespace(s, ch);
629 skip_quoted_string(s, ch);
632 *label = unquote_string(*label);
636 /* Returns TRUE if the given logfile mentions the given tape. */
637 static gboolean logfile_has_tape(char * label, char * datestamp,
640 char * ck_datestamp, *ck_label = NULL;
641 if((logf = fopen(logfile, "r")) == NULL) {
642 error(_("could not open logfile %s: %s"), logfile, strerror(errno));
646 while(get_logline(logf)) {
647 if(curlog == L_START && curprog == P_TAPER) {
648 if(parse_taper_datestamp_log(curstr,
649 &ck_datestamp, &ck_label) == 0) {
650 g_printf(_("strange log line \"start taper %s\" curstr='%s'\n"),
652 } else if(strcmp(ck_datestamp, datestamp) == 0
653 && strcmp(ck_label, label) == 0) {
670 const char *datestamp)
678 return (strcmp(label1, label2) == 0);
680 /* check in tapelist */
681 if (!(tp = lookup_tapelabel(label2)))
684 if (strcmp(tp->datestamp, datestamp) != 0)
690 /* WARNING: Function accesses globals find_diskqp, curlog, curlog, curstr,
691 * dynamic_disklist */
694 find_result_t **output_find,
696 const char *passed_datestamp,
698 disklist_t * dynamic_disklist)
701 char *host, *host_undo;
702 char *disk, *qdisk, *disk_undo;
703 char *date, *date_undo;
709 char *current_label = stralloc("");
710 char *rest, *rest_undo;
714 char *ck_datestamp=NULL;
719 GHashTable* valid_label;
720 GHashTable* part_by_dle;
721 find_result_t *part_find;
722 find_result_t *a_part_find;
723 gboolean right_label = FALSE;
724 gboolean found_something = FALSE;
731 g_return_val_if_fail(output_find != NULL, 0);
732 g_return_val_if_fail(logfile != NULL, 0);
734 if (string_chunk == NULL) {
735 string_chunk = g_string_chunk_new(32768);
737 valid_label = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
738 part_by_dle = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
739 datestamp = g_strdup(passed_datestamp);
741 if((logf = fopen(logfile, "r")) == NULL) {
742 error(_("could not open logfile %s: %s"), logfile, strerror(errno));
747 while(get_logline(logf)) {
748 if (curlog == L_START && curprog == P_TAPER) {
751 if(parse_taper_datestamp_log(curstr, &ck_datestamp,
753 g_printf(_("strange log line in %s \"start taper %s\"\n"),
757 if (datestamp != NULL) {
758 if (strcmp(datestamp, ck_datestamp) != 0) {
759 g_printf(_("Log file %s stamped %s, expecting %s!\n"),
760 logfile, ck_datestamp, datestamp);
766 right_label = volume_matches(label, ck_label, ck_datestamp);
767 if (right_label && ck_label) {
768 g_hash_table_insert(valid_label, g_strdup(ck_label),
771 if (label && datestamp && right_label) {
772 found_something = TRUE;
774 amfree(current_label);
775 current_label = ck_label;
777 if (datestamp == NULL) {
778 datestamp = g_strdup(ck_datestamp);
785 (curlog == L_SUCCESS ||
786 curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTPARTIAL) &&
787 curprog == P_TAPER) {
789 } else if (right_label && curlog == L_PARTIAL && curprog == P_TAPER &&
795 if (curlog == L_SUCCESS || curlog == L_CHUNKSUCCESS ||
796 curlog == L_DONE || curlog == L_FAIL ||
797 curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTIAL ||
798 curlog == L_PARTPARTIAL ) {
802 skip_whitespace(s, ch);
804 g_printf(_("strange log line in %s \"%s\"\n"),
809 if (curlog == L_PART || curlog == L_PARTPARTIAL) {
811 char *qpart_label = s - 1;
813 skip_quoted_string(s, ch);
816 part_label = unquote_string(qpart_label);
817 if (!g_hash_table_lookup(valid_label, part_label)) {
821 amfree(current_label);
822 current_label = part_label;
824 skip_whitespace(s, ch);
826 g_printf("strange log line in %s \"%s\"\n",
832 skip_non_whitespace(s, ch);
834 fileno = atoi(number);
839 skip_whitespace(s, ch);
841 g_printf("strange log line in %s \"%s\"\n",
850 skip_non_whitespace(s, ch);
854 skip_whitespace(s, ch);
856 g_printf(_("strange log line in %s \"%s\"\n"),
861 skip_quoted_string(s, ch);
864 disk = unquote_string(qdisk);
866 skip_whitespace(s, ch);
868 g_printf(_("strange log line in %s \"%s\"\n"),
873 skip_non_whitespace(s, ch);
877 if(strlen(date) < 3) { /* old log didn't have datestamp */
879 date = stralloc(datestamp);
883 if (curprog == P_TAPER &&
884 (curlog == L_CHUNK || curlog == L_PART ||
885 curlog == L_PARTPARTIAL || curlog == L_PARTIAL ||
888 skip_whitespace(s, ch);
890 skip_non_whitespace(s, ch);
893 skip_whitespace(s, ch);
896 sscanf(number, "%d/%d", &partnum, &totalparts);
897 if (partnum > maxparts)
899 if (totalparts > maxparts)
900 maxparts = totalparts;
901 } else { /* nparts is not in all PARTIAL lines */
907 skip_whitespace(s, ch);
909 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
910 g_printf(_("Fstrange log line in %s \"%s\"\n"),
917 skip_whitespace(s, ch);
919 g_printf(_("strange log line in %s \"%s\"\n"),
924 skip_non_whitespace(s, ch);
927 if (strcmp(rest, "[sec") == 0) {
928 skip_whitespace(s, ch);
930 g_printf(_("strange log line in %s \"%s\"\n"),
935 skip_non_whitespace(s, ch);
936 skip_whitespace(s, ch);
938 skip_non_whitespace(s, ch);
941 if (strcmp(rest, "kb") != 0 &&
942 strcmp(rest, "bytes") != 0) {
943 g_printf(_("Bstrange log line in %s \"%s\"\n"),
948 skip_whitespace(s, ch);
950 g_printf(_("strange log line in %s \"%s\"\n"),
954 if (strcmp(rest, "kb") == 0) {
961 skip_non_whitespace(s, ch);
962 skip_whitespace(s, ch);
964 skip_non_whitespace(s, ch);
967 if (strcmp(rest, "kps") != 0) {
968 g_printf(_("Cstrange log line in %s \"%s\"\n"),
973 skip_whitespace(s, ch);
975 g_printf(_("strange log line in %s \"%s\"\n"),
979 /* kps = atof(s - 1); */
980 skip_non_whitespace(s, ch);
981 skip_whitespace(s, ch);
983 skip_non_whitespace(s, ch);
986 if (strcmp(rest, "orig-kb") != 0) {
990 skip_whitespace(s, ch);
992 g_printf(_("strange log line in %s \"%s\"\n"),
996 orig_kb = atof(s - 1);
1006 if (strncmp(rest, "error", 5) == 0) rest += 6;
1007 if (strncmp(rest, "config", 6) == 0) rest += 7;
1009 dp = lookup_disk(host,disk);
1011 if (dynamic_disklist == NULL) {
1014 dp = add_disk(dynamic_disklist, host, disk);
1015 enqueue_disk(dynamic_disklist, dp);
1017 if (find_match(host, disk)) {
1018 if(curprog == P_TAPER) {
1019 char *key = g_strdup_printf(
1020 "HOST:%s DISK:%s: DATE:%s LEVEL:%d",
1021 host, disk, date, level);
1022 find_result_t *new_output_find = g_new0(find_result_t, 1);
1023 part_find = g_hash_table_lookup(part_by_dle, key);
1025 if (maxparts < totalparts)
1026 maxparts = totalparts;
1027 for (a_part_find = part_find;
1029 a_part_find = a_part_find->next) {
1030 if (maxparts < a_part_find->partnum)
1031 maxparts = a_part_find->partnum;
1032 if (maxparts < a_part_find->totalparts)
1033 maxparts = a_part_find->totalparts;
1035 new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, date);
1036 new_output_find->write_timestamp = g_string_chunk_insert_const(string_chunk, datestamp);
1037 new_output_find->hostname=g_string_chunk_insert_const(string_chunk, host);
1038 new_output_find->diskname=g_string_chunk_insert_const(string_chunk, disk);
1039 new_output_find->level=level;
1040 new_output_find->partnum = partnum;
1041 new_output_find->totalparts = totalparts;
1042 new_output_find->label=g_string_chunk_insert_const(string_chunk, current_label);
1043 new_output_find->status=NULL;
1044 new_output_find->dump_status=NULL;
1045 new_output_find->message="";
1046 new_output_find->filenum=filenum;
1047 new_output_find->sec=sec;
1048 new_output_find->kb=kb;
1049 new_output_find->bytes=bytes;
1050 new_output_find->orig_kb=orig_kb;
1051 new_output_find->next=NULL;
1052 if (curlog == L_SUCCESS) {
1053 new_output_find->status = "OK";
1054 new_output_find->dump_status = "OK";
1055 new_output_find->next = *output_find;
1056 new_output_find->partnum = 1; /* L_SUCCESS is pre-splitting */
1057 *output_find = new_output_find;
1058 found_something = TRUE;
1059 } else if (curlog == L_CHUNKSUCCESS || curlog == L_DONE ||
1060 curlog == L_PARTIAL || curlog == L_FAIL) {
1062 if (curlog == L_PARTIAL || curlog == L_FAIL) {
1063 /* set dump_status of each part */
1064 for (a_part_find = part_find;
1066 a_part_find = a_part_find->next) {
1067 if (curlog == L_PARTIAL)
1068 a_part_find->dump_status = "PARTIAL";
1070 a_part_find->dump_status = "FAIL";
1071 a_part_find->message = g_string_chunk_insert_const(string_chunk, rest);
1075 if (maxparts > -1) { /* format with part */
1076 /* must check if all part are there */
1077 int num_part = maxparts;
1078 for (a_part_find = part_find;
1080 a_part_find = a_part_find->next) {
1081 if (a_part_find->partnum == num_part &&
1082 strcmp(a_part_find->status, "OK") == 0)
1085 /* set dump_status of each part */
1086 for (a_part_find = part_find;
1088 a_part_find = a_part_find->next) {
1089 if (num_part == 0) {
1090 a_part_find->dump_status = "OK";
1092 a_part_find->dump_status = "FAIL";
1093 a_part_find->message =
1094 g_string_chunk_insert_const(string_chunk, "Missing part");
1099 if (curlog == L_DONE) {
1100 for (a_part_find = part_find;
1102 a_part_find = a_part_find->next) {
1103 if (a_part_find->totalparts == -1) {
1104 a_part_find->totalparts = maxparts;
1106 if (a_part_find->orig_kb == 0) {
1107 a_part_find->orig_kb = orig_kb;
1111 if (part_find) { /* find last element */
1112 for (a_part_find = part_find;
1113 a_part_find->next != NULL;
1114 a_part_find=a_part_find->next) {
1116 /* merge part_find to *output_find */
1117 a_part_find->next = *output_find;
1118 *output_find = part_find;
1121 found_something = TRUE;
1122 g_hash_table_remove(part_by_dle, key);
1124 free_find_result(&new_output_find);
1125 } else { /* part line */
1126 if (curlog == L_PART || curlog == L_CHUNK) {
1127 new_output_find->status = "OK";
1128 new_output_find->dump_status = "OK";
1129 } else { /* PARTPARTIAL */
1130 new_output_find->status = "PARTIAL";
1131 new_output_find->dump_status = "PARTIAL";
1133 /* Add to part_find list */
1135 new_output_find->next = part_find;
1136 part_find = new_output_find;
1138 new_output_find->next = NULL;
1139 part_find = new_output_find;
1141 g_hash_table_insert(part_by_dle, g_strdup(key),
1143 found_something = TRUE;
1147 else if(curlog == L_FAIL) {
1148 char *status_failed;
1149 /* print other failures too -- this is a hack to ensure that failures which
1150 * did not make it to tape are also listed in the output of 'amadmin x find';
1151 * users that do not want this information (e.g., Amanda::DB::Catalog) should
1152 * filter dumps with a NULL label. */
1153 find_result_t *new_output_find = g_new0(find_result_t, 1);
1154 new_output_find->next = *output_find;
1155 new_output_find->timestamp = g_string_chunk_insert_const(string_chunk, date);
1156 new_output_find->write_timestamp = g_strdup("00000000000000"); /* dump was not written.. */
1157 new_output_find->hostname=g_string_chunk_insert_const(string_chunk, host);
1158 new_output_find->diskname=g_string_chunk_insert_const(string_chunk, disk);
1159 new_output_find->level=level;
1160 new_output_find->label=NULL;
1161 new_output_find->partnum=partnum;
1162 new_output_find->totalparts=totalparts;
1163 new_output_find->filenum=0;
1164 new_output_find->sec=sec;
1165 new_output_find->kb=kb;
1166 new_output_find->bytes=bytes;
1167 new_output_find->orig_kb=orig_kb;
1168 status_failed = vstralloc(
1170 program_str[(int)curprog],
1174 new_output_find->status = g_string_chunk_insert_const(string_chunk, status_failed);
1175 amfree(status_failed);
1176 new_output_find->dump_status="";
1177 new_output_find->message="";
1178 *output_find=new_output_find;
1179 found_something = TRUE;
1187 g_hash_table_destroy(valid_label);
1190 amfree(current_label);
1192 return found_something;
1197 * Return the set of dumps that match *all* of the given patterns (we consider
1198 * an empty pattern to match .*, though). If 'ok' is true, will only match
1199 * dumps with SUCCESS status.
1201 * Returns a newly allocated list of results, where all strings are also newly
1202 * allocated. Apparently some part of Amanda leaks under this condition.
1206 find_result_t *output_find,
1213 find_result_t *cur_result;
1214 find_result_t *matches = NULL;
1216 for(cur_result=output_find;
1218 cur_result=cur_result->next) {
1219 char level_str[NUM_STR_SIZE];
1220 g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);
1221 if((!hostname || *hostname == '\0' || match_host(hostname, cur_result->hostname)) &&
1222 (!diskname || *diskname == '\0' || match_disk(diskname, cur_result->diskname)) &&
1223 (!datestamp || *datestamp== '\0' || match_datestamp(datestamp, cur_result->timestamp)) &&
1224 (!level || *level== '\0' || match_level(level, level_str)) &&
1225 (!ok || !strcmp(cur_result->status, "OK")) &&
1226 (!ok || !strcmp(cur_result->dump_status, "OK"))){
1228 find_result_t *curmatch = g_new0(find_result_t, 1);
1229 memcpy(curmatch, cur_result, SIZEOF(find_result_t));
1231 curmatch->timestamp = cur_result->timestamp;
1232 curmatch->write_timestamp = cur_result->write_timestamp;
1233 curmatch->hostname = cur_result->hostname;
1234 curmatch->diskname = cur_result->diskname;
1235 curmatch->level = cur_result->level;
1236 curmatch->label = cur_result->label? cur_result->label : NULL;
1237 curmatch->filenum = cur_result->filenum;
1238 curmatch->sec = cur_result->sec;
1239 curmatch->kb = cur_result->kb;
1240 curmatch->bytes = cur_result->bytes;
1241 curmatch->orig_kb = cur_result->orig_kb;
1242 curmatch->status = cur_result->status;
1243 curmatch->dump_status = cur_result->dump_status;
1244 curmatch->message = cur_result->message;
1245 curmatch->partnum = cur_result->partnum;
1246 curmatch->totalparts = cur_result->totalparts;
1247 curmatch->next = matches;
1256 * Return the set of dumps that match one or more of the given dumpspecs,
1257 * If 'ok' is true, only dumps with a SUCCESS status will be matched.
1259 * Returns a newly allocated list of results, where all strings are also newly
1260 * allocated. Apparently some part of Amanda leaks under this condition.
1263 dumps_match_dumpspecs(
1264 find_result_t *output_find,
1268 find_result_t *cur_result;
1269 find_result_t *matches = NULL;
1273 for(cur_result=output_find;
1275 cur_result=cur_result->next) {
1276 char level_str[NUM_STR_SIZE];
1277 char *zeropad_ts = NULL;
1278 char *zeropad_w_ts = NULL;
1279 g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);
1281 /* get the timestamp padded to full width */
1282 if (strlen(cur_result->timestamp) < 14) {
1283 zeropad_ts = g_new0(char, 15);
1284 memset(zeropad_ts, '0', 14);
1285 memcpy(zeropad_ts, cur_result->timestamp, strlen(cur_result->timestamp));
1287 if (strlen(cur_result->write_timestamp) < 14) {
1288 zeropad_w_ts = g_new0(char, 15);
1289 memset(zeropad_w_ts, '0', 14);
1290 memcpy(zeropad_w_ts, cur_result->write_timestamp, strlen(cur_result->write_timestamp));
1293 for (dumpspec = dumpspecs; dumpspec; dumpspec = dumpspec->next) {
1294 ds = (dumpspec_t *)dumpspec->data;
1295 if((!ds->host || *ds->host == '\0' || match_host(ds->host, cur_result->hostname)) &&
1296 (!ds->disk || *ds->disk == '\0' || match_disk(ds->disk, cur_result->diskname)) &&
1297 (!ds->datestamp || *ds->datestamp== '\0'
1298 || match_datestamp(ds->datestamp, cur_result->timestamp)
1299 || (zeropad_ts && match_datestamp(ds->datestamp, zeropad_ts))) &&
1300 (!ds->write_timestamp || *ds->write_timestamp== '\0'
1301 || match_datestamp(ds->write_timestamp, cur_result->write_timestamp)
1302 || (zeropad_w_ts && match_datestamp(ds->write_timestamp, zeropad_w_ts))) &&
1303 (!ds->level || *ds->level== '\0' || match_level(ds->level, level_str)) &&
1304 (!ok || !strcmp(cur_result->status, "OK")) &&
1305 (!ok || !strcmp(cur_result->dump_status, "OK"))) {
1307 find_result_t *curmatch = alloc(SIZEOF(find_result_t));
1308 memcpy(curmatch, cur_result, SIZEOF(find_result_t));
1310 curmatch->timestamp = cur_result->timestamp;
1311 curmatch->write_timestamp = cur_result->write_timestamp;
1312 curmatch->hostname = cur_result->hostname;
1313 curmatch->diskname = cur_result->diskname;
1314 curmatch->level = cur_result->level;
1315 curmatch->label = cur_result->label? cur_result->label : NULL;
1316 curmatch->filenum = cur_result->filenum;
1317 curmatch->status = cur_result->status;
1318 curmatch->dump_status = cur_result->dump_status;
1319 curmatch->message = cur_result->message;
1320 curmatch->partnum = cur_result->partnum;
1321 curmatch->totalparts = cur_result->totalparts;
1323 curmatch->next = matches;
1337 find_result_t *output_find,
1343 find_result_t *output_find_result;
1345 for(output_find_result=output_find;
1347 output_find_result=output_find_result->next) {
1348 if( !strcmp(output_find_result->hostname, hostname) &&
1349 !strcmp(output_find_result->diskname, diskname) &&
1350 !strcmp(output_find_result->timestamp, datestamp) &&
1351 output_find_result->level == level) {
1353 return output_find_result;