2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998, 2000 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: reporter.c,v 1.132 2006/08/28 17:02:48 martinea Exp $
30 * nightly Amanda Report generator
53 #include "timestamp.h"
56 /* don't have (or need) a skipped type except internally to reporter */
57 #define L_SKIPPED L_MARKER
60 #define STATUS_STRANGE 2
61 #define STATUS_FAILED 4
62 #define STATUS_MISSING 8
63 #define STATUS_TAPE 16
65 typedef struct line_s {
70 typedef struct timedata_s {
72 double origsize, outsize;
80 typedef struct repdata_s {
83 double est_nsize, est_csize;
88 struct repdata_s *next;
91 #define data(dp) ((repdata_t *)(dp)->up)
93 static struct cumulative_stats {
94 int dumpdisks, tapedisks, tapechunks;
95 double taper_time, dumper_time;
96 double outsize, origsize, tapesize;
97 double coutsize, corigsize; /* compressed dump only */
100 static int dumpdisks[10], tapedisks[10], tapechunks[10]; /* by-level breakdown of disk count */
102 typedef struct taper_s {
105 double coutsize, corigsize;
106 int tapedisks, tapechunks;
107 struct taper_s *next;
110 static taper_t *stats_by_tape = NULL;
111 static taper_t *current_tape = NULL;
113 typedef struct X_summary_s {
118 struct X_summary_s *next;
121 static X_summary_t *first_strange=NULL, *last_strange=NULL;
122 static X_summary_t *first_failed=NULL, *last_failed=NULL;
124 static double total_time, startup_time, planner_time;
126 /* count files to tape */
127 static int tapefcount = 0;
129 static int exit_status = 0;
130 static char *run_datestamp;
131 static char *tape_labels = NULL;
132 static int last_run_tapes = 0;
133 static int degraded_mode = 0; /* defined in driverio too */
134 static int normal_run = 0;
135 static int amflush_run = 0;
136 static int got_finish = 0;
137 static int cmdlogfname = 0;
138 static char *ghostname = NULL;
140 static char *tapestart_error = NULL;
142 static FILE *logfile, *mailf;
144 static FILE *postscript;
145 static char *printer;
147 static disklist_t diskq;
148 static disklist_t sortq;
150 static line_t *errsum = NULL;
151 static line_t *errdet = NULL;
152 static line_t *strangedet = NULL;
153 static line_t *notes = NULL;
155 static char MaxWidthsRequested = 0; /* determined via config data */
157 static char *displayunit;
158 static long int unitdivisor;
160 /* local functions */
161 int main(int argc, char **argv);
163 static char * nicedate(const char * datestamp);
164 static char * prefix(char *host, char *disk, int level);
165 static char * prefixstrange(char *host, char *disk, int level,
166 size_t len_host, size_t len_disk);
167 static char * Rule(int From, int To);
168 static char * sDivZero(double a, double b, int cn);
169 static char * TextRule(int From, int To, char *s);
170 static int ColWidth(int From, int To);
171 static int contline_next(void);
172 static int sort_by_name(disk_t *a, disk_t *b);
173 static repdata_t *find_repdata(disk_t *dp, char *datestamp, int level);
174 static repdata_t *handle_chunk(logtype_t logtype);
175 static repdata_t *handle_success(logtype_t logtype);
176 static void addline(line_t **lp, char *str);
177 static void addtoX_summary(X_summary_t **first, X_summary_t **last,
178 char *host, char *disk, int level, char *str);
179 static void bogus_line(const char *);
180 static void CalcMaxWidth(void);
181 static void CheckFloatMax(ColumnInfo *cd, double d);
182 static void CheckIntMax(ColumnInfo *cd, int n);
183 static void CheckStringMax(ColumnInfo *cd, char *s);
184 static void copy_template_file(char *lbl_templ);
185 static void do_postscript_output(void);
186 static void generate_missing(void);
187 static void generate_bad_estimate(void);
188 static void handle_disk(void);
189 static void handle_error(void);
190 static void handle_failed(void);
191 static void handle_finish(void);
192 static void handle_note(void);
193 static void handle_partial(void);
194 static void handle_start(void);
195 static void handle_stats(void);
196 static void handle_strange(void);
197 static void handle_summary(void);
198 static void output_lines(line_t *lp, FILE *f);
199 static void output_stats(void);
200 static void output_X_summary(X_summary_t *first);
201 static void output_summary(void);
202 static void output_tapeinfo(void);
203 static void sort_disks(void);
204 static void usage(void);
212 for (i=From; i<=To && ColumnData[i].Name != NULL; i++) {
213 Width+= ColumnData[i].PrefixSpace + ColumnData[i].Width;
224 int Leng= ColWidth(0, ColumnDataCount());
225 char *RuleSpace= alloc((size_t)(Leng+1));
226 ThisLeng= ColWidth(From, To);
227 for (i=0;i<ColumnData[From].PrefixSpace; i++)
229 for (; i<ThisLeng; i++)
231 RuleSpace[ThisLeng]= '\0';
241 ColumnInfo *cd= &ColumnData[From];
243 int nbrules, i, txtlength;
244 int RuleSpaceSize= ColWidth(0, ColumnDataCount());
245 char *RuleSpace= alloc((size_t)RuleSpaceSize), *tmp;
247 leng = (int)strlen(s);
248 if(leng >= (RuleSpaceSize - cd->PrefixSpace))
249 leng = RuleSpaceSize - cd->PrefixSpace - 1;
250 g_snprintf(RuleSpace, (size_t)RuleSpaceSize, "%*s%*.*s ", cd->PrefixSpace, "",
252 txtlength = cd->PrefixSpace + leng + 1;
253 nbrules = ColWidth(From,To) - txtlength;
254 for(tmp=RuleSpace + txtlength, i=nbrules ; i>0; tmp++,i--)
266 ColumnInfo *cd= &ColumnData[cn];
267 static char PrtBuf[256];
269 g_snprintf(PrtBuf, SIZEOF(PrtBuf),
270 "%*s", cd->Width, "-- ");
272 g_snprintf(PrtBuf, SIZEOF(PrtBuf),
273 cd->Format, cd->Width, cd->Precision, a/b);
282 if ((ch = getc(logfile)) != EOF) {
283 if (ungetc(ch, logfile) == EOF) {
284 if (ferror(logfile)) {
285 error(_("ungetc failed: %s\n"), strerror(errno));
288 error(_("ungetc failed: EOF\n"));
302 /* allocate new line node */
303 new = (line_t *) alloc(SIZEOF(line_t));
305 new->str = stralloc(str);
307 /* add to end of list */
312 while (p->next != NULL)
321 error(_("Usage: amreport conf [-i] [-M address] [-f output-file] [-l logfile] [-p postscript-file] [-o configoption]*"));
333 char *logfname, *psfname, *outfname, *subj_str = NULL;
336 char *mail_cmd = NULL, *printer_cmd = NULL;
339 char *ColumnSpec = "";
344 char *lbl_templ = NULL;
345 config_overwrites_t *cfg_ovr = NULL;
346 char *cfg_opt = NULL;
349 * Configure program for internationalization:
350 * 1) Only set the message locale for now.
351 * 2) Set textdomain for all amanda related programs to "amanda"
352 * We don't want to be forced to support dozens of message catalogs.
354 setlocale(LC_MESSAGES, "C");
355 textdomain("amanda");
359 set_pname("amreport");
361 dbopen(DBG_SUBDIR_SERVER);
363 /* Don't die when child closes pipe */
364 signal(SIGPIPE, SIG_IGN);
366 /* Process options */
368 erroutput_type = ERR_INTERACTIVE;
374 cwd = g_get_current_dir();
376 error(_("Cannot determine current working directory: %s"),
382 if (argv[1][0] == '-') {
387 /* get the config name and move past it */
391 cfg_ovr = new_config_overwrites(argc/2);
392 while((opt = getopt(argc, argv, "o:M:f:l:p:i")) != EOF) {
398 if (mailto != NULL) {
399 error(_("you may specify at most one -M"));
402 mailto = stralloc(optarg);
403 if(!validate_mailto(mailto)) {
404 error(_("mail address has invalid characters"));
409 if (outfname != NULL) {
410 error(_("you may specify at most one -f"));
413 if (*optarg == '/') {
414 outfname = stralloc(optarg);
416 outfname = vstralloc(cwd, "/", optarg, NULL);
421 if (logfname != NULL) {
422 error(_("you may specify at most one -l"));
425 if (*optarg == '/') {
426 logfname = stralloc(optarg);
428 logfname = vstralloc(cwd, "/", optarg, NULL);
432 if (psfname != NULL) {
433 error(_("you may specify at most one -p"));
436 if (*optarg == '/') {
437 psfname = stralloc(optarg);
439 psfname = vstralloc(cwd, "/", optarg, NULL);
443 add_config_overwrite_opt(cfg_ovr, optarg);
456 if( !mailout && mailto ){
457 g_printf(_("You cannot specify both -i & -M at the same time\n"));
465 g_printf(_("You must run amreport with '-f <output file>' because configure\n"));
466 g_printf(_("didn't find a mailer.\n"));
471 /* read configuration files */
473 /* ignore any errors reading the config file (amreport can run without a config) */
474 config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
475 if (cfg_ovr) apply_config_overwrites(cfg_ovr);
477 check_running_as(RUNNING_AS_DUMPUSER);
479 dbrename(config_name, DBG_SUBDIR_SERVER);
481 safe_cd(); /* must be called *after* config_init() */
483 conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
484 /* Ignore error from read_diskfile */
485 read_diskfile(conf_diskfile, &diskq);
486 amfree(conf_diskfile);
487 if(mailout && !mailto &&
488 getconf_seen(CNF_MAILTO) && strlen(getconf_str(CNF_MAILTO)) > 0) {
489 mailto = getconf_str(CNF_MAILTO);
490 if(!validate_mailto(mailto)){
495 conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST));
496 /* Ignore error from read_tapelist */
497 read_tapelist(conf_tapelist);
498 amfree(conf_tapelist);
499 conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
500 if(open_infofile(conf_infofile)) {
501 error(_("could not open info db \"%s\""), conf_infofile);
504 amfree(conf_infofile);
506 displayunit = getconf_str(CNF_DISPLAYUNIT);
507 unitdivisor = getconf_unit_divisor();
509 ColumnSpec = getconf_str(CNF_COLUMNSPEC);
510 if(SetColumnDataFromString(ColumnData, ColumnSpec, &errstr) < 0) {
512 curprog = P_REPORTER;
517 ColumnSpec = ""; /* use the default */
518 if(SetColumnDataFromString(ColumnData, ColumnSpec, &errstr) < 0) {
520 curprog = P_REPORTER;
527 for (cn = 0; ColumnData[cn].Name != NULL; cn++) {
528 if (ColumnData[cn].MaxWidth) {
529 MaxWidthsRequested = 1;
537 conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
538 logfname = vstralloc(conf_logdir, "/", "log", NULL);
542 if((logfile = fopen(logfname, "r")) == NULL) {
544 curprog = P_REPORTER;
545 curstr = vstralloc(_("could not open log "),
554 while(logfile && get_logline(logfile)) {
556 case L_START: handle_start(); break;
557 case L_FINISH: handle_finish(); break;
559 case L_INFO: handle_note(); break;
560 case L_WARNING: handle_note(); break;
562 case L_SUMMARY: handle_summary(); break;
563 case L_STATS: handle_stats(); break;
565 case L_ERROR: handle_error(); break;
566 case L_FATAL: handle_error(); break;
568 case L_DISK: handle_disk(); break;
570 case L_DONE: handle_success(curlog); break;
571 case L_SUCCESS: handle_success(curlog); break;
572 case L_CHUNKSUCCESS: handle_success(curlog); break;
573 case L_PART: handle_chunk(curlog); break;
574 case L_PARTPARTIAL: handle_chunk(curlog); break;
575 case L_CHUNK: handle_chunk(curlog); break;
576 case L_PARTIAL: handle_partial(); break;
577 case L_STRANGE: handle_strange(); break;
578 case L_FAIL: handle_failed(); break;
582 curprog = P_REPORTER;
583 curstr = vstrallocf(_("unexpected log line: %s"), curstr);
592 generate_bad_estimate();
595 subj_str = vstralloc(getconf_str(CNF_ORG),
596 " ", amflush_run ? "AMFLUSH" : "AMANDA",
597 " ", "MAIL REPORT FOR",
598 " ", nicedate(run_datestamp ? run_datestamp : "0"),
601 /* lookup the tapetype and printer type from the amanda.conf file. */
602 tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));
603 printer = getconf_str(CNF_PRINTER);
605 /* ignore SIGPIPE so if a child process dies we do not also go away */
606 signal(SIGPIPE, SIG_IGN);
608 /* open pipe to mailer */
611 /* output to a file */
612 if((mailf = fopen(outfname,"w")) == NULL) {
613 error(_("could not open output file: %s %s"), outfname, strerror(errno));
616 if (mailto != NULL) {
617 g_fprintf(mailf, "To: %s\n", mailto);
618 g_fprintf(mailf, "Subject: %s\n\n", subj_str);
624 mail_cmd = vstralloc(MAILER,
625 " -s", " \"", subj_str, "\"",
627 if((mailf = popen(mail_cmd, "w")) == NULL) {
628 error(_("could not open pipe to \"%s\": %s"),
629 mail_cmd, strerror(errno));
635 g_printf(_("No mail sent! "));
636 g_printf(_("No valid mail address has been specified in amanda.conf or on the commmand line\n"));
643 /* open pipe to print spooler if necessary) */
646 /* if the postscript_label_template (tp->lbl_templ) field is not */
647 /* the empty string (i.e. it is set to something), open the */
648 /* postscript debugging file for writing. */
650 lbl_templ = tapetype_get_lbl_templ(tp);
651 if (tp && lbl_templ && strcmp(lbl_templ, "") != 0) {
652 if ((postscript = fopen(psfname, "w")) == NULL) {
654 curprog = P_REPORTER;
655 curstr = vstrallocf(_("could not open %s: %s"),
664 if (strcmp(printer, "") != 0) /* alternate printer is defined */
665 /* print to the specified printer */
667 printer_cmd = vstralloc(LPRCMD, " ", LPRFLAG, printer, NULL);
669 printer_cmd = vstralloc(LPRCMD, NULL);
672 /* print to the default printer */
673 printer_cmd = vstralloc(LPRCMD, NULL);
676 lbl_templ = tapetype_get_lbl_templ(tp);
677 if (tp && lbl_templ && strcmp(lbl_templ, "") != 0) {
679 if ((postscript = popen(printer_cmd, "w")) == NULL) {
681 curprog = P_REPORTER;
682 curstr = vstrallocf(_("could not open pipe to %s: %s"),
683 printer_cmd, strerror(errno));
689 curprog = P_REPORTER;
690 curstr = vstrallocf(_("no printer command defined"));
703 if(!got_finish) fputs(_("*** THE DUMPS DID NOT FINISH PROPERLY!\n\n"), mailf);
706 g_fprintf(mailf, _("Hostname: %s\n"), ghostname);
707 g_fprintf(mailf, _("Org : %s\n"), getconf_str(CNF_ORG));
708 g_fprintf(mailf, _("Config : %s\n"), config_name);
709 g_fprintf(mailf, _("Date : %s\n"),
710 nicedate(run_datestamp ? run_datestamp : "0"));
711 g_fprintf(mailf,"\n");
716 if(first_failed || errsum) {
717 g_fprintf(mailf,_("\nFAILURE DUMP SUMMARY:\n"));
718 if(first_failed) output_X_summary(first_failed);
719 if(errsum) output_lines(errsum, mailf);
722 g_fprintf(mailf,_("\nSTRANGE DUMP SUMMARY:\n"));
723 if(first_strange) output_X_summary(first_strange);
725 fputs("\n\n", mailf);
730 g_fprintf(mailf,"\n\f\n");
731 g_fprintf(mailf,_("FAILED DUMP DETAILS:\n"));
732 output_lines(errdet, mailf);
735 g_fprintf(mailf,"\n\f\n");
736 g_fprintf(mailf,_("STRANGE DUMP DETAILS:\n"));
737 output_lines(strangedet, mailf);
740 g_fprintf(mailf,"\n\f\n");
741 g_fprintf(mailf,_("NOTES:\n"));
742 output_lines(notes, mailf);
744 if(sortq.head != NULL) {
745 g_fprintf(mailf,"\n\f\n");
746 g_fprintf(mailf,_("DUMP SUMMARY:\n"));
749 g_fprintf(mailf,_("\n(brought to you by Amanda version %s)\n"),
754 do_postscript_output();
758 /* close postscript file */
759 if (psfname && postscript) {
760 /* it may be that postscript is NOT opened */
764 if (postscript != NULL && pclose(postscript) != 0) {
765 error(_("printer command failed: %s"), printer_cmd);
771 /* close output file */
777 if((exitcode = pclose(mailf)) != 0) {
778 char *exitstr = str_exit_status("mail command", exitcode);
786 free_disklist(&diskq);
787 amfree(run_datestamp);
799 #define mb(f) ((f)/1024) /* kbytes -> mbutes */
800 #define du(f) ((f)/unitdivisor) /* kbytes -> displayunit */
801 #define pct(f) ((f)*100.0) /* percent */
802 #define hrmn(f) ((int)(f)+30)/3600, (((int)(f)+30)%3600)/60
803 #define mnsc(f) ((int)(f+0.5))/60, ((int)(f+0.5)) % 60
805 #define divzero(fp,a,b) \
809 g_fprintf((fp)," -- "); \
810 else if ((q = (a)/q) >= 999.95) \
811 g_fprintf((fp), "###.#"); \
813 g_fprintf((fp), "%5.1lf",q); \
815 #define divzero_wide(fp,a,b) \
819 g_fprintf((fp)," -- "); \
820 else if ((q = (a)/q) >= 99999.95) \
821 g_fprintf((fp), "#####.#"); \
823 g_fprintf((fp), "%7.1lf",q); \
830 tapetype_t *tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));
836 tapesize = tapetype_get_length(tp);
837 marksize = tapetype_get_filemark(tp);
839 tapesize = 100 * 1024 * 1024;
840 marksize = 1 * 1024 * 1024;
843 stats[2].dumpdisks = stats[0].dumpdisks + stats[1].dumpdisks;
844 stats[2].tapedisks = stats[0].tapedisks + stats[1].tapedisks;
845 stats[2].tapechunks = stats[0].tapechunks + stats[1].tapechunks;
846 stats[2].outsize = stats[0].outsize + stats[1].outsize;
847 stats[2].origsize = stats[0].origsize + stats[1].origsize;
848 stats[2].tapesize = stats[0].tapesize + stats[1].tapesize;
849 stats[2].coutsize = stats[0].coutsize + stats[1].coutsize;
850 stats[2].corigsize = stats[0].corigsize + stats[1].corigsize;
851 stats[2].taper_time = stats[0].taper_time + stats[1].taper_time;
852 stats[2].dumper_time = stats[0].dumper_time + stats[1].dumper_time;
854 if(!got_finish) /* no driver finish line, estimate total run time */
855 total_time = stats[2].taper_time + planner_time;
857 idle_time = (total_time - startup_time) - stats[2].taper_time;
858 if(idle_time < 0) idle_time = 0.0;
860 g_fprintf(mailf,_("STATISTICS:\n"));
862 _(" Total Full Incr.\n"));
864 _(" -------- -------- --------\n"));
867 _("Estimate Time (hrs:min) %2d:%02d\n"), hrmn(planner_time));
870 _("Run Time (hrs:min) %2d:%02d\n"), hrmn(total_time));
873 _("Dump Time (hrs:min) %2d:%02d %2d:%02d %2d:%02d\n"),
874 hrmn(stats[2].dumper_time), hrmn(stats[0].dumper_time),
875 hrmn(stats[1].dumper_time));
878 _("Output Size (meg) %8.1lf %8.1lf %8.1lf\n"),
879 mb(stats[2].outsize), mb(stats[0].outsize), mb(stats[1].outsize));
882 _("Original Size (meg) %8.1lf %8.1lf %8.1lf\n"),
883 mb(stats[2].origsize), mb(stats[0].origsize),
884 mb(stats[1].origsize));
886 g_fprintf(mailf, _("Avg Compressed Size (%%) "));
887 divzero(mailf, pct(stats[2].coutsize),stats[2].corigsize);
888 fputs(_(" "), mailf);
889 divzero(mailf, pct(stats[0].coutsize),stats[0].corigsize);
890 fputs(_(" "), mailf);
891 divzero(mailf, pct(stats[1].coutsize),stats[1].corigsize);
893 if(stats[1].dumpdisks > 0) fputs(_(" (level:#disks ...)"), mailf);
897 _("Filesystems Dumped %4d %4d %4d"),
898 stats[2].dumpdisks, stats[0].dumpdisks, stats[1].dumpdisks);
900 if(stats[1].dumpdisks > 0) {
902 for(lv = 1; lv < 10; lv++) if(dumpdisks[lv]) {
903 fputs(first?_(" ("):_(" "), mailf);
905 g_fprintf(mailf, _("%d:%d"), lv, dumpdisks[lv]);
911 g_fprintf(mailf, _("Avg Dump Rate (k/s) "));
912 divzero_wide(mailf, stats[2].outsize,stats[2].dumper_time);
913 fputs(_(" "), mailf);
914 divzero_wide(mailf, stats[0].outsize,stats[0].dumper_time);
915 fputs(_(" "), mailf);
916 divzero_wide(mailf, stats[1].outsize,stats[1].dumper_time);
921 _("Tape Time (hrs:min) %2d:%02d %2d:%02d %2d:%02d\n"),
922 hrmn(stats[2].taper_time), hrmn(stats[0].taper_time),
923 hrmn(stats[1].taper_time));
926 _("Tape Size (meg) %8.1lf %8.1lf %8.1lf\n"),
927 mb(stats[2].tapesize), mb(stats[0].tapesize),
928 mb(stats[1].tapesize));
930 g_fprintf(mailf, _("Tape Used (%%) "));
931 divzero(mailf, pct(stats[2].tapesize+marksize*(stats[2].tapedisks+stats[2].tapechunks)),(double)tapesize);
932 fputs(_(" "), mailf);
933 divzero(mailf, pct(stats[0].tapesize+marksize*(stats[0].tapedisks+stats[0].tapechunks)),(double)tapesize);
934 fputs(_(" "), mailf);
935 divzero(mailf, pct(stats[1].tapesize+marksize*(stats[1].tapedisks+stats[1].tapechunks)),(double)tapesize);
937 if(stats[1].tapedisks > 0) fputs(_(" (level:#disks ...)"), mailf);
941 _("Filesystems Taped %4d %4d %4d"),
942 stats[2].tapedisks, stats[0].tapedisks, stats[1].tapedisks);
944 if(stats[1].tapedisks > 0) {
946 for(lv = 1; lv < 10; lv++) if(tapedisks[lv]) {
947 fputs(first?_(" ("):_(" "), mailf);
949 g_fprintf(mailf, _("%d:%d"), lv, tapedisks[lv]);
955 if(stats[1].tapechunks > 0) fputs(_(" (level:#chunks ...)"), mailf);
959 _("Chunks Taped %4d %4d %4d"),
960 stats[2].tapechunks, stats[0].tapechunks, stats[1].tapechunks);
962 if(stats[1].tapechunks > 0) {
964 for(lv = 1; lv < 10; lv++) if(tapechunks[lv]) {
965 fputs(first?_(" ("):_(" "), mailf);
967 g_fprintf(mailf, _("%d:%d"), lv, tapechunks[lv]);
973 g_fprintf(mailf, _("Avg Tp Write Rate (k/s) "));
974 divzero_wide(mailf, stats[2].tapesize,stats[2].taper_time);
975 fputs(_(" "), mailf);
976 divzero_wide(mailf, stats[0].tapesize,stats[0].taper_time);
977 fputs(_(" "), mailf);
978 divzero_wide(mailf, stats[1].tapesize,stats[1].taper_time);
982 int label_length = (int)strlen(stats_by_tape->label) + 5;
983 g_fprintf(mailf,_("\nUSAGE BY TAPE:\n"));
984 g_fprintf(mailf,_(" %-*s Time Size %% Nb Nc\n"),
985 label_length, _("Label"));
986 for(current_tape = stats_by_tape; current_tape != NULL;
987 current_tape = current_tape->next) {
988 g_fprintf(mailf, _(" %-*s"), label_length, current_tape->label);
989 g_fprintf(mailf, _(" %2d:%02d"), hrmn(current_tape->taper_time));
990 g_fprintf(mailf, _(" %8.0lf%s "), du(current_tape->coutsize), displayunit);
991 divzero(mailf, pct(current_tape->coutsize + marksize *
992 (current_tape->tapedisks+current_tape->tapechunks)),
994 g_fprintf(mailf, _(" %4d"), current_tape->tapedisks);
995 g_fprintf(mailf, _(" %4d\n"), current_tape->tapechunks);
1003 output_tapeinfo(void)
1010 if (last_run_tapes > 0) {
1013 plural(_("The dumps were flushed to tape %s.\n"),
1014 _("The dumps were flushed to tapes %s.\n"),
1016 tape_labels ? tape_labels : "");
1019 plural(_("These dumps were to tape %s.\n"),
1020 _("These dumps were to tapes %s.\n"),
1022 tape_labels ? tape_labels : "");
1027 _("*** A TAPE ERROR OCCURRED: %s.\n"), tapestart_error);
1029 if (cmdlogfname == 1) {
1031 fputs(_("Some dumps may have been left in the holding disk.\n"),
1033 g_fprintf(mailf,"\n");
1036 GSList *holding_list, *holding_file;
1037 off_t h_size = 0, mh_size;
1039 holding_list = holding_get_files_for_flush(NULL);
1040 for(holding_file=holding_list; holding_file != NULL;
1041 holding_file = holding_file->next) {
1042 mh_size = holding_file_size((char *)holding_file->data, 1);
1049 _("There are %lld%s of dumps left in the holding disk.\n"),
1050 (long long)h_size, displayunit);
1051 if (getconf_boolean(CNF_AUTOFLUSH)) {
1052 g_fprintf(mailf, _("They will be flushed on the next run.\n"));
1054 g_fprintf(mailf, _("Run amflush to flush them to tape.\n"));
1056 g_fprintf(mailf,"\n");
1057 } else if (degraded_mode) {
1058 g_fprintf(mailf, _("No dumps are left in the holding disk. %lld%s\n"), (long long)h_size, displayunit);
1059 g_fprintf(mailf,"\n");
1063 tp = lookup_last_reusable_tape(skip);
1065 run_tapes = getconf_int(CNF_RUNTAPES);
1068 fputs(_("The next tape Amanda expects to use is: "), mailf);
1069 else if(run_tapes > 1)
1070 g_fprintf(mailf, _("The next %d tapes Amanda expects to use are: "),
1074 for (i=0 ; i < run_tapes ; i++) {
1076 if (nb_new_tape > 0) {
1077 if (nb_new_tape == 1)
1078 g_fprintf(mailf, _("1 new tape, "));
1080 g_fprintf(mailf, _("%d new tapes, "), nb_new_tape);
1083 g_fprintf(mailf, "%s", tp->label);
1084 if (i < run_tapes-1) fputs(", ", mailf);
1090 tp = lookup_last_reusable_tape(skip);
1092 if (nb_new_tape > 0) {
1093 if (nb_new_tape == 1)
1094 g_fprintf(mailf, _("1 new tape"));
1096 g_fprintf(mailf, _("%d new tapes"), nb_new_tape);
1098 fputs(".\n", mailf);
1100 run_tapes = getconf_int(CNF_RUNTAPES);
1101 print_new_tapes(mailf, run_tapes);
1109 size_t len_host=0, len_disk=0;
1110 X_summary_t *strange;
1113 for(strange=first; strange != NULL; strange = strange->next) {
1114 if(strlen(strange->hostname) > len_host)
1115 len_host = strlen(strange->hostname);
1116 if(strlen(strange->diskname) > len_disk)
1117 len_disk = strlen(strange->diskname);
1119 for(strange=first; strange != NULL; strange = strange->next) {
1120 str = vstralloc(" ", prefixstrange(strange->hostname, strange->diskname, strange->level, len_host, len_disk),
1121 " ", strange->str, NULL);
1122 g_fprintf(mailf, "%s\n", str);
1153 rc = strcmp(a->host->hostname, b->host->hostname);
1154 if(rc == 0) rc = strcmp(a->name, b->name);
1163 sortq.head = sortq.tail = NULL;
1164 while(!empty(diskq)) {
1165 dp = dequeue_disk(&diskq);
1166 if(data(dp) == NULL) { /* create one */
1167 find_repdata(dp, run_datestamp, 0);
1169 insert_disk(&sortq, dp, sort_by_name);
1179 int l = (int)strlen(s);
1195 g_snprintf(testBuf, SIZEOF(testBuf),
1196 cd->Format, cd->Width, cd->Precision, n);
1197 l = (int)strlen(testBuf);
1212 g_snprintf(testBuf, SIZEOF(testBuf),
1213 cd->Format, cd->Width, cd->Precision, d);
1214 l = (int)strlen(testBuf);
1220 static int HostName;
1225 static int Compress;
1226 static int DumpTime;
1227 static int DumpRate;
1228 static int TapeTime;
1229 static int TapeRate;
1234 /* we have to look for columspec's, that require the recalculation.
1235 * we do here the same loops over the sortq as is done in
1236 * output_summary. So, if anything is changed there, we have to
1237 * change this here also.
1246 for (i=0;ColumnData[i].Name != NULL; i++) {
1247 if (ColumnData[i].MaxWidth) {
1248 l = (int)strlen(ColumnData[i].Title);
1249 if (ColumnData[i].Width < l)
1250 ColumnData[i].Width= l;
1254 for(dp = sortq.head; dp != NULL; dp = dp->next) {
1256 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
1257 char TimeRateBuffer[40];
1259 CheckStringMax(&ColumnData[HostName], dp->host->hostname);
1260 qdevname = quote_string(dp->name);
1261 CheckStringMax(&ColumnData[Disk], qdevname);
1263 if (repdata->dumper.result == L_BOGUS &&
1264 repdata->taper.result == L_BOGUS)
1266 CheckIntMax(&ColumnData[Level], repdata->level);
1267 if(repdata->dumper.result == L_SUCCESS ||
1268 repdata->dumper.result == L_CHUNKSUCCESS) {
1269 CheckFloatMax(&ColumnData[OrigKB],
1270 (double)du(repdata->dumper.origsize));
1271 CheckFloatMax(&ColumnData[OutKB],
1272 (double)du(repdata->dumper.outsize));
1273 if(abs(repdata->dumper.outsize - repdata->dumper.origsize)< 32)
1276 f = repdata->dumper.origsize;
1277 CheckStringMax(&ColumnData[Compress],
1278 sDivZero(pct(repdata->dumper.outsize), f, Compress));
1281 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1282 "%3d:%02d", mnsc(repdata->dumper.sec));
1284 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1286 CheckStringMax(&ColumnData[DumpTime], TimeRateBuffer);
1288 CheckFloatMax(&ColumnData[DumpRate], repdata->dumper.kps);
1291 if(repdata->taper.result == L_FAIL) {
1292 CheckStringMax(&ColumnData[TapeTime], "FAILED");
1295 if(repdata->taper.result == L_SUCCESS ||
1296 repdata->taper.result == L_CHUNKSUCCESS)
1297 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1298 "%3d:%02d", mnsc(repdata->taper.sec));
1300 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1302 CheckStringMax(&ColumnData[TapeTime], TimeRateBuffer);
1304 if(repdata->taper.result == L_SUCCESS ||
1305 repdata->taper.result == L_CHUNKSUCCESS)
1306 CheckFloatMax(&ColumnData[TapeRate], repdata->taper.kps);
1308 CheckStringMax(&ColumnData[TapeRate], "N/A ");
1315 output_summary(void)
1319 char *ds="DUMPER STATS";
1320 char *ts=" TAPER STATS";
1323 int i, h, w1, wDump, wTape;
1324 double outsize, origsize;
1327 HostName = StringToColumn("HostName");
1328 Disk = StringToColumn("Disk");
1329 Level = StringToColumn("Level");
1330 OrigKB = StringToColumn("OrigKB");
1331 OutKB = StringToColumn("OutKB");
1332 Compress = StringToColumn("Compress");
1333 DumpTime = StringToColumn("DumpTime");
1334 DumpRate = StringToColumn("DumpRate");
1335 TapeTime = StringToColumn("TapeTime");
1336 TapeRate = StringToColumn("TapeRate");
1338 /* at first determine if we have to recalculate our widths */
1339 if (MaxWidthsRequested)
1342 /* title for Dumper-Stats */
1343 w1= ColWidth(HostName, Level);
1344 wDump= ColWidth(OrigKB, DumpRate);
1345 wTape= ColWidth(TapeTime, TapeRate);
1347 /* print centered top titles */
1348 h = (int)strlen(ds);
1354 g_fprintf(mailf, "%*s", w1+h, "");
1355 g_fprintf(mailf, "%-*s", wDump-h, ds);
1356 h = (int)strlen(ts);
1362 g_fprintf(mailf, "%*s", h, "");
1363 g_fprintf(mailf, "%-*s", wTape-h, ts);
1366 /* print the titles */
1367 for (i=0; ColumnData[i].Name != NULL; i++) {
1369 ColumnInfo *cd= &ColumnData[i];
1370 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1371 if (cd->Format[1] == '-')
1375 if(strcmp(cd->Title,"ORIG-KB") == 0) {
1376 /* cd->Title must be re-allocated in write-memory */
1377 cd->Title = stralloc("ORIG-KB");
1378 cd->Title[5] = displayunit[0];
1380 if(strcmp(cd->Title,"OUT-KB") == 0) {
1381 /* cd->Title must be re-allocated in write-memory */
1382 cd->Title = stralloc("OUT-KB");
1383 cd->Title[4] = displayunit[0];
1385 g_fprintf(mailf, fmt, cd->Width, cd->Title);
1389 /* print the rules */
1390 fputs(tmp=Rule(HostName, Level), mailf); amfree(tmp);
1391 fputs(tmp=Rule(OrigKB, DumpRate), mailf); amfree(tmp);
1392 fputs(tmp=Rule(TapeTime, TapeRate), mailf); amfree(tmp);
1395 for(dp = sortq.head; dp != NULL; dp = dp->next) {
1398 char TimeRateBuffer[40];
1399 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
1404 cd= &ColumnData[HostName];
1405 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1406 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, dp->host->hostname);
1408 cd= &ColumnData[Disk];
1409 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1410 devname = sanitize_string(dp->name);
1411 qdevname = quote_string(devname);
1412 devlen = strlen(qdevname);
1413 if (devlen > (size_t)cd->Width) {
1415 g_fprintf(mailf, cd->Format, cd->Width-1, cd->Precision-1,
1416 qdevname+devlen - (cd->Width-1) );
1419 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, qdevname);
1422 cd= &ColumnData[Level];
1423 if (repdata->dumper.result == L_BOGUS &&
1424 repdata->taper.result == L_BOGUS) {
1426 g_fprintf(mailf, "%*s%s\n", cd->PrefixSpace+cd->Width, "",
1427 tmp=TextRule(OrigKB, TapeRate, "NO FILE TO FLUSH"));
1429 g_fprintf(mailf, "%*s%s\n", cd->PrefixSpace+cd->Width, "",
1430 tmp=TextRule(OrigKB, TapeRate, "MISSING"));
1436 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1437 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision,repdata->level);
1439 if (repdata->dumper.result == L_SKIPPED) {
1440 g_fprintf(mailf, "%s\n",
1441 tmp=TextRule(OrigKB, TapeRate, "SKIPPED"));
1445 if (repdata->dumper.result == L_FAIL && (repdata->chunker.result != L_PARTIAL && repdata->taper.result != L_PARTIAL)) {
1446 g_fprintf(mailf, "%s\n",
1447 tmp=TextRule(OrigKB, TapeRate, "FAILED"));
1449 exit_status |= STATUS_FAILED;
1453 if(repdata->dumper.result == L_SUCCESS ||
1454 repdata->dumper.result == L_CHUNKSUCCESS)
1455 origsize = repdata->dumper.origsize;
1456 else if(repdata->taper.result == L_SUCCESS ||
1457 repdata->taper.result == L_PARTIAL)
1458 origsize = repdata->taper.origsize;
1460 origsize = repdata->chunker.origsize;
1462 if(repdata->taper.result == L_SUCCESS ||
1463 repdata->taper.result == L_CHUNKSUCCESS)
1464 outsize = repdata->taper.outsize;
1465 else if(repdata->chunker.result == L_SUCCESS ||
1466 repdata->chunker.result == L_PARTIAL ||
1467 repdata->chunker.result == L_CHUNKSUCCESS)
1468 outsize = repdata->chunker.outsize;
1469 else if (repdata->taper.result == L_PARTIAL)
1470 outsize = repdata->taper.outsize;
1472 outsize = repdata->dumper.outsize;
1474 cd= &ColumnData[OrigKB];
1475 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1476 if(isnormal(origsize))
1477 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, du(origsize));
1479 g_fprintf(mailf, "%*.*s", cd->Width, cd->Width, "N/A");
1481 cd= &ColumnData[OutKB];
1482 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1484 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, du(outsize));
1486 cd= &ColumnData[Compress];
1487 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1489 if(abs(outsize - origsize) < 32)
1491 else if(origsize < 1.0)
1496 fputs(sDivZero(pct(outsize), f, Compress), mailf);
1498 cd= &ColumnData[DumpTime];
1499 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1500 if(repdata->dumper.result == L_SUCCESS ||
1501 repdata->dumper.result == L_CHUNKSUCCESS)
1502 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1503 "%3d:%02d", mnsc(repdata->dumper.sec));
1505 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1507 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, TimeRateBuffer);
1509 cd= &ColumnData[DumpRate];
1510 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1511 if(repdata->dumper.result == L_SUCCESS ||
1512 repdata->dumper.result == L_CHUNKSUCCESS)
1513 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, repdata->dumper.kps);
1515 g_fprintf(mailf, "%*s", cd->Width, "N/A ");
1517 cd= &ColumnData[TapeTime];
1518 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1519 if(repdata->taper.result == L_FAIL) {
1520 g_fprintf(mailf, "%s\n",
1521 tmp=TextRule(TapeTime, TapeRate, "FAILED "));
1526 if(repdata->taper.result == L_SUCCESS ||
1527 repdata->taper.result == L_PARTIAL ||
1528 repdata->taper.result == L_CHUNKSUCCESS)
1529 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1530 "%3d:%02d", mnsc(repdata->taper.sec));
1532 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1534 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, TimeRateBuffer);
1536 cd= &ColumnData[TapeRate];
1537 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1538 if(repdata->taper.result == L_SUCCESS ||
1539 repdata->taper.result == L_PARTIAL ||
1540 repdata->taper.result == L_CHUNKSUCCESS)
1541 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, repdata->taper.kps);
1543 g_fprintf(mailf, "%*s", cd->Width, "N/A ");
1545 if (repdata->chunker.result == L_PARTIAL)
1546 g_fprintf(mailf, " PARTIAL");
1547 else if(repdata->taper.result == L_PARTIAL)
1548 g_fprintf(mailf, " TAPE-PARTIAL");
1558 const char *err_text)
1561 s = g_strdup_printf(_("line %d of log is bogus: <%s %s %s>\n"),
1563 logtype_str[curlog], program_str[curprog], curstr);
1564 g_printf("%s\n", s);
1565 g_printf(_(" Scan failed at: <%s>\n"), err_text);
1566 addline(&errsum, s);
1572 * Formats an integer of the form YYYYMMDDHHMMSS into the string
1573 * "Monthname DD, YYYY". A pointer to the statically allocated string
1574 * is returned, so it must be copied to other storage (or just printed)
1575 * before calling nicedate() again.
1579 const char *datestamp)
1581 static char nice[64];
1584 static char *months[13] = {
1599 int year, month, day;
1601 strncpy(date, datestamp, 8);
1603 numdate = atoi(date);
1604 year = numdate / 10000;
1605 day = numdate % 100;
1606 month = (numdate / 100) % 100;
1610 g_snprintf(nice, SIZEOF(nice), "%s %d, %d", _(months[month]), day, year);
1618 static int started = 0;
1628 skip_whitespace(s, ch);
1629 if(ch == '\0' || strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {
1634 skip_whitespace(s, ch);
1640 skip_non_whitespace(s, ch);
1642 run_datestamp = newstralloc(run_datestamp, fp);
1645 skip_whitespace(s, ch);
1646 if(ch == '\0' || strncmp_const_skip(s - 1, "label", s, ch) != 0) {
1651 skip_whitespace(s, ch);
1657 skip_non_whitespace(s, ch);
1660 label = stralloc(fp);
1664 fp = vstralloc(tape_labels, ", ", label, NULL);
1665 amfree(tape_labels);
1668 tape_labels = stralloc(label);
1673 if(stats_by_tape == NULL) {
1674 stats_by_tape = current_tape = (taper_t *)alloc(SIZEOF(taper_t));
1677 current_tape->next = (taper_t *)alloc(SIZEOF(taper_t));
1678 current_tape = current_tape->next;
1680 current_tape->label = label;
1681 current_tape->taper_time = 0.0;
1682 current_tape->coutsize = 0.0;
1683 current_tape->corigsize = 0.0;
1684 current_tape->tapedisks = 0;
1685 current_tape->tapechunks = 0;
1686 current_tape->next = NULL;
1706 skip_whitespace(s, ch);
1707 if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {
1708 return; /* ignore bogus line */
1711 skip_whitespace(s, ch);
1717 skip_non_whitespace(s, ch);
1719 run_datestamp = newstralloc(run_datestamp, fp);
1724 if(amflush_run && normal_run) {
1727 _(" reporter: both amflush and planner output in log, ignoring amflush."));
1739 if(curprog == P_DRIVER || curprog == P_AMFLUSH || curprog == P_PLANNER) {
1743 skip_whitespace(s, ch);
1744 if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {
1749 skip_whitespace(s, ch);
1754 skip_non_whitespace(s, ch); /* ignore the date string */
1756 skip_whitespace(s, ch);
1757 if(ch == '\0' || strncmp_const_skip(s - 1, "time", s, ch) != 0) {
1758 /* older planner doesn't write time */
1759 if(curprog == P_PLANNER) return;
1764 skip_whitespace(s, ch);
1769 if(sscanf(s - 1, "%lf", &a_time) != 1) {
1773 if(curprog == P_PLANNER) {
1774 planner_time = a_time;
1777 total_time = a_time;
1788 char *hostname, *diskname, *datestamp, *qdiskname;
1790 double sec, kps, nbytes, cbytes;
1794 if(curprog == P_DRIVER) {
1798 skip_whitespace(s, ch);
1799 if(ch != '\0' && strncmp_const_skip(s - 1, "startup time", s, ch) == 0) {
1800 skip_whitespace(s, ch);
1805 if(sscanf(s - 1, "%lf", &startup_time) != 1) {
1809 planner_time = startup_time;
1811 else if(ch != '\0' && strncmp_const_skip(s - 1, "hostname", s, ch) == 0) {
1812 skip_whitespace(s, ch);
1817 ghostname = stralloc(s-1);
1819 else if(ch != '\0' && strncmp_const_skip(s - 1, "estimate", s, ch) == 0) {
1820 skip_whitespace(s, ch);
1826 skip_non_whitespace(s, ch);
1828 hostname = stralloc(fp);
1831 skip_whitespace(s, ch);
1839 skip_quoted_string(s, ch);
1841 diskname = unquote_string(qdiskname);
1844 skip_whitespace(s, ch);
1852 skip_non_whitespace(s, ch);
1854 datestamp = stralloc(fp);
1856 skip_whitespace(s, ch);
1858 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
1865 skip_integer(s, ch);
1866 if(level < 0 || level > 9) {
1873 skip_whitespace(s, ch);
1875 if(sscanf(s - 1,"[sec %lf nkb %lf ckb %lf kps %lf",
1876 &sec, &nbytes, &cbytes, &kps) != 4) {
1884 dp = lookup_disk(hostname, diskname);
1886 addtoX_summary(&first_failed, &last_failed,
1887 hostname, diskname, level,
1888 _("ERROR [not in disklist]"));
1889 exit_status |= STATUS_FAILED;
1896 repdata = find_repdata(dp, datestamp, level);
1898 repdata->est_nsize = nbytes;
1899 repdata->est_csize = cbytes;
1920 str = vstrallocf(" %s: %s", program_str[curprog], curstr);
1921 addline(¬es, str);
1931 char *s = NULL, *nl;
1934 if(curlog == L_ERROR && curprog == P_TAPER) {
1938 skip_whitespace(s, ch);
1939 if(ch != '\0' && strncmp_const_skip(s - 1, "no-tape", s, ch) == 0) {
1940 skip_whitespace(s, ch);
1942 if((nl = strchr(s - 1, '\n')) != NULL) {
1945 tapestart_error = newstralloc(tapestart_error, s - 1);
1948 exit_status |= STATUS_TAPE;;
1951 /* else some other tape error, handle like other errors */
1953 /* else some other tape error, handle like other errors */
1955 s = vstrallocf(" %s: %s %s", program_str[curprog],
1956 logtype_str[curlog], curstr);
1957 addline(&errsum, s);
1964 handle_summary(void)
1971 static int nb_disk=0;
1976 char *s, *fp, *qdiskname;
1978 char *hostname = NULL, *diskname = NULL;
1980 if(curprog != P_PLANNER && curprog != P_AMFLUSH) {
1986 for(dp = diskq.head; dp != NULL; dp = dp->next)
1994 skip_whitespace(s, ch);
2000 skip_non_whitespace(s, ch);
2002 hostname = newstralloc(hostname, fp);
2005 skip_whitespace(s, ch);
2012 skip_quoted_string(s, ch);
2014 diskname = unquote_string(qdiskname);
2017 dp = lookup_disk(hostname, diskname);
2019 dp = add_disk(&diskq, hostname, diskname);
2027 /* XXX Just a placeholder, in case we decide to do something with L_CHUNK
2028 * log entries. Right now they're just the equivalent of L_SUCCESS, but only
2029 * for a split chunk of the overall dumpfile.
2036 double sec, kps, kbytes;
2041 char *hostname = NULL;
2042 char *diskname = NULL;
2050 if(curprog != P_TAPER) {
2058 skip_whitespace(s, ch);
2064 if (logtype == L_PART || logtype == L_PARTPARTIAL) {
2066 skip_non_whitespace(s, ch);
2068 label = stralloc(fp);
2071 skip_whitespace(s, ch);
2072 if(ch == '\0' || sscanf(s - 1, "%d", &fileno) != 1) {
2077 skip_integer(s, ch);
2078 skip_whitespace(s, ch);
2088 skip_non_whitespace(s, ch);
2090 hostname = stralloc(fp);
2093 skip_whitespace(s, ch);
2100 skip_quoted_string(s, ch);
2102 diskname = unquote_string(fp);
2105 skip_whitespace(s, ch);
2113 skip_non_whitespace(s, ch);
2115 datestamp = stralloc(fp);
2118 skip_whitespace(s, ch);
2119 if(ch == '\0' || sscanf(s - 1, "%d", &chunk) != 1) {
2126 skip_integer(s, ch);
2128 if (ch != '\0' && s[-1] == '/') {
2130 if (sscanf(s - 1, "%d", &totpart) != 1) {
2137 skip_integer(s, ch);
2140 skip_whitespace(s, ch);
2141 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2148 skip_integer(s, ch);
2151 if(level < 0 || level > 9) {
2159 skip_whitespace(s, ch);
2160 if(sscanf(s - 1,"[sec %lf kb %lf kps %lf", &sec, &kbytes, &kps) != 3) {
2169 dp = lookup_disk(hostname, diskname);
2173 str = vstrallocf(_(" %s ERROR [not in disklist]"),
2174 prefix(hostname, diskname, level));
2175 addline(&errsum, str);
2183 repdata = find_repdata(dp, datestamp, level);
2185 sp = &(repdata->taper);
2193 if(current_tape == NULL) {
2194 error("current_tape == NULL");
2196 if (sp->filenum == 0) {
2197 sp->filenum = ++tapefcount;
2198 sp->tapelabel = current_tape->label;
2200 tapechunks[level] +=1;
2201 stats[i].tapechunks +=1;
2202 current_tape->taper_time += sec;
2203 current_tape->coutsize += kbytes;
2204 current_tape->tapechunks += 1;
2215 double kbytes = 0.0;
2216 double origkb = 0.0;
2219 char *s, *fp, *qdiskname;
2221 char *hostname = NULL;
2222 char *diskname = NULL;
2230 if(curprog != P_TAPER && curprog != P_DUMPER && curprog != P_PLANNER &&
2231 curprog != P_CHUNKER) {
2239 skip_whitespace(s, ch);
2245 skip_non_whitespace(s, ch);
2247 hostname = stralloc(fp);
2250 skip_whitespace(s, ch);
2257 skip_quoted_string(s, ch);
2259 diskname = unquote_string(qdiskname);
2261 skip_whitespace(s, ch);
2269 skip_non_whitespace(s, ch);
2271 datestamp = stralloc(fp);
2274 //datestamp is optional
2275 if(strlen(datestamp) < 6) {
2276 totpart = atoi(datestamp);
2277 datestamp = newstralloc(datestamp, run_datestamp);
2280 skip_whitespace(s, ch);
2281 if(ch == '\0' || sscanf(s - 1, "%d", &totpart) != 1) {
2288 skip_integer(s, ch);
2291 skip_whitespace(s, ch);
2293 //totpart is optional
2296 if (*(s-1) == '[') {
2300 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2307 skip_integer(s, ch);
2308 skip_whitespace(s, ch);
2312 if(level < 0 || level > 9) {
2319 /* Planner success messages (for skipped
2320 dumps) do not contain statistics */
2321 if(curprog != P_PLANNER) {
2324 if((curprog != P_DUMPER)
2325 || (sscanf(s - 1,"[sec %lf kb %lf kps %lf orig-kb %lf",
2326 &sec, &kbytes, &kps, &origkb) != 4)) {
2328 if(sscanf(s - 1,"[sec %lf kb %lf kps %lf",
2329 &sec, &kbytes, &kps) != 3) {
2338 if(!isnormal(origkb))
2344 dp = lookup_disk(hostname, diskname);
2346 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2347 _("ERROR [not in disklist]"));
2348 exit_status |= STATUS_FAILED;
2355 repdata = find_repdata(dp, datestamp, level);
2357 if(curprog == P_PLANNER) {
2358 repdata->dumper.result = L_SKIPPED;
2365 if(curprog == P_TAPER)
2366 sp = &(repdata->taper);
2367 else if(curprog == P_DUMPER)
2368 sp = &(repdata->dumper);
2369 else sp = &(repdata->chunker);
2373 if (origkb < 0.0 && (curprog == P_CHUNKER || curprog == P_TAPER) &&
2374 isnormal(repdata->dumper.outsize)) {
2375 /* take origkb from DUMPER line */
2376 origkb = repdata->dumper.outsize;
2377 } else if (origkb < 0.0) {
2378 /* take origkb from infofile, needed for amflush */
2383 get_info(hostname, diskname, &inf);
2384 tm = localtime(&inf.inf[level].date);
2386 Idatestamp = 10000*(tm->tm_year+1900) +
2387 100*(tm->tm_mon+1) + tm->tm_mday;
2389 Idatestamp = 19000101;
2392 if(atoi(datestamp) == Idatestamp) {
2393 /* grab original size from record */
2394 origkb = (double)inf.inf[level].size;
2400 if (curprog == P_DUMPER &&
2401 (sp->result == L_FAIL || sp->result == L_PARTIAL)) {
2402 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2403 _("was successfully retried"));
2410 sp->result = L_SUCCESS;
2411 sp->datestamp = repdata->datestamp;
2414 sp->origsize = origkb;
2415 sp->outsize = kbytes;
2417 if(curprog == P_TAPER) {
2418 if(current_tape == NULL) {
2419 error(_("current_tape == NULL"));
2422 stats[i].taper_time += sec;
2423 sp->filenum = ++tapefcount;
2424 sp->tapelabel = current_tape->label;
2425 sp->totpart = totpart;
2426 tapedisks[level] +=1;
2427 stats[i].tapedisks +=1;
2428 stats[i].tapesize += kbytes;
2429 sp->outsize = kbytes;
2430 if(!isnormal(repdata->chunker.outsize) && isnormal(repdata->dumper.outsize)) { /* dump to tape */
2431 stats[i].outsize += kbytes;
2432 if (abs(kbytes - origkb) >= 32) {
2433 /* server compressed */
2434 stats[i].corigsize += origkb;
2435 stats[i].coutsize += kbytes;
2438 current_tape->tapedisks += 1;
2441 if(curprog == P_DUMPER) {
2442 stats[i].dumper_time += sec;
2443 if (abs(kbytes - origkb) < 32) {
2444 /* not client compressed */
2445 sp->origsize = kbytes;
2448 /* client compressed */
2449 stats[i].corigsize += sp->origsize;
2450 stats[i].coutsize += kbytes;
2452 dumpdisks[level] +=1;
2453 stats[i].dumpdisks +=1;
2454 stats[i].origsize += sp->origsize;
2457 if(curprog == P_CHUNKER) {
2458 sp->outsize = kbytes;
2459 stats[i].outsize += kbytes;
2460 if (abs(kbytes - origkb) >= 32) {
2461 /* server compressed */
2462 stats[i].corigsize += origkb;
2463 stats[i].coutsize += kbytes;
2470 handle_partial(void)
2475 repdata = handle_success(L_PARTIAL);
2479 if(curprog == P_TAPER)
2480 sp = &(repdata->taper);
2481 else if(curprog == P_DUMPER)
2482 sp = &(repdata->dumper);
2483 else sp = &(repdata->chunker);
2485 sp->result = L_PARTIAL;
2489 handle_strange(void)
2492 char *strangestr = NULL;
2496 repdata = handle_success(L_SUCCESS);
2500 qdisk = quote_string(repdata->disk->name);
2502 addline(&strangedet,"");
2503 str = vstrallocf("/-- %s STRANGE",
2504 prefix(repdata->disk->host->hostname, qdisk, repdata->level));
2505 addline(&strangedet, str);
2508 while(contline_next()) {
2510 get_logline(logfile);
2512 if(strncmp_const_skip(curstr, "sendbackup: warning ", s, ch) == 0) {
2513 strangestr = newstralloc(strangestr, s);
2515 addline(&strangedet, curstr);
2517 addline(&strangedet,"\\--------");
2519 str = vstrallocf("STRANGE %s", strangestr? strangestr : _("(see below)"));
2520 addtoX_summary(&first_strange, &last_strange,
2521 repdata->disk->host->hostname, qdisk, repdata->level, str);
2522 exit_status |= STATUS_STRANGE;
2537 char *s, *fp, *qdiskname;
2549 skip_whitespace(s, ch);
2555 skip_non_whitespace(s, ch);
2558 skip_whitespace(s, ch);
2564 skip_quoted_string(s, ch);
2566 diskname = unquote_string(qdiskname);
2568 skip_whitespace(s, ch);
2575 skip_non_whitespace(s, ch);
2577 datestamp = stralloc(fp);
2579 if(strlen(datestamp) < 3) { /* there is no datestamp, it's the level */
2580 level = atoi(datestamp);
2581 datestamp = newstralloc(datestamp, run_datestamp);
2583 else { /* read the level */
2584 skip_whitespace(s, ch);
2585 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2591 skip_integer(s, ch);
2594 skip_whitespace(s, ch);
2602 if((s = strchr(errstr, '\n')) != NULL) {
2606 dp = lookup_disk(hostname, diskname);
2609 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2610 _("ERROR [not in disklist]"));
2612 repdata = find_repdata(dp, datestamp, level);
2614 if(curprog == P_TAPER)
2615 sp = &(repdata->taper);
2616 else sp = &(repdata->dumper);
2618 if(sp->result != L_SUCCESS)
2619 sp->result = L_FAIL;
2623 str = vstrallocf(_("FAILED %s"), errstr);
2624 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2628 if(curprog == P_DUMPER) {
2629 addline(&errdet,"");
2630 str = vstrallocf("/-- %s FAILED %s",
2631 prefix(hostname, qdiskname, level),
2633 addline(&errdet, str);
2635 while(contline_next()) {
2636 get_logline(logfile);
2637 addline(&errdet, curstr);
2639 addline(&errdet,"\\--------");
2640 exit_status |= STATUS_FAILED;
2647 generate_missing(void)
2652 for(dp = diskq.head; dp != NULL; dp = dp->next) {
2653 if(dp->todo && data(dp) == NULL) {
2654 qdisk = quote_string(dp->name);
2655 addtoX_summary(&first_failed, &last_failed, dp->host->hostname,
2656 qdisk, -987, _("RESULTS MISSING"));
2657 exit_status |= STATUS_MISSING;
2664 generate_bad_estimate(void)
2671 for(dp = diskq.head; dp != NULL; dp = dp->next) {
2673 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
2674 if(repdata->est_csize >= 0.1) {
2675 if(repdata->taper.result == L_SUCCESS ||
2676 repdata->taper.result == L_CHUNKSUCCESS)
2677 outsize = repdata->taper.outsize;
2678 else if(repdata->chunker.result == L_SUCCESS ||
2679 repdata->chunker.result == L_PARTIAL ||
2680 repdata->chunker.result == L_CHUNKSUCCESS)
2681 outsize = repdata->chunker.outsize;
2682 else if(repdata->taper.result == L_PARTIAL)
2683 outsize = repdata->taper.outsize;
2685 outsize = repdata->dumper.outsize;
2687 if(repdata->est_csize * 0.9 > outsize) {
2689 _(" big estimate: %s %s %d"),
2690 repdata->disk->host->hostname,
2691 repdata->disk->name,
2696 _(" est: %.0lf%s out %.0lf%s"),
2697 du(repdata->est_csize), displayunit,
2698 du(outsize), displayunit);
2702 else if(repdata->est_csize * 1.1 < outsize) {
2704 _(" small estimate: %s %s %d"),
2705 repdata->disk->host->hostname,
2706 repdata->disk->name,
2711 _(" est: %.0lf%s out %.0lf%s"),
2712 du(repdata->est_csize), displayunit,
2713 du(outsize), displayunit);
2729 static char *str = NULL;
2731 if (level == -987) {
2732 str = newvstrallocf(str, " %s %s",
2733 host ? host : _("(host?)"),
2734 disk ? disk : _("(disk?)"));
2736 str = newvstrallocf(str, " %s %s lev %d",
2737 host ? host : _("(host?)"),
2738 disk ? disk : _("(disk?)"),
2755 static char *str = NULL;
2757 h=alloc(len_host+1);
2759 strncpy(h, host, len_host);
2761 strncpy(h, _("(host?)"), len_host);
2764 for(l = strlen(h); l < len_host; l++) {
2767 d=alloc(len_disk+1);
2769 strncpy(d, disk, len_disk);
2771 strncpy(d, _("(disk?)"), len_disk);
2774 for(l = strlen(d); l < len_disk; l++) {
2777 if (level == -987) {
2778 str = newvstrallocf(str, " %s %s", h, d);
2780 str = newvstrallocf(str, " %s %s lev %d", h, d, level);
2790 X_summary_t **first,
2797 X_summary_t *X_summary;
2799 X_summary = alloc(SIZEOF(X_summary_t));
2800 X_summary->hostname = stralloc(host);
2801 X_summary->diskname = stralloc(disk);
2802 X_summary->level = level;
2803 X_summary->str = stralloc(str);
2804 X_summary->next = NULL;
2805 if (*first == NULL) {
2809 (*last)->next = X_summary;
2822 lbl_templ = config_dir_relative(lbl_templ);
2823 if ((fd = open(lbl_templ, 0)) < 0) {
2825 curprog = P_REPORTER;
2826 curstr = vstrallocf(_("could not open PostScript template file %s: %s"),
2827 lbl_templ, strerror(errno));
2831 afclose(postscript);
2834 while ((numread = read(fd, buf, SIZEOF(buf))) > 0) {
2835 if (fwrite(buf, (size_t)numread, 1, postscript) != 1) {
2837 curprog = P_REPORTER;
2838 curstr = vstrallocf(_("error copying PostScript template file %s: %s"),
2839 lbl_templ, strerror(errno));
2843 afclose(postscript);
2849 curprog = P_REPORTER;
2850 curstr = vstrallocf(_("error reading PostScript template file %s: %s"),
2851 lbl_templ, strerror(errno));
2855 afclose(postscript);
2864 /*@keep@*/ disk_t *dp,
2868 repdata_t *repdata, *prev;
2871 datestamp = run_datestamp;
2873 for(repdata = data(dp); repdata != NULL && (repdata->level != level || strcmp(repdata->datestamp,datestamp)!=0); repdata = repdata->next) {
2877 repdata = (repdata_t *)alloc(SIZEOF(repdata_t));
2878 memset(repdata, '\0', SIZEOF(repdata_t));
2880 repdata->datestamp = stralloc(datestamp ? datestamp : "");
2881 repdata->level = level;
2882 repdata->dumper.result = L_BOGUS;
2883 repdata->taper.result = L_BOGUS;
2884 repdata->next = NULL;
2886 prev->next = repdata;
2888 dp->up = (void *)repdata;
2895 do_postscript_output(void)
2897 tapetype_t *tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));
2900 double outsize, origsize;
2907 tapesize = tapetype_get_length(tp);
2908 marksize = tapetype_get_filemark(tp);
2910 for(current_tape = stats_by_tape; current_tape != NULL;
2911 current_tape = current_tape->next) {
2913 if (current_tape->label == NULL) {
2917 copy_template_file(tapetype_get_lbl_templ(tp));
2919 if (postscript == NULL)
2922 /* generate a few elements */
2923 g_fprintf(postscript,"(%s) DrawDate\n\n",
2924 nicedate(run_datestamp ? run_datestamp : "0"));
2925 g_fprintf(postscript,_("(Amanda Version %s) DrawVers\n"),version());
2926 g_fprintf(postscript,"(%s) DrawTitle\n", current_tape->label);
2929 g_fprintf(postscript, "(Total Size: %6.1lf MB) DrawStat\n",
2930 mb(current_tape->coutsize));
2931 g_fprintf(postscript, _("(Tape Used (%%) "));
2932 divzero(postscript, pct(current_tape->coutsize +
2933 marksize * (current_tape->tapedisks + current_tape->tapechunks)),
2935 g_fprintf(postscript," %%) DrawStat\n");
2936 g_fprintf(postscript, _("(Compression Ratio: "));
2937 divzero(postscript, pct(current_tape->coutsize),current_tape->corigsize);
2938 g_fprintf(postscript," %%) DrawStat\n");
2939 g_fprintf(postscript,_("(Filesystems Taped: %4d) DrawStat\n"),
2940 current_tape->tapedisks);
2944 g_fprintf(postscript,
2945 "(-) (%s) (-) ( 0) ( 32) ( 32) DrawHost\n",
2946 current_tape->label);
2948 for(dp = sortq.head; dp != NULL; dp = dp->next) {
2949 if (dp->todo == 0) {
2952 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
2954 if(repdata->taper.tapelabel != current_tape->label) {
2958 if(repdata->dumper.result == L_SUCCESS ||
2959 repdata->dumper.result == L_PARTIAL)
2960 origsize = repdata->dumper.origsize;
2962 origsize = repdata->taper.origsize;
2964 if(repdata->taper.result == L_SUCCESS ||
2965 repdata->taper.result == L_PARTIAL)
2966 outsize = repdata->taper.outsize;
2968 outsize = repdata->dumper.outsize;
2970 if (repdata->taper.result == L_SUCCESS ||
2971 repdata->taper.result == L_PARTIAL) {
2972 if(isnormal(origsize)) {
2973 g_fprintf(postscript,"(%s) (%s) (%d) (%3.0d) (%8.0lf) (%8.0lf) DrawHost\n",
2974 dp->host->hostname, dp->name, repdata->level,
2975 repdata->taper.filenum, origsize,
2979 g_fprintf(postscript,"(%s) (%s) (%d) (%3.0d) (%8s) (%8.0lf) DrawHost\n",
2980 dp->host->hostname, dp->name, repdata->level,
2981 repdata->taper.filenum, "N/A",
2988 g_fprintf(postscript,"\nshowpage\n");