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

📄 find.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998 University of Maryland at College Park * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of U.M. not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission.  U.M. makes no representations about the * suitability of this software for any purpose.  It is provided "as is" * without express or implied warranty. * * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Author: James da Silva, Systems Design and Analysis Group *			   Computer Science Department *			   University of Maryland at College Park *//* * $Id: find.c,v 1.33 2006/07/06 13:13:15 martinea Exp $ * * controlling process for the Amanda backup system */#include "amanda.h"#include "conffile.h"#include "tapefile.h"#include "logfile.h"#include "holding.h"#include "find.h"#include "cmdline.h"int find_match(char *host, char *disk);void search_holding_disk(find_result_t **output_find);char *find_nicedate(char *datestamp);static int find_compare(const void *, const void *);static int parse_taper_datestamp_log(char *logline, char **datestamp, char **level);static gboolean logfile_has_tape(char * label, char * datestamp,                                 char * logfile);static char *find_sort_order = NULL;find_result_t * find_dump(disklist_t* diskqp) {    char *conf_logdir, *logfile = NULL;    int tape, maxtape, logs;    unsigned seq;    tape_t *tp;    find_result_t *output_find = NULL;    conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));    maxtape = lookup_nb_tape();    for(tape = 1; tape <= maxtape; tape++) {	tp = lookup_tapepos(tape);	if(tp == NULL) continue;	/* search log files */	logs = 0;	/* new-style log.<date>.<seq> */	for(seq = 0; 1; seq++) {	    char seq_str[NUM_STR_SIZE];	    g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);	    logfile = newvstralloc(logfile,			conf_logdir, "/log.", tp->datestamp, ".", seq_str, NULL);	    if(access(logfile, R_OK) != 0) break;	    if (search_logfile(&output_find, tp->label, tp->datestamp,                               logfile, diskqp)) {                logs ++;            }	}	/* search old-style amflush log, if any */	logfile = newvstralloc(logfile, conf_logdir, "/log.",                               tp->datestamp, ".amflush", NULL);	if(access(logfile,R_OK) == 0) {	    if (search_logfile(&output_find, tp->label, tp->datestamp,                               logfile, diskqp)) {                logs ++;            }        }        	/* search old-style main log, if any */	logfile = newvstralloc(logfile, conf_logdir, "/log.", tp->datestamp,                               NULL);	if(access(logfile,R_OK) == 0) {	    if (search_logfile(&output_find, tp->label, tp->datestamp,                               logfile, diskqp)) {                logs ++;            }	}	if(logs == 0 && strcmp(tp->datestamp,"0") != 0)	    g_fprintf(stderr,                      _("Warning: no log files found for tape %s written %s\n"),                      tp->label, find_nicedate(tp->datestamp));    }    amfree(logfile);    amfree(conf_logdir);    search_holding_disk(&output_find);    return(output_find);}char **find_log(void){    char *conf_logdir, *logfile = NULL;    char *pathlogfile = NULL;    int tape, maxtape, logs;    unsigned seq;    tape_t *tp;    char **output_find_log = NULL;    char **current_log;    conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));    maxtape = lookup_nb_tape();    output_find_log = alloc((maxtape*5+10) * SIZEOF(char *));    current_log = output_find_log;    for(tape = 1; tape <= maxtape; tape++) {	tp = lookup_tapepos(tape);	if(tp == NULL) continue;	/* search log files */	logs = 0;	/* new-style log.<date>.<seq> */	for(seq = 0; 1; seq++) {	    char seq_str[NUM_STR_SIZE];	    g_snprintf(seq_str, SIZEOF(seq_str), "%u", seq);	    logfile = newvstralloc(logfile, "log.", tp->datestamp, ".", seq_str, NULL);	    pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);	    if (access(pathlogfile, R_OK) != 0) break;	    if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {		if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {		    *current_log = stralloc(logfile);		    current_log++;		}		logs++;		break;	    }	}	/* search old-style amflush log, if any */	logfile = newvstralloc(logfile, "log.", tp->datestamp, ".amflush", NULL);	pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);	if (access(pathlogfile, R_OK) == 0) {	    if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {		if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {		    *current_log = stralloc(logfile);		    current_log++;		}		logs++;	    }	}	/* search old-style main log, if any */	logfile = newvstralloc(logfile, "log.", tp->datestamp, NULL);	pathlogfile = newvstralloc(pathlogfile, conf_logdir, "/", logfile, NULL);	if (access(pathlogfile, R_OK) == 0) {	    if (logfile_has_tape(tp->label, tp->datestamp, pathlogfile)) {		if (current_log == output_find_log || strcmp(*(current_log-1), logfile)) {		    *current_log = stralloc(logfile);		    current_log++;		}		logs++;	    }	}	if(logs == 0 && strcmp(tp->datestamp,"0") != 0)	    g_fprintf(stderr, _("Warning: no log files found for tape %s written %s\n"),		   tp->label, find_nicedate(tp->datestamp));    }    amfree(logfile);    amfree(pathlogfile);    amfree(conf_logdir);    *current_log = NULL;    return(output_find_log);}voidsearch_holding_disk(    find_result_t **output_find){    GSList *holding_file_list;    GSList *e;    char *holding_file;    disk_t *dp;    dumpfile_t file;    holding_file_list = holding_get_files(NULL, 1);    for(e = holding_file_list; e != NULL; e = e->next) {	holding_file = (char *)e->data;	if (!holding_file_get_dumpfile(holding_file, &file))	    continue;	if (file.dumplevel < 0 || file.dumplevel > 9)	    continue;	dp = NULL;	for(;;) {	    char *s;	    if((dp = lookup_disk(file.name, file.disk)))		break;	    if((s = strrchr(file.name,'.')) == NULL)		break;	    *s = '\0';	}	if ( dp == NULL ) {	    continue;	}	if(find_match(file.name,file.disk)) {	    find_result_t *new_output_find =		alloc(SIZEOF(find_result_t));	    new_output_find->next=*output_find;	    new_output_find->timestamp = stralloc(file.datestamp);	    new_output_find->hostname = stralloc(file.name);	    new_output_find->diskname = stralloc(file.disk);	    new_output_find->level=file.dumplevel;	    new_output_find->label=stralloc(holding_file);	    new_output_find->partnum=stralloc("--");	    new_output_find->filenum=0;	    new_output_find->status=stralloc("OK");	    *output_find=new_output_find;	}    }    g_slist_free_full(holding_file_list);}static intfind_compare(    const void *i1,    const void *j1){    int compare=0;    find_result_t *i, *j;    size_t nb_compare=strlen(find_sort_order);    size_t k;    for(k=0;k<nb_compare;k++) {        char sort_key = find_sort_order[k];        if (isupper((int)sort_key)) {            /* swap */            sort_key = tolower(sort_key);            j = *(find_result_t **)i1;            i = *(find_result_t **)j1;        } else {            i = *(find_result_t **)i1;            j = *(find_result_t **)j1;        }                    	switch (sort_key) {	case 'h' : compare=strcmp(i->hostname,j->hostname);		   break;	case 'k' : compare=strcmp(i->diskname,j->diskname);		   break;	case 'd' : compare=strcmp(i->timestamp,j->timestamp);		   break;	case 'l' : compare=j->level - i->level;		   break;	case 'f' : compare=(i->filenum == j->filenum) ? 0 :		           ((i->filenum < j->filenum) ? -1 : 1);		   break;	case 'b' : compare=compare_possibly_null_strings(i->label,                                                         j->label);                   break;	case 'p' :		   if(strcmp(i->partnum, "--") != 0 &&		      strcmp(j->partnum, "--") != 0){		      compare = atoi(i->partnum) - atoi(j->partnum);		   }	           else compare=strcmp(i->partnum,j->partnum);		   break;	}	if(compare != 0)	    return compare;    }    return 0;}voidsort_find_result(    char *sort_order,    find_result_t **output_find){    find_result_t *output_find_result;    find_result_t **array_find_result = NULL;    size_t nb_result=0;    size_t no_result;    find_sort_order = sort_order;    /* qsort core dump if nothing to sort */    if(*output_find==NULL)	return;    /* How many result */    for(output_find_result=*output_find;	output_find_result;	output_find_result=output_find_result->next) {	nb_result++;    }    /* put the list in an array */    array_find_result=alloc(nb_result * SIZEOF(find_result_t *));    for(output_find_result=*output_find,no_result=0;	output_find_result;	output_find_result=output_find_result->next,no_result++) {	array_find_result[no_result]=output_find_result;    }    /* sort the array */    qsort(array_find_result,nb_result,SIZEOF(find_result_t *),	  find_compare);    /* put the sorted result in the list */    for(no_result=0;	no_result<nb_result-1; no_result++) {	array_find_result[no_result]->next = array_find_result[no_result+1];    }    array_find_result[nb_result-1]->next=NULL;    *output_find=array_find_result[0];    amfree(array_find_result);}voidprint_find_result(    find_result_t *output_find){    find_result_t *output_find_result;    int max_len_datestamp = 4;    int max_len_hostname  = 4;    int max_len_diskname  = 4;    int max_len_level     = 2;    int max_len_label     =12;    int max_len_filenum   = 4;    int max_len_part      = 4;    int max_len_status    = 6;    size_t len;    for(output_find_result=output_find;	output_find_result;	output_find_result=output_find_result->next) {	char *qdiskname;	len=strlen(find_nicedate(output_find_result->timestamp));	if((int)len > max_len_datestamp)	    max_len_datestamp=(int)len;	len=strlen(output_find_result->hostname);	if((int)len > max_len_hostname)	    max_len_hostname = (int)len;	qdiskname=quote_string(output_find_result->diskname);	len=strlen(qdiskname);	amfree(qdiskname);	if((int)len > max_len_diskname)	    max_len_diskname = (int)len;        if (output_find_result->label != NULL) {            len=strlen(output_find_result->label);            if((int)len > max_len_label)                max_len_label = (int)len;        }	len=strlen(output_find_result->status);	if((int)len > max_len_status)	    max_len_status = (int)len;	len=strlen(output_find_result->partnum);	if((int)len > max_len_part)	    max_len_part = (int)len;    }    /*     * Since status is the rightmost field, we zap the maximum length     * because it is not needed.  The code is left in place in case     * another column is added later.     */    max_len_status = 1;    if(output_find==NULL) {	g_printf(_("\nNo dump to list\n"));    }    else {	g_printf(_("\ndate%*s host%*s disk%*s lv%*s tape or file%*s file%*s part%*s status\n"),	       max_len_datestamp-4,"",	       max_len_hostname-4 ,"",	       max_len_diskname-4 ,"",	       max_len_level-2    ,"",	       max_len_label-12   ,"",	       max_len_filenum-4  ,"",	       max_len_part-4  ,"");        for(output_find_result=output_find;	        output_find_result;	        output_find_result=output_find_result->next) {	    char *qdiskname;            char * formatted_label;	    qdiskname = quote_string(output_find_result->diskname);            formatted_label = output_find_result->label;            if (formatted_label == NULL)                formatted_label = "";	    /*@ignore@*/	    g_printf("%-*s %-*s %-*s %*d %-*s %*lld %*s %-*s\n",                     max_len_datestamp,                      find_nicedate(output_find_result->timestamp),                     max_len_hostname,  output_find_result->hostname,                     max_len_diskname,  qdiskname,                     max_len_level,     output_find_result->level,                     max_len_label,     formatted_label,                     max_len_filenum,   (long long)output_find_result->filenum,                     max_len_part,      output_find_result->partnum,                     max_len_status,    output_find_result->status		    );	    /*@end@*/	    amfree(qdiskname);	}    }}voidfree_find_result(    find_result_t **output_find){    find_result_t *output_find_result, *prev;    prev=NULL;    for(output_find_result=*output_find;	    output_find_result;	    output_find_result=output_find_result->next) {	amfree(prev);	amfree(output_find_result->timestamp);	amfree(output_find_result->hostname);	amfree(output_find_result->diskname);	amfree(output_find_result->label);	amfree(output_find_result->partnum);	amfree(output_find_result->status);	prev = output_find_result;    }    amfree(prev);    *output_find = NULL;}intfind_match(    char *host,    char *disk){    disk_t *dp = lookup_disk(host,disk);    return (dp && dp->todo);}char *find_nicedate(    char *datestamp){    static char nice[20];    int year, month, day;    int hours, minutes, seconds;    char date[9], atime[7];    int  numdate, numtime;    strncpy(date, datestamp, 8);    date[8] = '\0';    numdate = atoi(date);    year  = numdate / 10000;    month = (numdate / 100) % 100;    day   = numdate % 100;    if(strlen(datestamp) <= 8) {	g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d",		year, month, day);    }    else {	strncpy(atime, &(datestamp[8]), 6);	atime[6] = '\0';	numtime = atoi(atime);	hours = numtime / 10000;	minutes = (numtime / 100) % 100;	seconds = numtime % 100;	g_snprintf(nice, SIZEOF(nice), "%4d-%02d-%02d %02d:%02d:%02d",		year, month, day, hours, minutes, seconds);    }    return nice;}

⌨️ 快捷键说明

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