⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reporter.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 5 页
字号:
	    break;	}    }    if(!logfname) {	char *conf_logdir;	conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));	logfname = vstralloc(conf_logdir, "/", "log", NULL);	amfree(conf_logdir);    }    if((logfile = fopen(logfname, "r")) == NULL) {	curlog = L_ERROR;	curprog = P_REPORTER;	curstr = vstralloc(_("could not open log "),			   logfname,			   ": ",			   strerror(errno),			   NULL);	handle_error();	amfree(curstr);    }    while(logfile && get_logline(logfile)) {	switch(curlog) {	case L_START:        handle_start(); break;	case L_FINISH:       handle_finish(); break;	case L_INFO:         handle_note(); break;	case L_WARNING:      handle_note(); break;	case L_SUMMARY:      handle_summary(); break;	case L_STATS:        handle_stats(); break;	case L_ERROR:        handle_error(); break;	case L_FATAL:        handle_error(); break;	case L_DISK:         handle_disk(); break;	case L_DONE:         handle_success(curlog); break;	case L_SUCCESS:      handle_success(curlog); break;	case L_CHUNKSUCCESS: handle_success(curlog); break;	case L_PART:         handle_chunk(curlog); break;	case L_PARTPARTIAL:  handle_chunk(curlog); break;	case L_CHUNK:        handle_chunk(curlog); break;	case L_PARTIAL:      handle_partial(); break;	case L_STRANGE:      handle_strange(); break;	case L_FAIL:         handle_failed(); break;	default:	    curlog = L_ERROR;	    curprog = P_REPORTER;	    curstr = vstrallocf(_("unexpected log line: %s"), curstr);	    handle_error();	    amfree(curstr);	}    }    afclose(logfile);    close_infofile();    if(!amflush_run) {	generate_missing();	generate_bad_estimate();    }    subj_str = vstralloc(getconf_str(CNF_ORG),			 " ", amflush_run ? "AMFLUSH" : "AMANDA",			 " ", "MAIL REPORT FOR",			 " ", nicedate(run_datestamp ? run_datestamp : "0"),			 NULL);	    /* lookup the tapetype and printer type from the amanda.conf file. */    tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));    printer = getconf_str(CNF_PRINTER);    /* ignore SIGPIPE so if a child process dies we do not also go away */    signal(SIGPIPE, SIG_IGN);    /* open pipe to mailer */    if(outfname) {	/* output to a file */	if((mailf = fopen(outfname,"w")) == NULL) {	    error(_("could not open output file: %s %s"), outfname, strerror(errno));	    /*NOTREACHED*/	}        if (mailto != NULL) {		g_fprintf(mailf, "To: %s\n", mailto);		g_fprintf(mailf, "Subject: %s\n\n", subj_str);	}    } else {#ifdef MAILER    	if(mailto) {		mail_cmd = vstralloc(MAILER,			     " -s", " \"", subj_str, "\"",			     " ", mailto, NULL);		if((mailf = popen(mail_cmd, "w")) == NULL) {	    	error(_("could not open pipe to \"%s\": %s"),		  	mail_cmd, strerror(errno));	    	/*NOTREACHED*/		}	}	else {		if(mailout) {                   g_printf(_("No mail sent! "));		   g_printf(_("No valid mail address has been specified in amanda.conf or on the commmand line\n"));		}		mailf = NULL;	}#endif    }    /* open pipe to print spooler if necessary) */    if(psfname) {	/* if the postscript_label_template (tp->lbl_templ) field is not */	/* the empty string (i.e. it is set to something), open the      */	/* postscript debugging file for writing.                        */	if (tp)	    lbl_templ = tapetype_get_lbl_templ(tp);	if (tp && lbl_templ && strcmp(lbl_templ, "") != 0) {	    if ((postscript = fopen(psfname, "w")) == NULL) {		curlog = L_ERROR;		curprog = P_REPORTER;		curstr = vstrallocf(_("could not open %s: %s"),				   psfname,				   strerror(errno));		handle_error();		amfree(curstr);	    }	}    } else {#ifdef LPRCMD	if (strcmp(printer, "") != 0)	/* alternate printer is defined */	    /* print to the specified printer */#ifdef LPRFLAG	    printer_cmd = vstralloc(LPRCMD, " ", LPRFLAG, printer, NULL);#else	    printer_cmd = vstralloc(LPRCMD, NULL);#endif	else	    /* print to the default printer */	    printer_cmd = vstralloc(LPRCMD, NULL);#endif	if (tp)	    lbl_templ = tapetype_get_lbl_templ(tp);	if (tp && lbl_templ && strcmp(lbl_templ, "") != 0) {#ifdef LPRCMD	    if ((postscript = popen(printer_cmd, "w")) == NULL) {		curlog = L_ERROR;		curprog = P_REPORTER;		curstr = vstrallocf(_("could not open pipe to %s: %s"),				   printer_cmd, strerror(errno));		handle_error();		amfree(curstr);	    }#else	    curlog = L_ERROR;	    curprog = P_REPORTER;	    curstr = vstrallocf(_("no printer command defined"));	    handle_error();	    amfree(curstr);#endif	}    }    amfree(subj_str);    sort_disks();    if(mailf) {    	if(!got_finish) fputs(_("*** THE DUMPS DID NOT FINISH PROPERLY!\n\n"), mailf);	if (ghostname) {	    g_fprintf(mailf, _("Hostname: %s\n"), ghostname);	    g_fprintf(mailf, _("Org     : %s\n"), getconf_str(CNF_ORG));	    g_fprintf(mailf, _("Config  : %s\n"), config_name);	    g_fprintf(mailf, _("Date    : %s\n"),		    nicedate(run_datestamp ? run_datestamp : "0"));	    g_fprintf(mailf,"\n");	}    	output_tapeinfo();    	if(first_failed || errsum) {		g_fprintf(mailf,_("\nFAILURE DUMP SUMMARY:\n"));		if(first_failed) output_X_summary(first_failed);		if(errsum) output_lines(errsum, mailf);    	}    	if(first_strange) {		g_fprintf(mailf,_("\nSTRANGE DUMP SUMMARY:\n"));		if(first_strange) output_X_summary(first_strange);    	}    	fputs("\n\n", mailf);	    	output_stats();	    	if(errdet) {		g_fprintf(mailf,"\n\f\n");		g_fprintf(mailf,_("FAILED DUMP DETAILS:\n"));		output_lines(errdet, mailf);    	}    	if(strangedet) {		g_fprintf(mailf,"\n\f\n");		g_fprintf(mailf,_("STRANGE DUMP DETAILS:\n"));		output_lines(strangedet, mailf);    	}    	if(notes) {		g_fprintf(mailf,"\n\f\n");		g_fprintf(mailf,_("NOTES:\n"));		output_lines(notes, mailf);    	}    	if(sortq.head != NULL) {		g_fprintf(mailf,"\n\f\n");		g_fprintf(mailf,_("DUMP SUMMARY:\n"));		output_summary();    	}    	g_fprintf(mailf,_("\n(brought to you by Amanda version %s)\n"),	    	version());    }    if (postscript) {	do_postscript_output();    }    /* close postscript file */    if (psfname && postscript) {    	/* it may be that postscript is NOT opened */	afclose(postscript);    }    else {	if (postscript != NULL && pclose(postscript) != 0) {	    error(_("printer command failed: %s"), printer_cmd);	    /*NOTREACHED*/	}	postscript = NULL;    }    /* close output file */    if(outfname) {        afclose(mailf);    }    else if(mailf) {	int exitcode;        if((exitcode = pclose(mailf)) != 0) {	    char *exitstr = str_exit_status("mail command", exitcode);            error(exitstr);	    /*NOTREACHED*/	}        mailf = NULL;    }    clear_tapelist();    free_disklist(&diskq);    amfree(run_datestamp);    amfree(tape_labels);    amfree(printer_cmd);    amfree(mail_cmd);    amfree(logfname);    dbclose();    return exit_status;}/* ----- */#define mb(f)	((f)/1024)		/* kbytes -> mbutes */#define du(f)	((f)/unitdivisor)	/* kbytes -> displayunit */#define pct(f)	((f)*100.0)		/* percent */#define hrmn(f) ((int)(f)+30)/3600, (((int)(f)+30)%3600)/60#define mnsc(f) ((int)(f+0.5))/60, ((int)(f+0.5)) % 60#define divzero(fp,a,b)	        	    \    do {       	       	       	       	    \	double q = (b);			    \	if (!isnormal(q))		    \	    g_fprintf((fp),"  -- ");	    \	else if ((q = (a)/q) >= 999.95)	    \	    g_fprintf((fp), "###.#");	    \	else				    \	    g_fprintf((fp), "%5.1lf",q);	    \    } while(0)#define divzero_wide(fp,a,b)	       	    \    do {       	       	       	       	    \	double q = (b);			    \	if (!isnormal(q))		    \	    g_fprintf((fp),"    -- ");	    \	else if ((q = (a)/q) >= 99999.95)   \	    g_fprintf((fp), "#####.#");	    \	else				    \	    g_fprintf((fp), "%7.1lf",q);	    \    } while(0)static voidoutput_stats(void){    double idle_time;    tapetype_t *tp = lookup_tapetype(getconf_str(CNF_TAPETYPE));    off_t tapesize;    off_t marksize;    int lv, first;    if (tp) {	tapesize = tapetype_get_length(tp);	marksize = tapetype_get_filemark(tp);    } else {	tapesize = 100 * 1024 * 1024;	marksize = 1   * 1024 * 1024;    }    stats[2].dumpdisks   = stats[0].dumpdisks   + stats[1].dumpdisks;    stats[2].tapedisks   = stats[0].tapedisks   + stats[1].tapedisks;    stats[2].tapechunks  = stats[0].tapechunks  + stats[1].tapechunks;    stats[2].outsize     = stats[0].outsize     + stats[1].outsize;    stats[2].origsize    = stats[0].origsize    + stats[1].origsize;    stats[2].tapesize    = stats[0].tapesize    + stats[1].tapesize;    stats[2].coutsize    = stats[0].coutsize    + stats[1].coutsize;    stats[2].corigsize   = stats[0].corigsize   + stats[1].corigsize;    stats[2].taper_time  = stats[0].taper_time  + stats[1].taper_time;    stats[2].dumper_time = stats[0].dumper_time + stats[1].dumper_time;    if(!got_finish)	/* no driver finish line, estimate total run time */	total_time = stats[2].taper_time + planner_time;    idle_time = (total_time - startup_time) - stats[2].taper_time;    if(idle_time < 0) idle_time = 0.0;    g_fprintf(mailf,_("STATISTICS:\n"));    g_fprintf(mailf,	    _("                          Total       Full      Incr.\n"));    g_fprintf(mailf,	    _("                        --------   --------   --------\n"));    g_fprintf(mailf,	    _("Estimate Time (hrs:min)   %2d:%02d\n"), hrmn(planner_time));    g_fprintf(mailf,	    _("Run Time (hrs:min)        %2d:%02d\n"), hrmn(total_time));    g_fprintf(mailf,	    _("Dump Time (hrs:min)       %2d:%02d      %2d:%02d      %2d:%02d\n"),	    hrmn(stats[2].dumper_time), hrmn(stats[0].dumper_time),	    hrmn(stats[1].dumper_time));    g_fprintf(mailf,	    _("Output Size (meg)      %8.1lf   %8.1lf   %8.1lf\n"),	    mb(stats[2].outsize), mb(stats[0].outsize), mb(stats[1].outsize));    g_fprintf(mailf,	    _("Original Size (meg)    %8.1lf   %8.1lf   %8.1lf\n"),	    mb(stats[2].origsize), mb(stats[0].origsize),	    mb(stats[1].origsize));    g_fprintf(mailf, _("Avg Compressed Size (%%)   "));    divzero(mailf, pct(stats[2].coutsize),stats[2].corigsize);    fputs(_("      "), mailf);    divzero(mailf, pct(stats[0].coutsize),stats[0].corigsize);    fputs(_("      "), mailf);    divzero(mailf, pct(stats[1].coutsize),stats[1].corigsize);    if(stats[1].dumpdisks > 0) fputs(_("   (level:#disks ...)"), mailf);    putc('\n', mailf);    g_fprintf(mailf,	    _("Filesystems Dumped         %4d       %4d       %4d"),	    stats[2].dumpdisks, stats[0].dumpdisks, stats[1].dumpdisks);    if(stats[1].dumpdisks > 0) {	first = 1;	for(lv = 1; lv < 10; lv++) if(dumpdisks[lv]) {	    fputs(first?_("   ("):_(" "), mailf);	    first = 0;	    g_fprintf(mailf, _("%d:%d"), lv, dumpdisks[lv]);	}	putc(')', mailf);    }    putc('\n', mailf);    g_fprintf(mailf, _("Avg Dump Rate (k/s)     "));    divzero_wide(mailf, stats[2].outsize,stats[2].dumper_time);    fputs(_("    "), mailf);    divzero_wide(mailf, stats[0].outsize,stats[0].dumper_time);    fputs(_("    "), mailf);    divzero_wide(mailf, stats[1].outsize,stats[1].dumper_time);    putc('\n', mailf);    putc('\n', mailf);    g_fprintf(mailf,	    _("Tape Time (hrs:min)       %2d:%02d      %2d:%02d      %2d:%02d\n"),	    hrmn(stats[2].taper_time), hrmn(stats[0].taper_time),	    hrmn(stats[1].taper_time));    g_fprintf(mailf,	    _("Tape Size (meg)        %8.1lf   %8.1lf   %8.1lf\n"),	    mb(stats[2].tapesize), mb(stats[0].tapesize),	    mb(stats[1].tapesize));    g_fprintf(mailf, _("Tape Used (%%)             "));    divzero(mailf, pct(stats[2].tapesize+marksize*(stats[2].tapedisks+stats[2].tapechunks)),(double)tapesize);    fputs(_("      "), mailf);    divzero(mailf, pct(stats[0].tapesize+marksize*(stats[0].tapedisks+stats[0].tapechunks)),(double)tapesize);    fputs(_("      "), mailf);    divzero(mailf, pct(stats[1].tapesize+marksize*(stats[1].tapedisks+stats[1].tapechunks)),(double)tapesize);    if(stats[1].tapedisks > 0) fputs(_("   (level:#disks ...)"), mailf);    putc('\n', mailf);    g_fprintf(mailf,	    _("Filesystems Taped          %4d       %4d       %4d"),	    stats[2].tapedisks, stats[0].tapedisks, stats[1].tapedisks);    if(stats[1].tapedisks > 0) {	first = 1;	for(lv = 1; lv < 10; lv++) if(tapedisks[lv]) {	    fputs(first?_("   ("):_(" "), mailf);	    first = 0;	    g_fprintf(mailf, _("%d:%d"), lv, tapedisks[lv]);	}	putc(')', mailf);    }    putc('\n', mailf);    if(stats[1].tapechunks > 0) fputs(_("   (level:#chunks ...)"), mailf);    putc('\n', mailf);    g_fprintf(mailf,	    _("Chunks Taped               %4d       %4d       %4d"),	    stats[2].tapechunks, stats[0].tapechunks, stats[1].tapechunks);    if(stats[1].tapechunks > 0) {	first = 1;	for(lv = 1; lv < 10; lv++) if(tapechunks[lv]) {	    fputs(first?_("   ("):_(" "), mailf);	    first = 0;	    g_fprintf(mailf, _("%d:%d"), lv, tapechunks[lv]);	}	putc(')', mailf);    }    putc('\n', mailf);    g_fprintf(mailf, _("Avg Tp Write Rate (k/s) "));    divzero_wide(mailf, stats[2].tapesize,stats[2].taper_time);    fputs(_("    "), mailf);    divzero_wide(mailf, stats[0].tapesize,stats[0].taper_time);    fputs(_("    "), mailf);    divzero_wide(mailf, stats[1].tapesize,stats[1].taper_time);    putc('\n', mailf);    if(stats_by_tape) {	int label_length = (int)strlen(stats_by_tape->label) + 5;	g_fprintf(mailf,_("\nUSAGE BY TAPE:\n"));	g_fprintf(mailf,_("  %-*s  Time      Size      %%    Nb    Nc\n"),		label_length, _("Label"));	for(current_tape = stats_by_tape; current_tape != NULL;	    current_tape = current_tape->next) {	    g_fprintf(mailf, _("  %-*s"), label_length, current_tape->label);	    g_fprintf(mailf, _(" %2d:%02d"), hrmn(current_tape->taper_time));	    g_fprintf(mailf, _(" %8.0lf%s  "), du(current_tape->coutsize), displayunit);	    divzero(mailf, pct(current_tape->coutsize + marksize *		   (current_tape->tapedisks+current_tape->tapechunks)),		   (double)tapesize);	    g_fprintf(mailf, _("  %4d"), current_tape->tapedisks);	    g_fprintf(mailf, _("  %4d\n"), current_tape->tapechunks);	}    }}/* ----- */static voidoutput_tapeinfo(void){    tape_t *tp, *lasttp;    int run_tapes;    int skip = 0;    if (last_run_tapes > 0) {	if(amflush_run)	    g_fprintf(mailf,		    plural(_("The dumps were flushed to tape %s.\n"),			   _("The dumps were flushed to tapes %s.\n"),			   last_run_tapes),		    tape_labels ? tape_labels : "");	else	    g_fprintf(mailf,		    plural(_("These dumps were to tape %s.\n"),			   _("These dumps were to tapes %s.\n"),			   last_run_tapes),		    tape_labels ? tape_labels : "");    }    if(degraded_mode) {	g_fprintf(mailf,		_("*** A TAPE ERROR OCCURRED: %s.\n"), tapestart_error);    }    if (cmdlogfname == 1) {	if(degraded_mode) {	    fputs(_("Some dumps may have been left in the holding disk.\n"),		  mailf);	    g_fprintf(mailf,"\n");	}    }  else {	GSList *holding_list, *holding_file;	off_t  h_size = 0, mh_size;	holding_list = holding_get_files_for_flush(NULL);	for(holding_file=holding_list; holding_file != NULL;				       holding_file = holding_file->next) {	    mh_size = holding_file_size((char *)holding_file->data, 1);	    if (mh_size > 0)		h_size += mh_size;	}	if (h_size > 0) {	    g_fprintf(mailf,		    _("There are %lld%s of dumps left in the holding disk.\n"),		    (long long)h_size, displayunit);	    if (getconf_boolean(CNF_AUTOFLUSH)) {		g_fprintf(mailf, _("They will be flushed on the next run.\n"));	    } else {		g_fprintf(mailf, _("Run amflush to flush them to tape.\n"));	    }	    g_fprintf(mailf,"\n");	} else if (degraded_mode) {	    g_fprintf(mailf, _("No dumps are left in the holding disk. %lld%s\n"), (long long)h_size, displayunit);	    g_fprintf(mailf,"\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -