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)
1005 tape_t *tp, *lasttp;
1009 if (last_run_tapes > 0) {
1012 plural(_("The dumps were flushed to tape %s.\n"),
1013 _("The dumps were flushed to tapes %s.\n"),
1015 tape_labels ? tape_labels : "");
1018 plural(_("These dumps were to tape %s.\n"),
1019 _("These dumps were to tapes %s.\n"),
1021 tape_labels ? tape_labels : "");
1026 _("*** A TAPE ERROR OCCURRED: %s.\n"), tapestart_error);
1028 if (cmdlogfname == 1) {
1030 fputs(_("Some dumps may have been left in the holding disk.\n"),
1032 g_fprintf(mailf,"\n");
1035 GSList *holding_list, *holding_file;
1036 off_t h_size = 0, mh_size;
1038 holding_list = holding_get_files_for_flush(NULL);
1039 for(holding_file=holding_list; holding_file != NULL;
1040 holding_file = holding_file->next) {
1041 mh_size = holding_file_size((char *)holding_file->data, 1);
1048 _("There are %lld%s of dumps left in the holding disk.\n"),
1049 (long long)h_size, displayunit);
1050 if (getconf_boolean(CNF_AUTOFLUSH)) {
1051 g_fprintf(mailf, _("They will be flushed on the next run.\n"));
1053 g_fprintf(mailf, _("Run amflush to flush them to tape.\n"));
1055 g_fprintf(mailf,"\n");
1056 } else if (degraded_mode) {
1057 g_fprintf(mailf, _("No dumps are left in the holding disk. %lld%s\n"), (long long)h_size, displayunit);
1058 g_fprintf(mailf,"\n");
1062 tp = lookup_last_reusable_tape(skip);
1064 run_tapes = getconf_int(CNF_RUNTAPES);
1067 fputs(_("The next tape Amanda expects to use is: "), mailf);
1068 else if(run_tapes > 1)
1069 g_fprintf(mailf, _("The next %d tapes Amanda expects to use are: "),
1072 while(run_tapes > 0) {
1074 g_fprintf(mailf, "%s", tp->label);
1077 g_fprintf(mailf, _("a new tape"));
1079 g_fprintf(mailf, _("%d new tapes"), run_tapes);
1083 if(run_tapes > 1) fputs(", ", mailf);
1087 tp = lookup_last_reusable_tape(skip);
1089 fputs(".\n", mailf);
1091 lasttp = lookup_tapepos(lookup_nb_tape());
1092 run_tapes = getconf_int(CNF_RUNTAPES);
1093 if(lasttp && run_tapes > 0 && strcmp(lasttp->datestamp,"0") == 0) {
1095 while(lasttp && run_tapes > 0 && strcmp(lasttp->datestamp,"0") == 0) {
1097 lasttp = lasttp->prev;
1100 lasttp = lookup_tapepos(lookup_nb_tape());
1102 g_fprintf(mailf, _("The next new tape already labelled is: %s.\n"),
1106 g_fprintf(mailf, _("The next %d new tapes already labelled are: %s"), c,
1108 lasttp = lasttp->prev;
1110 while(lasttp && c > 0 && strcmp(lasttp->datestamp,"0") == 0) {
1111 g_fprintf(mailf, ", %s", lasttp->label);
1112 lasttp = lasttp->prev;
1115 g_fprintf(mailf, ".\n");
1125 size_t len_host=0, len_disk=0;
1126 X_summary_t *strange;
1129 for(strange=first; strange != NULL; strange = strange->next) {
1130 if(strlen(strange->hostname) > len_host)
1131 len_host = strlen(strange->hostname);
1132 if(strlen(strange->diskname) > len_disk)
1133 len_disk = strlen(strange->diskname);
1135 for(strange=first; strange != NULL; strange = strange->next) {
1136 str = vstralloc(" ", prefixstrange(strange->hostname, strange->diskname, strange->level, len_host, len_disk),
1137 " ", strange->str, NULL);
1138 g_fprintf(mailf, "%s\n", str);
1169 rc = strcmp(a->host->hostname, b->host->hostname);
1170 if(rc == 0) rc = strcmp(a->name, b->name);
1179 sortq.head = sortq.tail = NULL;
1180 while(!empty(diskq)) {
1181 dp = dequeue_disk(&diskq);
1182 if(data(dp) == NULL) { /* create one */
1183 find_repdata(dp, run_datestamp, 0);
1185 insert_disk(&sortq, dp, sort_by_name);
1195 int l = (int)strlen(s);
1211 g_snprintf(testBuf, SIZEOF(testBuf),
1212 cd->Format, cd->Width, cd->Precision, n);
1213 l = (int)strlen(testBuf);
1228 g_snprintf(testBuf, SIZEOF(testBuf),
1229 cd->Format, cd->Width, cd->Precision, d);
1230 l = (int)strlen(testBuf);
1236 static int HostName;
1241 static int Compress;
1242 static int DumpTime;
1243 static int DumpRate;
1244 static int TapeTime;
1245 static int TapeRate;
1250 /* we have to look for columspec's, that require the recalculation.
1251 * we do here the same loops over the sortq as is done in
1252 * output_summary. So, if anything is changed there, we have to
1253 * change this here also.
1262 for (i=0;ColumnData[i].Name != NULL; i++) {
1263 if (ColumnData[i].MaxWidth) {
1264 l = (int)strlen(ColumnData[i].Title);
1265 if (ColumnData[i].Width < l)
1266 ColumnData[i].Width= l;
1270 for(dp = sortq.head; dp != NULL; dp = dp->next) {
1272 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
1273 char TimeRateBuffer[40];
1275 CheckStringMax(&ColumnData[HostName], dp->host->hostname);
1276 qdevname = quote_string(dp->name);
1277 CheckStringMax(&ColumnData[Disk], qdevname);
1279 if (repdata->dumper.result == L_BOGUS &&
1280 repdata->taper.result == L_BOGUS)
1282 CheckIntMax(&ColumnData[Level], repdata->level);
1283 if(repdata->dumper.result == L_SUCCESS ||
1284 repdata->dumper.result == L_CHUNKSUCCESS) {
1285 CheckFloatMax(&ColumnData[OrigKB],
1286 (double)du(repdata->dumper.origsize));
1287 CheckFloatMax(&ColumnData[OutKB],
1288 (double)du(repdata->dumper.outsize));
1289 if(abs(repdata->dumper.outsize - repdata->dumper.origsize)< 32)
1292 f = repdata->dumper.origsize;
1293 CheckStringMax(&ColumnData[Compress],
1294 sDivZero(pct(repdata->dumper.outsize), f, Compress));
1297 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1298 "%3d:%02d", mnsc(repdata->dumper.sec));
1300 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1302 CheckStringMax(&ColumnData[DumpTime], TimeRateBuffer);
1304 CheckFloatMax(&ColumnData[DumpRate], repdata->dumper.kps);
1307 if(repdata->taper.result == L_FAIL) {
1308 CheckStringMax(&ColumnData[TapeTime], "FAILED");
1311 if(repdata->taper.result == L_SUCCESS ||
1312 repdata->taper.result == L_CHUNKSUCCESS)
1313 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1314 "%3d:%02d", mnsc(repdata->taper.sec));
1316 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1318 CheckStringMax(&ColumnData[TapeTime], TimeRateBuffer);
1320 if(repdata->taper.result == L_SUCCESS ||
1321 repdata->taper.result == L_CHUNKSUCCESS)
1322 CheckFloatMax(&ColumnData[TapeRate], repdata->taper.kps);
1324 CheckStringMax(&ColumnData[TapeRate], "N/A ");
1331 output_summary(void)
1335 char *ds="DUMPER STATS";
1336 char *ts=" TAPER STATS";
1339 int i, h, w1, wDump, wTape;
1340 double outsize, origsize;
1343 HostName = StringToColumn("HostName");
1344 Disk = StringToColumn("Disk");
1345 Level = StringToColumn("Level");
1346 OrigKB = StringToColumn("OrigKB");
1347 OutKB = StringToColumn("OutKB");
1348 Compress = StringToColumn("Compress");
1349 DumpTime = StringToColumn("DumpTime");
1350 DumpRate = StringToColumn("DumpRate");
1351 TapeTime = StringToColumn("TapeTime");
1352 TapeRate = StringToColumn("TapeRate");
1354 /* at first determine if we have to recalculate our widths */
1355 if (MaxWidthsRequested)
1358 /* title for Dumper-Stats */
1359 w1= ColWidth(HostName, Level);
1360 wDump= ColWidth(OrigKB, DumpRate);
1361 wTape= ColWidth(TapeTime, TapeRate);
1363 /* print centered top titles */
1364 h = (int)strlen(ds);
1370 g_fprintf(mailf, "%*s", w1+h, "");
1371 g_fprintf(mailf, "%-*s", wDump-h, ds);
1372 h = (int)strlen(ts);
1378 g_fprintf(mailf, "%*s", h, "");
1379 g_fprintf(mailf, "%-*s", wTape-h, ts);
1382 /* print the titles */
1383 for (i=0; ColumnData[i].Name != NULL; i++) {
1385 ColumnInfo *cd= &ColumnData[i];
1386 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1387 if (cd->Format[1] == '-')
1391 if(strcmp(cd->Title,"ORIG-KB") == 0) {
1392 /* cd->Title must be re-allocated in write-memory */
1393 cd->Title = stralloc("ORIG-KB");
1394 cd->Title[5] = displayunit[0];
1396 if(strcmp(cd->Title,"OUT-KB") == 0) {
1397 /* cd->Title must be re-allocated in write-memory */
1398 cd->Title = stralloc("OUT-KB");
1399 cd->Title[4] = displayunit[0];
1401 g_fprintf(mailf, fmt, cd->Width, cd->Title);
1405 /* print the rules */
1406 fputs(tmp=Rule(HostName, Level), mailf); amfree(tmp);
1407 fputs(tmp=Rule(OrigKB, DumpRate), mailf); amfree(tmp);
1408 fputs(tmp=Rule(TapeTime, TapeRate), mailf); amfree(tmp);
1411 for(dp = sortq.head; dp != NULL; dp = dp->next) {
1414 char TimeRateBuffer[40];
1415 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
1420 cd= &ColumnData[HostName];
1421 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1422 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, dp->host->hostname);
1424 cd= &ColumnData[Disk];
1425 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1426 devname = sanitize_string(dp->name);
1427 qdevname = quote_string(devname);
1428 devlen = strlen(qdevname);
1429 if (devlen > (size_t)cd->Width) {
1431 g_fprintf(mailf, cd->Format, cd->Width-1, cd->Precision-1,
1432 qdevname+devlen - (cd->Width-1) );
1435 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, qdevname);
1438 cd= &ColumnData[Level];
1439 if (repdata->dumper.result == L_BOGUS &&
1440 repdata->taper.result == L_BOGUS) {
1442 g_fprintf(mailf, "%*s%s\n", cd->PrefixSpace+cd->Width, "",
1443 tmp=TextRule(OrigKB, TapeRate, "NO FILE TO FLUSH"));
1445 g_fprintf(mailf, "%*s%s\n", cd->PrefixSpace+cd->Width, "",
1446 tmp=TextRule(OrigKB, TapeRate, "MISSING"));
1452 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1453 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision,repdata->level);
1455 if (repdata->dumper.result == L_SKIPPED) {
1456 g_fprintf(mailf, "%s\n",
1457 tmp=TextRule(OrigKB, TapeRate, "SKIPPED"));
1461 if (repdata->dumper.result == L_FAIL && (repdata->chunker.result != L_PARTIAL && repdata->taper.result != L_PARTIAL)) {
1462 g_fprintf(mailf, "%s\n",
1463 tmp=TextRule(OrigKB, TapeRate, "FAILED"));
1465 exit_status |= STATUS_FAILED;
1469 if(repdata->dumper.result == L_SUCCESS ||
1470 repdata->dumper.result == L_CHUNKSUCCESS)
1471 origsize = repdata->dumper.origsize;
1472 else if(repdata->taper.result == L_SUCCESS ||
1473 repdata->taper.result == L_PARTIAL)
1474 origsize = repdata->taper.origsize;
1476 origsize = repdata->chunker.origsize;
1478 if(repdata->taper.result == L_SUCCESS ||
1479 repdata->taper.result == L_CHUNKSUCCESS)
1480 outsize = repdata->taper.outsize;
1481 else if(repdata->chunker.result == L_SUCCESS ||
1482 repdata->chunker.result == L_PARTIAL ||
1483 repdata->chunker.result == L_CHUNKSUCCESS)
1484 outsize = repdata->chunker.outsize;
1485 else if (repdata->taper.result == L_PARTIAL)
1486 outsize = repdata->taper.outsize;
1488 outsize = repdata->dumper.outsize;
1490 cd= &ColumnData[OrigKB];
1491 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1492 if(isnormal(origsize))
1493 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, du(origsize));
1495 g_fprintf(mailf, "%*.*s", cd->Width, cd->Width, "N/A");
1497 cd= &ColumnData[OutKB];
1498 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1500 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, du(outsize));
1502 cd= &ColumnData[Compress];
1503 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1505 if(abs(outsize - origsize) < 32)
1507 else if(origsize < 1.0)
1512 fputs(sDivZero(pct(outsize), f, Compress), mailf);
1514 cd= &ColumnData[DumpTime];
1515 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1516 if(repdata->dumper.result == L_SUCCESS ||
1517 repdata->dumper.result == L_CHUNKSUCCESS)
1518 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1519 "%3d:%02d", mnsc(repdata->dumper.sec));
1521 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1523 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, TimeRateBuffer);
1525 cd= &ColumnData[DumpRate];
1526 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1527 if(repdata->dumper.result == L_SUCCESS ||
1528 repdata->dumper.result == L_CHUNKSUCCESS)
1529 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, repdata->dumper.kps);
1531 g_fprintf(mailf, "%*s", cd->Width, "N/A ");
1533 cd= &ColumnData[TapeTime];
1534 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1535 if(repdata->taper.result == L_FAIL) {
1536 g_fprintf(mailf, "%s\n",
1537 tmp=TextRule(TapeTime, TapeRate, "FAILED "));
1542 if(repdata->taper.result == L_SUCCESS ||
1543 repdata->taper.result == L_PARTIAL ||
1544 repdata->taper.result == L_CHUNKSUCCESS)
1545 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1546 "%3d:%02d", mnsc(repdata->taper.sec));
1548 g_snprintf(TimeRateBuffer, SIZEOF(TimeRateBuffer),
1550 g_fprintf(mailf, cd->Format, cd->Width, cd->Width, TimeRateBuffer);
1552 cd= &ColumnData[TapeRate];
1553 g_fprintf(mailf, "%*s", cd->PrefixSpace, "");
1554 if(repdata->taper.result == L_SUCCESS ||
1555 repdata->taper.result == L_PARTIAL ||
1556 repdata->taper.result == L_CHUNKSUCCESS)
1557 g_fprintf(mailf, cd->Format, cd->Width, cd->Precision, repdata->taper.kps);
1559 g_fprintf(mailf, "%*s", cd->Width, "N/A ");
1561 if (repdata->chunker.result == L_PARTIAL)
1562 g_fprintf(mailf, " PARTIAL");
1563 else if(repdata->taper.result == L_PARTIAL)
1564 g_fprintf(mailf, " TAPE-PARTIAL");
1574 const char *err_text)
1577 s = g_strdup_printf(_("line %d of log is bogus: <%s %s %s>\n"),
1579 logtype_str[curlog], program_str[curprog], curstr);
1580 g_printf("%s\n", s);
1581 g_printf(_(" Scan failed at: <%s>\n"), err_text);
1582 addline(&errsum, s);
1588 * Formats an integer of the form YYYYMMDDHHMMSS into the string
1589 * "Monthname DD, YYYY". A pointer to the statically allocated string
1590 * is returned, so it must be copied to other storage (or just printed)
1591 * before calling nicedate() again.
1595 const char *datestamp)
1597 static char nice[64];
1600 static char *months[13] = {
1615 int year, month, day;
1617 strncpy(date, datestamp, 8);
1619 numdate = atoi(date);
1620 year = numdate / 10000;
1621 day = numdate % 100;
1622 month = (numdate / 100) % 100;
1626 g_snprintf(nice, SIZEOF(nice), "%s %d, %d", _(months[month]), day, year);
1634 static int started = 0;
1644 skip_whitespace(s, ch);
1645 if(ch == '\0' || strncmp_const_skip(s - 1, "datestamp", s, ch) != 0) {
1650 skip_whitespace(s, ch);
1656 skip_non_whitespace(s, ch);
1658 run_datestamp = newstralloc(run_datestamp, fp);
1661 skip_whitespace(s, ch);
1662 if(ch == '\0' || strncmp_const_skip(s - 1, "label", s, ch) != 0) {
1667 skip_whitespace(s, ch);
1673 skip_non_whitespace(s, ch);
1676 label = stralloc(fp);
1680 fp = vstralloc(tape_labels, ", ", label, NULL);
1681 amfree(tape_labels);
1684 tape_labels = stralloc(label);
1689 if(stats_by_tape == NULL) {
1690 stats_by_tape = current_tape = (taper_t *)alloc(SIZEOF(taper_t));
1693 current_tape->next = (taper_t *)alloc(SIZEOF(taper_t));
1694 current_tape = current_tape->next;
1696 current_tape->label = label;
1697 current_tape->taper_time = 0.0;
1698 current_tape->coutsize = 0.0;
1699 current_tape->corigsize = 0.0;
1700 current_tape->tapedisks = 0;
1701 current_tape->tapechunks = 0;
1702 current_tape->next = NULL;
1722 skip_whitespace(s, ch);
1723 if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {
1724 return; /* ignore bogus line */
1727 skip_whitespace(s, ch);
1733 skip_non_whitespace(s, ch);
1735 run_datestamp = newstralloc(run_datestamp, fp);
1740 if(amflush_run && normal_run) {
1743 _(" reporter: both amflush and planner output in log, ignoring amflush."));
1755 if(curprog == P_DRIVER || curprog == P_AMFLUSH || curprog == P_PLANNER) {
1759 skip_whitespace(s, ch);
1760 if(ch == '\0' || strncmp_const_skip(s - 1, "date", s, ch) != 0) {
1765 skip_whitespace(s, ch);
1770 skip_non_whitespace(s, ch); /* ignore the date string */
1772 skip_whitespace(s, ch);
1773 if(ch == '\0' || strncmp_const_skip(s - 1, "time", s, ch) != 0) {
1774 /* older planner doesn't write time */
1775 if(curprog == P_PLANNER) return;
1780 skip_whitespace(s, ch);
1785 if(sscanf(s - 1, "%lf", &a_time) != 1) {
1789 if(curprog == P_PLANNER) {
1790 planner_time = a_time;
1793 total_time = a_time;
1804 char *hostname, *diskname, *datestamp, *qdiskname;
1806 double sec, kps, nbytes, cbytes;
1810 if(curprog == P_DRIVER) {
1814 skip_whitespace(s, ch);
1815 if(ch != '\0' && strncmp_const_skip(s - 1, "startup time", s, ch) == 0) {
1816 skip_whitespace(s, ch);
1821 if(sscanf(s - 1, "%lf", &startup_time) != 1) {
1825 planner_time = startup_time;
1827 else if(ch != '\0' && strncmp_const_skip(s - 1, "hostname", s, ch) == 0) {
1828 skip_whitespace(s, ch);
1833 ghostname = stralloc(s-1);
1835 else if(ch != '\0' && strncmp_const_skip(s - 1, "estimate", s, ch) == 0) {
1836 skip_whitespace(s, ch);
1842 skip_non_whitespace(s, ch);
1844 hostname = stralloc(fp);
1847 skip_whitespace(s, ch);
1855 skip_quoted_string(s, ch);
1857 diskname = unquote_string(qdiskname);
1860 skip_whitespace(s, ch);
1868 skip_non_whitespace(s, ch);
1870 datestamp = stralloc(fp);
1872 skip_whitespace(s, ch);
1874 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
1881 skip_integer(s, ch);
1882 if(level < 0 || level > 9) {
1889 skip_whitespace(s, ch);
1891 if(sscanf(s - 1,"[sec %lf nkb %lf ckb %lf kps %lf",
1892 &sec, &nbytes, &cbytes, &kps) != 4) {
1900 dp = lookup_disk(hostname, diskname);
1902 addtoX_summary(&first_failed, &last_failed,
1903 hostname, diskname, level,
1904 _("ERROR [not in disklist]"));
1905 exit_status |= STATUS_FAILED;
1912 repdata = find_repdata(dp, datestamp, level);
1914 repdata->est_nsize = nbytes;
1915 repdata->est_csize = cbytes;
1936 str = vstrallocf(" %s: %s", program_str[curprog], curstr);
1937 addline(¬es, str);
1947 char *s = NULL, *nl;
1950 if(curlog == L_ERROR && curprog == P_TAPER) {
1954 skip_whitespace(s, ch);
1955 if(ch != '\0' && strncmp_const_skip(s - 1, "no-tape", s, ch) == 0) {
1956 skip_whitespace(s, ch);
1958 if((nl = strchr(s - 1, '\n')) != NULL) {
1961 tapestart_error = newstralloc(tapestart_error, s - 1);
1964 exit_status |= STATUS_TAPE;;
1967 /* else some other tape error, handle like other errors */
1969 /* else some other tape error, handle like other errors */
1971 s = vstrallocf(" %s: %s %s", program_str[curprog],
1972 logtype_str[curlog], curstr);
1973 addline(&errsum, s);
1980 handle_summary(void)
1987 static int nb_disk=0;
1992 char *s, *fp, *qdiskname;
1994 char *hostname = NULL, *diskname = NULL;
1996 if(curprog != P_PLANNER && curprog != P_AMFLUSH) {
2002 for(dp = diskq.head; dp != NULL; dp = dp->next)
2010 skip_whitespace(s, ch);
2016 skip_non_whitespace(s, ch);
2018 hostname = newstralloc(hostname, fp);
2021 skip_whitespace(s, ch);
2028 skip_quoted_string(s, ch);
2030 diskname = unquote_string(qdiskname);
2033 dp = lookup_disk(hostname, diskname);
2035 dp = add_disk(&diskq, hostname, diskname);
2043 /* XXX Just a placeholder, in case we decide to do something with L_CHUNK
2044 * log entries. Right now they're just the equivalent of L_SUCCESS, but only
2045 * for a split chunk of the overall dumpfile.
2052 double sec, kps, kbytes;
2057 char *hostname = NULL;
2058 char *diskname = NULL;
2066 if(curprog != P_TAPER) {
2074 skip_whitespace(s, ch);
2080 if (logtype == L_PART || logtype == L_PARTPARTIAL) {
2082 skip_non_whitespace(s, ch);
2084 label = stralloc(fp);
2087 skip_whitespace(s, ch);
2088 if(ch == '\0' || sscanf(s - 1, "%d", &fileno) != 1) {
2093 skip_integer(s, ch);
2094 skip_whitespace(s, ch);
2104 skip_non_whitespace(s, ch);
2106 hostname = stralloc(fp);
2109 skip_whitespace(s, ch);
2116 skip_quoted_string(s, ch);
2118 diskname = unquote_string(fp);
2121 skip_whitespace(s, ch);
2129 skip_non_whitespace(s, ch);
2131 datestamp = stralloc(fp);
2134 skip_whitespace(s, ch);
2135 if(ch == '\0' || sscanf(s - 1, "%d", &chunk) != 1) {
2142 skip_integer(s, ch);
2144 if (ch != '\0' && s[-1] == '/') {
2146 if (sscanf(s - 1, "%d", &totpart) != 1) {
2153 skip_integer(s, ch);
2156 skip_whitespace(s, ch);
2157 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2164 skip_integer(s, ch);
2167 if(level < 0 || level > 9) {
2175 skip_whitespace(s, ch);
2176 if(sscanf(s - 1,"[sec %lf kb %lf kps %lf", &sec, &kbytes, &kps) != 3) {
2185 dp = lookup_disk(hostname, diskname);
2189 str = vstrallocf(_(" %s ERROR [not in disklist]"),
2190 prefix(hostname, diskname, level));
2191 addline(&errsum, str);
2199 repdata = find_repdata(dp, datestamp, level);
2201 sp = &(repdata->taper);
2209 if(current_tape == NULL) {
2210 error("current_tape == NULL");
2212 if (sp->filenum == 0) {
2213 sp->filenum = ++tapefcount;
2214 sp->tapelabel = current_tape->label;
2216 tapechunks[level] +=1;
2217 stats[i].tapechunks +=1;
2218 current_tape->taper_time += sec;
2219 current_tape->coutsize += kbytes;
2220 current_tape->tapechunks += 1;
2231 double kbytes = 0.0;
2232 double origkb = 0.0;
2235 char *s, *fp, *qdiskname;
2237 char *hostname = NULL;
2238 char *diskname = NULL;
2246 if(curprog != P_TAPER && curprog != P_DUMPER && curprog != P_PLANNER &&
2247 curprog != P_CHUNKER) {
2255 skip_whitespace(s, ch);
2261 skip_non_whitespace(s, ch);
2263 hostname = stralloc(fp);
2266 skip_whitespace(s, ch);
2273 skip_quoted_string(s, ch);
2275 diskname = unquote_string(qdiskname);
2277 skip_whitespace(s, ch);
2285 skip_non_whitespace(s, ch);
2287 datestamp = stralloc(fp);
2290 //datestamp is optional
2291 if(strlen(datestamp) < 6) {
2292 totpart = atoi(datestamp);
2293 datestamp = newstralloc(datestamp, run_datestamp);
2296 skip_whitespace(s, ch);
2297 if(ch == '\0' || sscanf(s - 1, "%d", &totpart) != 1) {
2304 skip_integer(s, ch);
2307 skip_whitespace(s, ch);
2309 //totpart is optional
2312 if (*(s-1) == '[') {
2316 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2323 skip_integer(s, ch);
2324 skip_whitespace(s, ch);
2328 if(level < 0 || level > 9) {
2335 /* Planner success messages (for skipped
2336 dumps) do not contain statistics */
2337 if(curprog != P_PLANNER) {
2340 if((curprog != P_DUMPER)
2341 || (sscanf(s - 1,"[sec %lf kb %lf kps %lf orig-kb %lf",
2342 &sec, &kbytes, &kps, &origkb) != 4)) {
2344 if(sscanf(s - 1,"[sec %lf kb %lf kps %lf",
2345 &sec, &kbytes, &kps) != 3) {
2354 if(!isnormal(origkb))
2360 dp = lookup_disk(hostname, diskname);
2362 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2363 _("ERROR [not in disklist]"));
2364 exit_status |= STATUS_FAILED;
2371 repdata = find_repdata(dp, datestamp, level);
2373 if(curprog == P_PLANNER) {
2374 repdata->dumper.result = L_SKIPPED;
2381 if(curprog == P_TAPER)
2382 sp = &(repdata->taper);
2383 else if(curprog == P_DUMPER)
2384 sp = &(repdata->dumper);
2385 else sp = &(repdata->chunker);
2394 get_info(hostname, diskname, &inf);
2395 tm = localtime(&inf.inf[level].date);
2397 Idatestamp = 10000*(tm->tm_year+1900) +
2398 100*(tm->tm_mon+1) + tm->tm_mday;
2400 Idatestamp = 19000101;
2403 if(atoi(datestamp) == Idatestamp) {
2404 /* grab original size from record */
2405 origkb = (double)inf.inf[level].size;
2411 if (curprog == P_DUMPER &&
2412 (sp->result == L_FAIL || sp->result == L_PARTIAL)) {
2413 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2414 _("was successfully retried"));
2421 sp->result = L_SUCCESS;
2422 sp->datestamp = repdata->datestamp;
2425 sp->origsize = origkb;
2426 sp->outsize = kbytes;
2428 if(curprog == P_TAPER) {
2429 if(current_tape == NULL) {
2430 error(_("current_tape == NULL"));
2433 stats[i].taper_time += sec;
2434 sp->filenum = ++tapefcount;
2435 sp->tapelabel = current_tape->label;
2436 sp->totpart = totpart;
2437 tapedisks[level] +=1;
2438 stats[i].tapedisks +=1;
2439 stats[i].tapesize += kbytes;
2440 sp->outsize = kbytes;
2441 if(!isnormal(repdata->chunker.outsize) && isnormal(repdata->dumper.outsize)) { /* dump to tape */
2442 stats[i].outsize += kbytes;
2443 if (abs(kbytes - origkb) >= 32) {
2444 stats[i].coutsize += kbytes;
2447 current_tape->tapedisks += 1;
2450 if(curprog == P_DUMPER) {
2451 stats[i].dumper_time += sec;
2452 if (abs(kbytes - origkb) < 32) {
2453 sp->origsize = kbytes;
2456 stats[i].corigsize += sp->origsize;
2458 dumpdisks[level] +=1;
2459 stats[i].dumpdisks +=1;
2460 stats[i].origsize += sp->origsize;
2463 if(curprog == P_CHUNKER) {
2464 sp->outsize = kbytes;
2465 stats[i].outsize += kbytes;
2466 if (abs(kbytes - origkb) >= 32) {
2467 stats[i].coutsize += kbytes;
2474 handle_partial(void)
2479 repdata = handle_success(L_PARTIAL);
2483 if(curprog == P_TAPER)
2484 sp = &(repdata->taper);
2485 else if(curprog == P_DUMPER)
2486 sp = &(repdata->dumper);
2487 else sp = &(repdata->chunker);
2489 sp->result = L_PARTIAL;
2493 handle_strange(void)
2496 char *strangestr = NULL;
2500 repdata = handle_success(L_SUCCESS);
2504 qdisk = quote_string(repdata->disk->name);
2506 addline(&strangedet,"");
2507 str = vstrallocf("/-- %s STRANGE",
2508 prefix(repdata->disk->host->hostname, qdisk, repdata->level));
2509 addline(&strangedet, str);
2512 while(contline_next()) {
2514 get_logline(logfile);
2516 if(strncmp_const_skip(curstr, "sendbackup: warning ", s, ch) == 0) {
2517 strangestr = newstralloc(strangestr, s);
2519 addline(&strangedet, curstr);
2521 addline(&strangedet,"\\--------");
2523 str = vstrallocf("STRANGE %s", strangestr? strangestr : _("(see below)"));
2524 addtoX_summary(&first_strange, &last_strange,
2525 repdata->disk->host->hostname, qdisk, repdata->level, str);
2526 exit_status |= STATUS_STRANGE;
2541 char *s, *fp, *qdiskname;
2553 skip_whitespace(s, ch);
2559 skip_non_whitespace(s, ch);
2562 skip_whitespace(s, ch);
2568 skip_quoted_string(s, ch);
2570 diskname = unquote_string(qdiskname);
2572 skip_whitespace(s, ch);
2579 skip_non_whitespace(s, ch);
2581 datestamp = stralloc(fp);
2583 if(strlen(datestamp) < 3) { /* there is no datestamp, it's the level */
2584 level = atoi(datestamp);
2585 datestamp = newstralloc(datestamp, run_datestamp);
2587 else { /* read the level */
2588 skip_whitespace(s, ch);
2589 if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {
2595 skip_integer(s, ch);
2598 skip_whitespace(s, ch);
2606 if((s = strchr(errstr, '\n')) != NULL) {
2610 dp = lookup_disk(hostname, diskname);
2613 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2614 _("ERROR [not in disklist]"));
2616 repdata = find_repdata(dp, datestamp, level);
2618 if(curprog == P_TAPER)
2619 sp = &(repdata->taper);
2620 else sp = &(repdata->dumper);
2622 if(sp->result != L_SUCCESS)
2623 sp->result = L_FAIL;
2627 str = vstrallocf(_("FAILED %s"), errstr);
2628 addtoX_summary(&first_failed, &last_failed, hostname, qdiskname, level,
2632 if(curprog == P_DUMPER) {
2633 addline(&errdet,"");
2634 str = vstrallocf("/-- %s FAILED %s",
2635 prefix(hostname, qdiskname, level),
2637 addline(&errdet, str);
2639 while(contline_next()) {
2640 get_logline(logfile);
2641 addline(&errdet, curstr);
2643 addline(&errdet,"\\--------");
2644 exit_status |= STATUS_FAILED;
2651 generate_missing(void)
2656 for(dp = diskq.head; dp != NULL; dp = dp->next) {
2657 if(dp->todo && data(dp) == NULL) {
2658 qdisk = quote_string(dp->name);
2659 addtoX_summary(&first_failed, &last_failed, dp->host->hostname,
2660 qdisk, -987, _("RESULTS MISSING"));
2661 exit_status |= STATUS_MISSING;
2668 generate_bad_estimate(void)
2675 for(dp = diskq.head; dp != NULL; dp = dp->next) {
2677 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
2678 if(repdata->est_csize >= 0.1) {
2679 if(repdata->taper.result == L_SUCCESS ||
2680 repdata->taper.result == L_CHUNKSUCCESS)
2681 outsize = repdata->taper.outsize;
2682 else if(repdata->chunker.result == L_SUCCESS ||
2683 repdata->chunker.result == L_PARTIAL ||
2684 repdata->chunker.result == L_CHUNKSUCCESS)
2685 outsize = repdata->chunker.outsize;
2686 else if(repdata->taper.result == L_PARTIAL)
2687 outsize = repdata->taper.outsize;
2689 outsize = repdata->dumper.outsize;
2691 if(repdata->est_csize * 0.9 > outsize) {
2693 _(" big estimate: %s %s %d"),
2694 repdata->disk->host->hostname,
2695 repdata->disk->name,
2700 _(" est: %.0lf%s out %.0lf%s"),
2701 du(repdata->est_csize), displayunit,
2702 du(outsize), displayunit);
2706 else if(repdata->est_csize * 1.1 < outsize) {
2708 _(" small estimate: %s %s %d"),
2709 repdata->disk->host->hostname,
2710 repdata->disk->name,
2715 _(" est: %.0lf%s out %.0lf%s"),
2716 du(repdata->est_csize), displayunit,
2717 du(outsize), displayunit);
2733 static char *str = NULL;
2735 if (level == -987) {
2736 str = newvstrallocf(str, " %s %s",
2737 host ? host : _("(host?)"),
2738 disk ? disk : _("(disk?)"));
2740 str = newvstrallocf(str, " %s %s lev %d",
2741 host ? host : _("(host?)"),
2742 disk ? disk : _("(disk?)"),
2759 static char *str = NULL;
2761 h=alloc(len_host+1);
2763 strncpy(h, host, len_host);
2765 strncpy(h, _("(host?)"), len_host);
2768 for(l = strlen(h); l < len_host; l++) {
2771 d=alloc(len_disk+1);
2773 strncpy(d, disk, len_disk);
2775 strncpy(d, _("(disk?)"), len_disk);
2778 for(l = strlen(d); l < len_disk; l++) {
2781 if (level == -987) {
2782 str = newvstrallocf(str, " %s %s", h, d);
2784 str = newvstrallocf(str, " %s %s lev %d", h, d, level);
2794 X_summary_t **first,
2801 X_summary_t *X_summary;
2803 X_summary = alloc(SIZEOF(X_summary_t));
2804 X_summary->hostname = stralloc(host);
2805 X_summary->diskname = stralloc(disk);
2806 X_summary->level = level;
2807 X_summary->str = stralloc(str);
2808 X_summary->next = NULL;
2809 if (*first == NULL) {
2813 (*last)->next = X_summary;
2826 lbl_templ = config_dir_relative(lbl_templ);
2827 if ((fd = open(lbl_templ, 0)) < 0) {
2829 curprog = P_REPORTER;
2830 curstr = vstrallocf(_("could not open PostScript template file %s: %s"),
2831 lbl_templ, strerror(errno));
2835 afclose(postscript);
2838 while ((numread = read(fd, buf, SIZEOF(buf))) > 0) {
2839 if (fwrite(buf, (size_t)numread, 1, postscript) != 1) {
2841 curprog = P_REPORTER;
2842 curstr = vstrallocf(_("error copying PostScript template file %s: %s"),
2843 lbl_templ, strerror(errno));
2847 afclose(postscript);
2853 curprog = P_REPORTER;
2854 curstr = vstrallocf(_("error reading PostScript template file %s: %s"),
2855 lbl_templ, strerror(errno));
2859 afclose(postscript);
2868 /*@keep@*/ disk_t *dp,
2872 repdata_t *repdata, *prev;
2875 datestamp = run_datestamp;
2877 for(repdata = data(dp); repdata != NULL && (repdata->level != level || strcmp(repdata->datestamp,datestamp)!=0); repdata = repdata->next) {
2881 repdata = (repdata_t *)alloc(SIZEOF(repdata_t));
2882 memset(repdata, '\0', SIZEOF(repdata_t));
2884 repdata->datestamp = stralloc(datestamp ? datestamp : "");
2885 repdata->level = level;
2886 repdata->dumper.result = L_BOGUS;
2887 repdata->taper.result = L_BOGUS;
2888 repdata->next = NULL;
2890 prev->next = repdata;
2892 dp->up = (void *)repdata;
2899 do_postscript_output(void)
2901 tapetype_t *tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));
2904 double outsize, origsize;
2911 tapesize = tapetype_get_length(tp);
2912 marksize = tapetype_get_filemark(tp);
2914 for(current_tape = stats_by_tape; current_tape != NULL;
2915 current_tape = current_tape->next) {
2917 if (current_tape->label == NULL) {
2921 copy_template_file(tapetype_get_lbl_templ(tp));
2923 if (postscript == NULL)
2926 /* generate a few elements */
2927 g_fprintf(postscript,"(%s) DrawDate\n\n",
2928 nicedate(run_datestamp ? run_datestamp : "0"));
2929 g_fprintf(postscript,_("(Amanda Version %s) DrawVers\n"),version());
2930 g_fprintf(postscript,"(%s) DrawTitle\n", current_tape->label);
2933 g_fprintf(postscript, "(Total Size: %6.1lf MB) DrawStat\n",
2934 mb(current_tape->coutsize));
2935 g_fprintf(postscript, _("(Tape Used (%%) "));
2936 divzero(postscript, pct(current_tape->coutsize +
2937 marksize * (current_tape->tapedisks + current_tape->tapechunks)),
2939 g_fprintf(postscript," %%) DrawStat\n");
2940 g_fprintf(postscript, _("(Compression Ratio: "));
2941 divzero(postscript, pct(current_tape->coutsize),current_tape->corigsize);
2942 g_fprintf(postscript," %%) DrawStat\n");
2943 g_fprintf(postscript,_("(Filesystems Taped: %4d) DrawStat\n"),
2944 current_tape->tapedisks);
2948 g_fprintf(postscript,
2949 "(-) (%s) (-) ( 0) ( 32) ( 32) DrawHost\n",
2950 current_tape->label);
2952 for(dp = sortq.head; dp != NULL; dp = dp->next) {
2953 if (dp->todo == 0) {
2956 for(repdata = data(dp); repdata != NULL; repdata = repdata->next) {
2958 if(repdata->taper.tapelabel != current_tape->label) {
2962 if(repdata->dumper.result == L_SUCCESS ||
2963 repdata->dumper.result == L_PARTIAL)
2964 origsize = repdata->dumper.origsize;
2966 origsize = repdata->taper.origsize;
2968 if(repdata->taper.result == L_SUCCESS ||
2969 repdata->taper.result == L_PARTIAL)
2970 outsize = repdata->taper.outsize;
2972 outsize = repdata->dumper.outsize;
2974 if (repdata->taper.result == L_SUCCESS ||
2975 repdata->taper.result == L_PARTIAL) {
2976 if(isnormal(origsize)) {
2977 g_fprintf(postscript,"(%s) (%s) (%d) (%3.0d) (%8.0lf) (%8.0lf) DrawHost\n",
2978 dp->host->hostname, dp->name, repdata->level,
2979 repdata->taper.filenum, origsize,
2983 g_fprintf(postscript,"(%s) (%s) (%d) (%3.0d) (%8s) (%8.0lf) DrawHost\n",
2984 dp->host->hostname, dp->name, repdata->level,
2985 repdata->taper.filenum, "N/A",
2992 g_fprintf(postscript,"\nshowpage\n");