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;
52 find_result_t * find_dump(disklist_t* diskqp) {
53 char *conf_logdir, *logfile = NULL;
54 int tape, tape1, maxtape, logs;
57 find_result_t *output_find = NULL;
58 gboolean *tape_seen = NULL;
60 conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
61 maxtape = lookup_nb_tape();
62 tape_seen = g_new0(gboolean, maxtape+1);
64 for(tape = 1; tape <= maxtape; tape++) {
66 if (tape_seen[tape] == 1)
68 tp = lookup_tapepos(tape);
69 if(tp == NULL) continue;
71 /* find all tape with the same datestamp */
72 for (tape1 = tape; tape1 <= maxtape; tape1++) {
73 tp1 = lookup_tapepos(tape1);
74 if (tp1 == NULL) continue;
75 if (strcmp(tp->datestamp, tp1->datestamp) != 0)
81 /* search log files */
85 /* new-style log.<date>.<seq> */
87 for(seq = 0; 1; seq++) {
88 char seq_str[NUM_STR_SIZE];
90 g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);
91 logfile = newvstralloc(logfile,
92 conf_logdir, "/log.", tp->datestamp, ".", seq_str, NULL);
93 if(access(logfile, R_OK) != 0) break;
94 if (search_logfile(&output_find, NULL, tp->datestamp,
100 /* search old-style amflush log, if any */
102 logfile = newvstralloc(logfile, conf_logdir, "/log.",
103 tp->datestamp, ".amflush", NULL);
104 if(access(logfile,R_OK) == 0) {
105 if (search_logfile(&output_find, NULL, tp->datestamp,
111 /* search old-style main log, if any */
113 logfile = newvstralloc(logfile, conf_logdir, "/log.", tp->datestamp,
115 if(access(logfile,R_OK) == 0) {
116 if (search_logfile(&output_find, NULL, tp->datestamp,
126 search_holding_disk(&output_find, diskqp);
134 char *conf_logdir, *logfile = NULL;
135 char *pathlogfile = NULL;
136 int tape, maxtape, logs;
139 char **output_find_log = NULL;
142 conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
143 maxtape = lookup_nb_tape();
145 output_find_log = alloc((maxtape*5+10) * SIZEOF(char *));
146 current_log = output_find_log;
148 for(tape = 1; tape <= maxtape; tape++) {
150 tp = lookup_tapepos(tape);
151 if(tp == NULL) continue;
153 /* search log files */
157 /* new-style log.<date>.<seq> */
159 for(seq = 0; 1; seq++) {
160 char seq_str[NUM_STR_SIZE];
162 g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);
163 logfile = newvstralloc(logfile, "log.", tp->datestamp, ".", seq_str, NULL);
164 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
165 if (access(pathlogfile, R_OK) != 0) break;
166 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
167 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
168 *current_log = stralloc(logfile);
176 /* search old-style amflush log, if any */
178 logfile = newvstralloc(logfile, "log.", tp->datestamp, ".amflush", NULL);
179 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
180 if (access(pathlogfile, R_OK) == 0) {
181 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
182 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
183 *current_log = stralloc(logfile);
190 /* search old-style main log, if any */
192 logfile = newvstralloc(logfile, "log.", tp->datestamp, NULL);
193 pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);
194 if (access(pathlogfile, R_OK) == 0) {
195 if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {
196 if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {
197 *current_log = stralloc(logfile);
204 if(logs == 0 && strcmp(tp->datestamp,"0") != 0)
205 g_fprintf(stderr, _("Warning: no log files found for tape %s written %s\n"),
206 tp->label, find_nicedate(tp->datestamp));
212 return(output_find_log);
217 find_result_t **output_find,
218 disklist_t * dynamic_disklist)
220 GSList *holding_file_list;
226 holding_file_list = holding_get_files(NULL, 1);
228 for(e = holding_file_list; e != NULL; e = e->next) {
231 holding_file = (char *)e->data;
233 if (!holding_file_get_dumpfile(holding_file, &file))
236 if (file.dumplevel < 0 || file.dumplevel >= DUMP_LEVELS) {
237 dumpfile_free_data(&file);
242 orig_name = g_strdup(file.name);
245 if((dp = lookup_disk(file.name, file.disk)))
247 if((s = strrchr(file.name,'.')) == NULL)
251 strcpy(file.name, orig_name); /* restore munged string */
255 if (dynamic_disklist == NULL) {
256 dumpfile_free_data(&file);
259 dp = add_disk(dynamic_disklist, file.name, file.disk);
260 enqueue_disk(dynamic_disklist, dp);
263 if(find_match(file.name,file.disk)) {
264 find_result_t *new_output_find = g_new0(find_result_t, 1);
265 new_output_find->next=*output_find;
266 new_output_find->timestamp = stralloc(file.datestamp);
267 new_output_find->write_timestamp = stralloc("00000000000000");
268 new_output_find->hostname = stralloc(file.name);
269 new_output_find->diskname = stralloc(file.disk);
270 new_output_find->level=file.dumplevel;
271 new_output_find->label=stralloc(holding_file);
272 new_output_find->partnum = -1;
273 new_output_find->totalparts = -1;
274 new_output_find->filenum=0;
275 if (file.is_partial) {
276 new_output_find->status=stralloc("PARTIAL");
277 new_output_find->dump_status=stralloc("PARTIAL");
279 new_output_find->status=stralloc("OK");
280 new_output_find->dump_status=stralloc("OK");
282 new_output_find->message=stralloc("");
283 new_output_find->kb = holding_file_size(holding_file, 1);
284 new_output_find->orig_kb = file.orig_size;
286 *output_find=new_output_find;
288 dumpfile_free_data(&file);
291 slist_free_full(holding_file_list, g_free);
300 find_result_t *i, *j;
302 size_t nb_compare=strlen(find_sort_order);
305 for(k=0;k<nb_compare;k++) {
306 char sort_key = find_sort_order[k];
307 if (isupper((int)sort_key)) {
309 sort_key = tolower(sort_key);
310 j = *(find_result_t **)i1;
311 i = *(find_result_t **)j1;
313 i = *(find_result_t **)i1;
314 j = *(find_result_t **)j1;
318 case 'h' : compare=strcmp(i->hostname,j->hostname);
320 case 'k' : compare=strcmp(i->diskname,j->diskname);
322 case 'd' : compare=strcmp(i->timestamp,j->timestamp);
324 case 'l' : compare=j->level - i->level;
326 case 'f' : compare=(i->filenum == j->filenum) ? 0 :
327 ((i->filenum < j->filenum) ? -1 : 1);
329 case 'b' : compare=compare_possibly_null_strings(i->label,
332 case 'w': compare=strcmp(i->write_timestamp, j->write_timestamp);
335 compare=i->partnum - j->partnum;
347 find_result_t **output_find)
349 find_result_t *output_find_result;
350 find_result_t **array_find_result = NULL;
354 find_sort_order = sort_order;
355 /* qsort core dump if nothing to sort */
356 if(*output_find==NULL)
359 /* How many result */
360 for(output_find_result=*output_find;
362 output_find_result=output_find_result->next) {
366 /* put the list in an array */
367 array_find_result=alloc(nb_result * SIZEOF(find_result_t *));
368 for(output_find_result=*output_find,no_result=0;
370 output_find_result=output_find_result->next,no_result++) {
371 array_find_result[no_result]=output_find_result;
375 qsort(array_find_result,nb_result,SIZEOF(find_result_t *),
378 /* put the sorted result in the list */
380 no_result<nb_result-1; no_result++) {
381 array_find_result[no_result]->next = array_find_result[no_result+1];
383 array_find_result[nb_result-1]->next=NULL;
384 *output_find=array_find_result[0];
385 amfree(array_find_result);
390 find_result_t *output_find)
392 find_result_t *output_find_result;
393 int max_len_datestamp = 4;
394 int max_len_hostname = 4;
395 int max_len_diskname = 4;
396 int max_len_level = 2;
397 int max_len_label =12;
398 int max_len_filenum = 4;
399 int max_len_part = 4;
400 int max_len_status = 6;
403 for(output_find_result=output_find;
405 output_find_result=output_find_result->next) {
408 len=len_find_nicedate(output_find_result->timestamp);
409 if((int)len > max_len_datestamp)
410 max_len_datestamp=(int)len;
412 len=strlen(output_find_result->hostname);
413 if((int)len > max_len_hostname)
414 max_len_hostname = (int)len;
416 len = len_quote_string(output_find_result->diskname);
417 if((int)len > max_len_diskname)
418 max_len_diskname = (int)len;
420 if (output_find_result->label != NULL) {
421 len = len_quote_string(output_find_result->label);
422 if((int)len > max_len_label)
423 max_len_label = (int)len;
426 len=strlen(output_find_result->status) + 1 + strlen(output_find_result->dump_status);
427 if((int)len > max_len_status)
428 max_len_status = (int)len;
430 s = g_strdup_printf("%d/%d", output_find_result->partnum,
431 output_find_result->totalparts);
433 if((int)len > max_len_part)
434 max_len_part = (int)len;
439 * Since status is the rightmost field, we zap the maximum length
440 * because it is not needed. The code is left in place in case
441 * another column is added later.
445 if(output_find==NULL) {
446 g_printf(_("\nNo dump to list\n"));
449 g_printf(_("\ndate%*s host%*s disk%*s lv%*s tape or file%*s file%*s part%*s status\n"),
450 max_len_datestamp-4,"",
451 max_len_hostname-4 ,"",
452 max_len_diskname-4 ,"",
454 max_len_label-12 ,"",
455 max_len_filenum-4 ,"",
457 for(output_find_result=output_find;
459 output_find_result=output_find_result->next) {
461 char * formatted_label;
465 qdiskname = quote_string(output_find_result->diskname);
466 if (output_find_result->label == NULL)
467 formatted_label = stralloc("");
469 formatted_label = quote_string(output_find_result->label);
471 if (strcmp(output_find_result->status, "OK") != 0 ||
472 strcmp(output_find_result->dump_status, "OK") != 0) {
473 status = vstralloc(output_find_result->status, " ",
474 output_find_result->dump_status, NULL);
476 status = stralloc(output_find_result->status);
480 /* sec and kb are omitted here, for compatibility with the existing
481 * output from 'amadmin' */
482 s = g_strdup_printf("%d/%d", output_find_result->partnum,
483 output_find_result->totalparts);
484 g_printf("%-*s %-*s %-*s %*d %-*s %*lld %*s %s %s\n",
486 find_nicedate(output_find_result->timestamp),
487 max_len_hostname, output_find_result->hostname,
488 max_len_diskname, qdiskname,
489 max_len_level, output_find_result->level,
490 max_len_label, formatted_label,
491 max_len_filenum, (long long)output_find_result->filenum,
494 output_find_result->message
500 amfree(formatted_label);
507 find_result_t **output_find)
509 find_result_t *output_find_result, *prev;
512 for(output_find_result=*output_find;
514 output_find_result=output_find_result->next) {
516 amfree(output_find_result->timestamp);
517 amfree(output_find_result->write_timestamp);
518 amfree(output_find_result->hostname);
519 amfree(output_find_result->diskname);
520 amfree(output_find_result->label);
521 amfree(output_find_result->status);
522 amfree(output_find_result->dump_status);
523 amfree(output_find_result->message);
524 prev = output_find_result;
535 disk_t *dp = lookup_disk(host,disk);
536 return (dp && dp->todo);
543 static char nice[20];
544 int year, month, day;
545 int hours, minutes, seconds;
546 char date[9], atime[7];
547 int numdate, numtime;
549 strncpy(date, datestamp, 8);
551 numdate = atoi(date);
552 year = numdate / 10000;
553 month = (numdate / 100) % 100;
556 if(strlen(datestamp) <= 8) {
557 g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d",
561 strncpy(atime, &(datestamp[8]), 6);
563 numtime = atoi(atime);
564 hours = numtime / 10000;
565 minutes = (numtime / 100) % 100;
566 seconds = numtime % 100;
568 g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d %02d:%02d:%02d",
569 year, month, day, hours, minutes, seconds);
579 if(strlen(datestamp) <= 8) {
587 parse_taper_datestamp_log(
598 skip_whitespace(s, ch);
602 if(strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {
606 skip_whitespace(s, ch);
611 skip_non_whitespace(s, ch);
614 skip_whitespace(s, ch);
618 if(strncmp_const_skip(s - 1, "label", s, ch) != 0) {
622 skip_whitespace(s, ch);
627 skip_non_whitespace(s, ch);
633 /* Returns TRUE if the given logfile mentions the given tape. */
634 static gboolean logfile_has_tape(char * label, char * datestamp,
637 char * ck_datestamp, *ck_label;
638 if((logf = fopen(logfile, "r")) == NULL) {
639 error(_("could not open logfile %s: %s"), logfile, strerror(errno));
643 while(get_logline(logf)) {
644 if(curlog == L_START && curprog == P_TAPER) {
645 if(parse_taper_datestamp_log(curstr,
646 &ck_datestamp, &ck_label) == 0) {
647 g_printf(_("strange log line \"start taper %s\" curstr='%s'\n"),
649 } else if(strcmp(ck_datestamp, datestamp) == 0
650 && strcmp(ck_label, label) == 0) {
665 const char *datestamp)
673 return (strcmp(label1, label2) == 0);
675 /* check in tapelist */
676 if (!(tp = lookup_tapelabel(label2)))
679 if (strcmp(tp->datestamp, datestamp) != 0)
685 /* WARNING: Function accesses globals find_diskqp, curlog, curlog, curstr,
686 * dynamic_disklist */
689 find_result_t **output_find,
691 const char *passed_datestamp,
693 disklist_t * dynamic_disklist)
696 char *host, *host_undo;
697 char *disk, *qdisk, *disk_undo;
698 char *date, *date_undo;
704 char *current_label = stralloc("");
705 char *rest, *rest_undo;
709 char *ck_datestamp, *datestamp;
713 GHashTable* valid_label;
714 GHashTable* part_by_dle;
715 find_result_t *part_find;
716 find_result_t *a_part_find;
717 gboolean right_label = FALSE;
718 gboolean found_something = FALSE;
724 g_return_val_if_fail(output_find != NULL, 0);
725 g_return_val_if_fail(logfile != NULL, 0);
727 valid_label = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
728 part_by_dle = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
729 datestamp = g_strdup(passed_datestamp);
731 if((logf = fopen(logfile, "r")) == NULL) {
732 error(_("could not open logfile %s: %s"), logfile, strerror(errno));
737 while(get_logline(logf)) {
738 if (curlog == L_START && curprog == P_TAPER) {
739 if(parse_taper_datestamp_log(curstr, &ck_datestamp,
741 g_printf(_("strange log line in %s \"start taper %s\"\n"),
745 if (datestamp != NULL) {
746 if (strcmp(datestamp, ck_datestamp) != 0) {
747 g_printf(_("Log file %s stamped %s, expecting %s!\n"),
748 logfile, ck_datestamp, datestamp);
753 right_label = volume_matches(label, ck_label, ck_datestamp);
754 if (right_label && ck_label) {
755 g_hash_table_insert(valid_label, g_strdup(ck_label),
758 if (label && datestamp && right_label) {
759 found_something = TRUE;
761 amfree(current_label);
762 current_label = g_strdup(ck_label);
763 if (datestamp == NULL) {
764 datestamp = g_strdup(ck_datestamp);
769 (curlog == L_SUCCESS ||
770 curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTPARTIAL) &&
771 curprog == P_TAPER) {
773 } else if (right_label && curlog == L_PARTIAL && curprog == P_TAPER &&
779 if (curlog == L_SUCCESS || curlog == L_CHUNKSUCCESS ||
780 curlog == L_DONE || curlog == L_FAIL ||
781 curlog == L_CHUNK || curlog == L_PART || curlog == L_PARTIAL ||
782 curlog == L_PARTPARTIAL ) {
786 skip_whitespace(s, ch);
788 g_printf(_("strange log line in %s \"%s\"\n"),
793 if (curlog == L_PART || curlog == L_PARTPARTIAL) {
794 char * part_label = s - 1;
796 skip_non_whitespace(s, ch);
799 if (!g_hash_table_lookup(valid_label, part_label))
801 amfree(current_label);
802 current_label = stralloc(part_label);
804 skip_whitespace(s, ch);
806 g_printf("strange log line in %s \"%s\"\n",
812 skip_non_whitespace(s, ch);
814 fileno = atoi(number);
819 skip_whitespace(s, ch);
821 g_printf("strange log line in %s \"%s\"\n",
830 skip_non_whitespace(s, ch);
834 skip_whitespace(s, ch);
836 g_printf(_("strange log line in %s \"%s\"\n"),
841 skip_quoted_string(s, ch);
844 disk = unquote_string(qdisk);
846 skip_whitespace(s, ch);
848 g_printf(_("strange log line in %s \"%s\"\n"),
853 skip_non_whitespace(s, ch);
857 if(strlen(date) < 3) { /* old log didn't have datestamp */
859 date = stralloc(datestamp);
863 if (curprog == P_TAPER &&
864 (curlog == L_CHUNK || curlog == L_PART ||
865 curlog == L_PARTPARTIAL || curlog == L_PARTIAL ||
867 skip_whitespace(s, ch);
869 skip_non_whitespace(s, ch);
871 sscanf(number, "%d/%d", &partnum, &totalparts);
872 if (partnum > maxparts)
874 if (totalparts > maxparts)
875 maxparts = totalparts;
877 skip_whitespace(s, ch);
878 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
879 g_printf(_("strange log line in %s \"%s\"\n"),
886 skip_whitespace(s, ch);
888 g_printf(_("strange log line in %s \"%s\"\n"),
893 skip_non_whitespace(s, ch);
896 if (strcmp(rest, "[sec") == 0) {
897 skip_whitespace(s, ch);
899 g_printf(_("strange log line in %s \"%s\"\n"),
904 skip_non_whitespace(s, ch);
905 skip_whitespace(s, ch);
907 skip_non_whitespace(s, ch);
910 if (strcmp(rest, "kb") != 0) {
911 g_printf(_("Bstrange log line in %s \"%s\"\n"),
916 skip_whitespace(s, ch);
918 g_printf(_("strange log line in %s \"%s\"\n"),
923 skip_non_whitespace(s, ch);
924 skip_whitespace(s, ch);
926 skip_non_whitespace(s, ch);
929 if (strcmp(rest, "kps") != 0) {
930 g_printf(_("Cstrange log line in %s \"%s\"\n"),
935 skip_whitespace(s, ch);
937 g_printf(_("strange log line in %s \"%s\"\n"),
941 /* kps = atof(s - 1); */
942 skip_non_whitespace(s, ch);
943 skip_whitespace(s, ch);
945 skip_non_whitespace(s, ch);
948 if (strcmp(rest, "orig-kb") != 0) {
952 skip_whitespace(s, ch);
954 g_printf(_("strange log line in %s \"%s\"\n"),
958 orig_kb = atof(s - 1);
967 if (strncmp(rest, "error", 5) == 0) rest += 6;
968 if (strncmp(rest, "config", 6) == 0) rest += 7;
970 dp = lookup_disk(host,disk);
972 if (dynamic_disklist == NULL) {
975 dp = add_disk(dynamic_disklist, host, disk);
976 enqueue_disk(dynamic_disklist, dp);
978 if (find_match(host, disk)) {
979 if(curprog == P_TAPER) {
980 char *key = g_strdup_printf(
981 "HOST:%s DISK:%s: DATE:%s LEVEL:%d",
982 host, disk, date, level);
983 find_result_t *new_output_find = g_new0(find_result_t, 1);
984 part_find = g_hash_table_lookup(part_by_dle, key);
985 new_output_find->timestamp = stralloc(date);
986 new_output_find->write_timestamp = stralloc(datestamp);
987 new_output_find->hostname=stralloc(host);
988 new_output_find->diskname=stralloc(disk);
989 new_output_find->level=level;
990 new_output_find->partnum = partnum;
991 new_output_find->totalparts = totalparts;
992 new_output_find->label=stralloc(current_label);
993 new_output_find->status=NULL;
994 new_output_find->dump_status=NULL;
995 new_output_find->message=stralloc("");
996 new_output_find->filenum=filenum;
997 new_output_find->sec=sec;
998 new_output_find->kb=kb;
999 new_output_find->orig_kb=orig_kb;
1000 new_output_find->next=NULL;
1001 if (curlog == L_SUCCESS) {
1002 new_output_find->status = stralloc("OK");
1003 new_output_find->dump_status = stralloc("OK");
1004 new_output_find->next = *output_find;
1005 new_output_find->partnum = 1; /* L_SUCCESS is pre-splitting */
1006 *output_find = new_output_find;
1007 found_something = TRUE;
1008 } else if (curlog == L_CHUNKSUCCESS || curlog == L_DONE ||
1009 curlog == L_PARTIAL || curlog == L_FAIL) {
1011 if (curlog == L_PARTIAL || curlog == L_FAIL) {
1012 /* set dump_status of each part */
1013 for (a_part_find = part_find;
1015 a_part_find = a_part_find->next) {
1016 amfree(a_part_find->dump_status);
1017 if (curlog == L_PARTIAL)
1018 a_part_find->dump_status = stralloc("PARTIAL");
1020 a_part_find->dump_status = stralloc("FAIL");
1021 amfree(a_part_find->message);
1022 a_part_find->message = stralloc(rest);
1026 if (maxparts > -1) { /* format with part */
1027 /* must check if all part are there */
1028 int num_part = maxparts;
1029 for (a_part_find = part_find;
1031 a_part_find = a_part_find->next) {
1032 if (a_part_find->partnum == num_part &&
1033 strcmp(a_part_find->status, "OK") == 0)
1036 /* set dump_status of each part */
1037 for (a_part_find = part_find;
1039 a_part_find = a_part_find->next) {
1040 amfree(a_part_find->dump_status);
1041 if (num_part == 0) {
1042 a_part_find->dump_status =
1045 a_part_find->dump_status =
1047 amfree(a_part_find->message);
1048 a_part_find->message =
1049 stralloc("Missing part");
1054 if (curlog == L_DONE) {
1055 for (a_part_find = part_find;
1057 a_part_find = a_part_find->next) {
1058 if (a_part_find->totalparts == -1) {
1059 a_part_find->totalparts = maxparts;
1061 if (a_part_find->orig_kb == 0) {
1062 a_part_find->orig_kb = orig_kb;
1066 if (part_find) { /* find last element */
1067 for (a_part_find = part_find;
1068 a_part_find->next != NULL;
1069 a_part_find=a_part_find->next) {
1071 /* merge part_find to *output_find */
1072 a_part_find->next = *output_find;
1073 *output_find = part_find;
1076 found_something = TRUE;
1077 g_hash_table_remove(part_by_dle, key);
1079 free_find_result(&new_output_find);
1080 } else { /* part line */
1081 if (curlog == L_PART || curlog == L_CHUNK) {
1082 new_output_find->status=stralloc("OK");
1083 new_output_find->dump_status=stralloc("OK");
1084 } else { /* PARTPARTIAL */
1085 new_output_find->status=stralloc("PARTIAL");
1086 new_output_find->dump_status=stralloc("PARTIAL");
1088 /* Add to part_find list */
1090 new_output_find->next = part_find;
1091 part_find = new_output_find;
1093 new_output_find->next = NULL;
1094 part_find = new_output_find;
1096 g_hash_table_insert(part_by_dle, g_strdup(key),
1098 found_something = TRUE;
1102 else if(curlog == L_FAIL) {
1103 /* print other failures too -- this is a hack to ensure that failures which
1104 * did not make it to tape are also listed in the output of 'amadmin x find';
1105 * users that do not want this information (e.g., Amanda::DB::Catalog) should
1106 * filter dumps with a NULL label. */
1107 find_result_t *new_output_find = g_new0(find_result_t, 1);
1108 new_output_find->next = *output_find;
1109 new_output_find->timestamp = stralloc(date);
1110 new_output_find->write_timestamp = g_strdup("00000000000000"); /* dump was not written.. */
1111 new_output_find->hostname=stralloc(host);
1112 new_output_find->diskname=stralloc(disk);
1113 new_output_find->level=level;
1114 new_output_find->label=NULL;
1115 new_output_find->partnum=partnum;
1116 new_output_find->totalparts=totalparts;
1117 new_output_find->filenum=0;
1118 new_output_find->sec=sec;
1119 new_output_find->kb=kb;
1120 new_output_find->kb=orig_kb;
1121 new_output_find->status=vstralloc(
1123 program_str[(int)curprog],
1127 new_output_find->dump_status=stralloc("");
1128 new_output_find->message=stralloc("");
1129 *output_find=new_output_find;
1130 found_something = TRUE;
1138 g_hash_table_destroy(valid_label);
1141 amfree(current_label);
1143 return found_something;
1148 * Return the set of dumps that match *all* of the given patterns (we consider
1149 * an empty pattern to match .*, though). If 'ok' is true, will only match
1150 * dumps with SUCCESS status.
1152 * Returns a newly allocated list of results, where all strings are also newly
1153 * allocated. Apparently some part of Amanda leaks under this condition.
1157 find_result_t *output_find,
1164 find_result_t *cur_result;
1165 find_result_t *matches = NULL;
1167 for(cur_result=output_find;
1169 cur_result=cur_result->next) {
1170 char level_str[NUM_STR_SIZE];
1171 g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);
1172 if((!hostname || *hostname == '\0' || match_host(hostname, cur_result->hostname)) &&
1173 (!diskname || *diskname == '\0' || match_disk(diskname, cur_result->diskname)) &&
1174 (!datestamp || *datestamp== '\0' || match_datestamp(datestamp, cur_result->timestamp)) &&
1175 (!level || *level== '\0' || match_level(level, level_str)) &&
1176 (!ok || !strcmp(cur_result->status, "OK")) &&
1177 (!ok || !strcmp(cur_result->dump_status, "OK"))){
1179 find_result_t *curmatch = g_new0(find_result_t, 1);
1180 memcpy(curmatch, cur_result, SIZEOF(find_result_t));
1182 curmatch->timestamp = stralloc(cur_result->timestamp);
1183 curmatch->write_timestamp = stralloc(cur_result->write_timestamp);
1184 curmatch->hostname = stralloc(cur_result->hostname);
1185 curmatch->diskname = stralloc(cur_result->diskname);
1186 curmatch->level = cur_result->level;
1187 curmatch->label = cur_result->label? stralloc(cur_result->label) : NULL;
1188 curmatch->filenum = cur_result->filenum;
1189 curmatch->sec = cur_result->sec;
1190 curmatch->kb = cur_result->kb;
1191 curmatch->orig_kb = cur_result->orig_kb;
1192 curmatch->status = stralloc(cur_result->status);
1193 curmatch->dump_status = stralloc(cur_result->dump_status);
1194 curmatch->message = stralloc(cur_result->message);
1195 curmatch->partnum = cur_result->partnum;
1196 curmatch->totalparts = cur_result->totalparts;
1197 curmatch->next = matches;
1206 * Return the set of dumps that match one or more of the given dumpspecs,
1207 * If 'ok' is true, only dumps with a SUCCESS status will be matched.
1209 * Returns a newly allocated list of results, where all strings are also newly
1210 * allocated. Apparently some part of Amanda leaks under this condition.
1213 dumps_match_dumpspecs(
1214 find_result_t *output_find,
1218 find_result_t *cur_result;
1219 find_result_t *matches = NULL;
1223 for(cur_result=output_find;
1225 cur_result=cur_result->next) {
1226 char level_str[NUM_STR_SIZE];
1227 char *zeropad_ts = NULL;
1228 char *zeropad_w_ts = NULL;
1229 g_snprintf(level_str, SIZEOF(level_str), "%d", cur_result->level);
1231 /* get the timestamp padded to full width */
1232 if (strlen(cur_result->timestamp) < 14) {
1233 zeropad_ts = g_new0(char, 15);
1234 memset(zeropad_ts, '0', 14);
1235 memcpy(zeropad_ts, cur_result->timestamp, strlen(cur_result->timestamp));
1237 if (strlen(cur_result->write_timestamp) < 14) {
1238 zeropad_w_ts = g_new0(char, 15);
1239 memset(zeropad_w_ts, '0', 14);
1240 memcpy(zeropad_w_ts, cur_result->write_timestamp, strlen(cur_result->write_timestamp));
1243 for (dumpspec = dumpspecs; dumpspec; dumpspec = dumpspec->next) {
1244 ds = (dumpspec_t *)dumpspec->data;
1245 if((!ds->host || *ds->host == '\0' || match_host(ds->host, cur_result->hostname)) &&
1246 (!ds->disk || *ds->disk == '\0' || match_disk(ds->disk, cur_result->diskname)) &&
1247 (!ds->datestamp || *ds->datestamp== '\0'
1248 || match_datestamp(ds->datestamp, cur_result->timestamp)
1249 || (zeropad_ts && match_datestamp(ds->datestamp, zeropad_ts))) &&
1250 (!ds->write_timestamp || *ds->write_timestamp== '\0'
1251 || match_datestamp(ds->write_timestamp, cur_result->write_timestamp)
1252 || (zeropad_w_ts && match_datestamp(ds->write_timestamp, zeropad_w_ts))) &&
1253 (!ds->level || *ds->level== '\0' || match_level(ds->level, level_str)) &&
1254 (!ok || !strcmp(cur_result->status, "OK")) &&
1255 (!ok || !strcmp(cur_result->dump_status, "OK"))) {
1257 find_result_t *curmatch = alloc(SIZEOF(find_result_t));
1258 memcpy(curmatch, cur_result, SIZEOF(find_result_t));
1260 curmatch->timestamp = stralloc(cur_result->timestamp);
1261 curmatch->write_timestamp = stralloc(cur_result->write_timestamp);
1262 curmatch->hostname = stralloc(cur_result->hostname);
1263 curmatch->diskname = stralloc(cur_result->diskname);
1264 curmatch->level = cur_result->level;
1265 curmatch->label = cur_result->label? stralloc(cur_result->label) : NULL;
1266 curmatch->filenum = cur_result->filenum;
1267 curmatch->status = stralloc(cur_result->status);
1268 curmatch->dump_status = stralloc(cur_result->dump_status);
1269 curmatch->message = stralloc(cur_result->message);
1270 curmatch->partnum = cur_result->partnum;
1271 curmatch->totalparts = cur_result->totalparts;
1273 curmatch->next = matches;
1287 find_result_t *output_find,
1293 find_result_t *output_find_result;
1295 for(output_find_result=output_find;
1297 output_find_result=output_find_result->next) {
1298 if( !strcmp(output_find_result->hostname, hostname) &&
1299 !strcmp(output_find_result->diskname, diskname) &&
1300 !strcmp(output_find_result->timestamp, datestamp) &&
1301 output_find_result->level == level) {
1303 return output_find_result;