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

📄 amadmin.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 4 页
字号:
    s[-1] = '\0';    hdr = "CONF";    skip_whitespace(s, ch);			/* find the org keyword */    if(ch == '\0' || strncmp_const_skip(s - 1, "CONF", s, ch) != 0) {	goto bad_header;    }    ch = *s++;    hdr = "org";    skip_whitespace(s, ch);			/* find the org string */    if(ch == '\0') {	goto bad_header;    }    org = s - 1;    /*@ignore@*/    newer = (vers_maj != VERSION_MAJOR)? vers_maj > VERSION_MAJOR :	    (vers_min != VERSION_MINOR)? vers_min > VERSION_MINOR :					 vers_patch > VERSION_PATCH;    if(newer)	g_fprintf(stderr,	     _("%s: WARNING: input is from newer Amanda version: %d.%d.%d.\n"),		get_pname(), vers_maj, vers_min, vers_patch);    /*@end@*/    if(strcmp(org, getconf_str(CNF_ORG)) != 0) {	g_fprintf(stderr, _("%s: WARNING: input is from different org: %s\n"),		get_pname(), org);    }    do {    	rc = import_one();    } while (rc);    amfree(line);    return; bad_header:    /*@i@*/ amfree(line);    g_fprintf(stderr, _("%s: bad CURINFO header line in input: %s.\n"),	    get_pname(), hdr);    g_fprintf(stderr, _("    Was the input in \"amadmin export\" format?\n"));    return;}intimport_one(void){    info_t info;    stats_t onestat;    int rc, level;    char *line = NULL;    char *s, *fp;    int ch;    int nb_history, i;    char *hostname = NULL;    char *diskname = NULL;    long long off_t_tmp;    long long time_t_tmp;    memset(&info, 0, SIZEOF(info_t));    for(level = 0; level < DUMP_LEVELS; level++) {        info.inf[level].date = (time_t)-1;    }    /* get host: disk: command: lines */    hostname = diskname = NULL;    if((line = impget_line()) == NULL) return 0;	/* nothing there */    s = line;    ch = *s++;    skip_whitespace(s, ch);    if(ch == '\0' || strncmp_const_skip(s - 1, "host:", s, ch) != 0) goto parse_err;    skip_whitespace(s, ch);    if(ch == '\0') goto parse_err;    fp = s-1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    hostname = stralloc(fp);    s[-1] = (char)ch;    skip_whitespace(s, ch);    while (ch == 0) {      amfree(line);      if((line = impget_line()) == NULL) goto shortfile_err;      s = line;      ch = *s++;      skip_whitespace(s, ch);    }    if(strncmp_const_skip(s - 1, "disk:", s, ch) != 0) goto parse_err;    skip_whitespace(s, ch);    if(ch == '\0') goto parse_err;    fp = s-1;    skip_non_whitespace(s, ch);    s[-1] = '\0';    diskname = stralloc(fp);    s[-1] = (char)ch;    amfree(line);    if((line = impget_line()) == NULL) goto shortfile_err;    if(sscanf(line, "command: %u", &info.command) != 1) goto parse_err;    /* get last_level and consecutive_runs */    amfree(line);    if((line = impget_line()) == NULL) goto shortfile_err;    rc = sscanf(line, "last_level: %d", &info.last_level);    if(rc == 1) {	amfree(line);	if((line = impget_line()) == NULL) goto shortfile_err;	if(sscanf(line, "consecutive_runs: %d", &info.consecutive_runs) != 1) goto parse_err;	amfree(line);	if((line = impget_line()) == NULL) goto shortfile_err;    }    /* get rate: and comp: lines for full dumps */    rc = sscanf(line, "full-rate: %lf %lf %lf",		&info.full.rate[0], &info.full.rate[1], &info.full.rate[2]);    if(rc != 3) goto parse_err;    amfree(line);    if((line = impget_line()) == NULL) goto shortfile_err;    rc = sscanf(line, "full-comp: %lf %lf %lf",		&info.full.comp[0], &info.full.comp[1], &info.full.comp[2]);    if(rc != 3) goto parse_err;    /* get rate: and comp: lines for incr dumps */    amfree(line);    if((line = impget_line()) == NULL) goto shortfile_err;    rc = sscanf(line, "incr-rate: %lf %lf %lf",		&info.incr.rate[0], &info.incr.rate[1], &info.incr.rate[2]);    if(rc != 3) goto parse_err;    amfree(line);    if((line = impget_line()) == NULL) goto shortfile_err;    rc = sscanf(line, "incr-comp: %lf %lf %lf",		&info.incr.comp[0], &info.incr.comp[1], &info.incr.comp[2]);    if(rc != 3) goto parse_err;    /* get stats for dump levels */    while(1) {	amfree(line);	if((line = impget_line()) == NULL) goto shortfile_err;	if(strncmp_const(line, "//") == 0) {	    /* end of record */	    break;	}	if(strncmp_const(line, "history:") == 0) {	    /* end of record */	    break;	}	memset(&onestat, 0, SIZEOF(onestat));	s = line;	ch = *s++;	skip_whitespace(s, ch);	if(ch == '\0' || strncmp_const_skip(s - 1, "stats:", s, ch) != 0) {	    goto parse_err;	}	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) {	    goto parse_err;	}	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%lld", &off_t_tmp) != 1) {	    goto parse_err;	}	onestat.size = (off_t)off_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%lld", &off_t_tmp) != 1) {	    goto parse_err;	}	onestat.csize = (off_t)off_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%lld", &time_t_tmp) != 1) {	    goto parse_err;	}        onestat.secs = (time_t)time_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf(s - 1, "%lld", &time_t_tmp) != 1) {	    goto parse_err;	}	/* time_t not guarranteed to be long */	/*@i1@*/ onestat.date = (time_t)time_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch != '\0') {	    if(sscanf(s - 1, "%lld", &off_t_tmp) != 1) {		goto parse_err;	    }	    onestat.filenum = (off_t)off_t_tmp;	    skip_integer(s, ch);	    skip_whitespace(s, ch);	    if(ch == '\0') {		if (onestat.filenum != 0)		    goto parse_err;		onestat.label[0] = '\0';	    } else {		strncpy(onestat.label, s - 1, SIZEOF(onestat.label)-1);		onestat.label[SIZEOF(onestat.label)-1] = '\0';	    }	}	if(level < 0 || level > 9) goto parse_err;	info.inf[level] = onestat;    }    nb_history = 0;    for(i=0;i<=NB_HISTORY;i++) {	info.history[i].level = -2;    }    while(1) {	history_t onehistory;	if(line[0] == '/' && line[1] == '/') {	    info.history[nb_history].level = -2;	    rc = 0;	    break;	}	memset(&onehistory, 0, SIZEOF(onehistory));	s = line;	ch = *s++;	if(strncmp_const_skip(line, "history:", s, ch) != 0) {	    break;	}	skip_whitespace(s, ch);	if(ch == '\0' || sscanf((s - 1), "%d", &onehistory.level) != 1) {	    break;	}	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) {	    break;	}	onehistory.size = (off_t)off_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if(ch == '\0' || sscanf((s - 1), "%lld", &off_t_tmp) != 1) {	    break;	}	onehistory.csize = (off_t)off_t_tmp;	skip_integer(s, ch);	skip_whitespace(s, ch);	if((ch == '\0') || sscanf((s - 1), "%lld", &time_t_tmp) != 1) {	    break;	}	/* time_t not guarranteed to be long */	/*@i1@*/ onehistory.date = (time_t)time_t_tmp;	skip_integer(s, ch);	info.history[nb_history++] = onehistory;	amfree(line);	if((line = impget_line()) == NULL) goto shortfile_err;    }    /*@i@*/ amfree(line);    /* got a full record, now write it out to the database */    if(put_info(hostname, diskname, &info)) {	g_fprintf(stderr, _("%s: error writing record for %s:%s\n"),		get_pname(), hostname, diskname);    }    amfree(hostname);    amfree(diskname);    return 1; parse_err:    /*@i@*/ amfree(line);    amfree(hostname);    amfree(diskname);    g_fprintf(stderr, _("%s: parse error reading import record.\n"), get_pname());    return 0; shortfile_err:    /*@i@*/ amfree(line);    amfree(hostname);    amfree(diskname);    g_fprintf(stderr, _("%s: short file reading import record.\n"), get_pname());    return 0;}char *impget_line(void){    char *line;    char *s;    int ch;    for(; (line = agets(stdin)) != NULL; free(line)) {	s = line;	ch = *s++;	skip_whitespace(s, ch);	if(ch == '#') {	    /* ignore comment lines */	    continue;	} else if(ch) {	    /* found non-blank, return line */	    return line;	}	/* otherwise, a blank line, so keep going */    }    if(ferror(stdin)) {	g_fprintf(stderr, _("%s: reading stdin: %s\n"),		get_pname(), strerror(errno));    }    return NULL;}/* ----------------------------------------------- */voiddisklist_one(    disk_t *	dp){    am_host_t *hp;    netif_t *ip;    sle_t *excl;    hp = dp->host;    ip = hp->netif;    g_printf("line %d:\n", dp->line);    g_printf("    host %s:\n", hp->hostname);    g_printf("        interface %s\n",	   interface_name(ip->config)[0] ? interface_name(ip->config) : "default");    g_printf("    disk %s:\n", dp->name);    if(dp->device) g_printf("        device %s\n", dp->device);    g_printf("        program \"%s\"\n", dp->program);    if(dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {	g_printf("        exclude file");	for(excl = dp->exclude_file->first; excl != NULL; excl = excl->next) {	    g_printf(" \"%s\"", excl->name);	}	g_printf("\n");    }    if(dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {	g_printf("        exclude list");	if(dp->exclude_optional) g_printf(" optional");	for(excl = dp->exclude_list->first; excl != NULL; excl = excl->next) {	    g_printf(" \"%s\"", excl->name);	}	g_printf("\n");    }    if(dp->include_file != NULL && dp->include_file->nb_element > 0) {	g_printf("        include file");	for(excl = dp->include_file->first; excl != NULL; excl = excl->next) {	    g_printf(" \"%s\"", excl->name);	}	g_printf("\n");    }    if(dp->include_list != NULL && dp->include_list->nb_element > 0) {	g_printf("        include list");	if(dp->include_optional) g_printf(" optional");	for(excl = dp->include_list->first; excl != NULL; excl = excl->next) {	    g_printf(" \"%s\"", excl->name);	}	g_printf("\n");    }    g_printf("        priority %d\n", dp->priority);    g_printf("        dumpcycle %d\n", dp->dumpcycle);    g_printf("        maxdumps %d\n", dp->maxdumps);    g_printf("        maxpromoteday %d\n", dp->maxpromoteday);    if(dp->bumppercent > 0) {	g_printf("        bumppercent %d\n", dp->bumppercent);    }    else {	g_printf("        bumpsize %lld\n",		(long long)dp->bumpsize);    }    g_printf("        bumpdays %d\n", dp->bumpdays);    g_printf("        bumpmult %lf\n", dp->bumpmult);    g_printf("        strategy ");    switch(dp->strategy) {    case DS_SKIP:	g_printf("SKIP\n");	break;    case DS_STANDARD:	g_printf("STANDARD\n");	break;    case DS_NOFULL:	g_printf("NOFULL\n");	break;    case DS_NOINC:	g_printf("NOINC\n");	break;    case DS_HANOI:	g_printf("HANOI\n");	break;    case DS_INCRONLY:	g_printf("INCRONLY\n");	break;    }    g_printf("        ignore %s\n", (dp->ignore? "YES" : "NO"));    g_printf("        estimate ");    switch(dp->estimate) {    case ES_CLIENT:	g_printf("CLIENT\n");	break;    case ES_SERVER:	g_printf("SERVER\n");	break;    case ES_CALCSIZE:	g_printf("CALCSIZE\n");	break;    }    g_printf("        compress ");    switch(dp->compress) {    case COMP_NONE:	g_printf("NONE\n");	break;    case COMP_FAST:	g_printf("CLIENT FAST\n");	break;    case COMP_BEST:	g_printf("CLIENT BEST\n");	break;    case COMP_SERVER_FAST:	g_printf("SERVER FAST\n");	break;    case COMP_SERVER_BEST:	g_printf("SERVER BEST\n");	break;    }    if(dp->compress != COMP_NONE) {	g_printf("        comprate %.2lf %.2lf\n",	       dp->comprate[0], dp->comprate[1]);    }    g_printf("        encrypt ");    switch(dp->encrypt) {    case ENCRYPT_NONE:	g_printf("NONE\n");	break;    case ENCRYPT_CUST:	g_printf("CLIENT\n");	break;    case ENCRYPT_SERV_CUST:	g_printf("SERVER\n");	break;    }    g_printf("        auth %s\n", dp->security_driver);    g_printf("        kencrypt %s\n", (dp->kencrypt? "YES" : "NO"));    g_printf("        amandad_path %s\n", dp->amandad_path);    g_printf("        client_username %s\n", dp->client_username);    g_printf("        ssh_keys %s\n", dp->ssh_keys);    g_printf("        holdingdisk ");    switch(dp->to_holdingdisk) {    case HOLD_NEVER:	g_printf("NEVER\n");	break;    case HOLD_AUTO:	g_printf("AUTO\n");	break;    case HOLD_REQUIRED:	g_printf("REQUIRED\n");	break;    }    g_printf("        record %s\n", (dp->record? "YES" : "NO"));    g_printf("        index %s\n", (dp->index? "YES" : "NO"));    g_printf("        starttime %04d\n", (int)dp->starttime);    if(dp->tape_splitsize > (off_t)0) {	g_printf("        tape_splitsize %lld\n",	       (long long)dp->tape_splitsize);    }    if(dp->split_diskbuffer) {	g_printf("        split_diskbuffer %s\n", dp->split_diskbuffer);    }    if(dp->fallback_splitsize > (off_t)0) {	g_printf("        fallback_splitsize %lldMb\n",	       (long long)(dp->fallback_splitsize / (off_t)1024));    }    g_printf("        skip-incr %s\n", (dp->skip_incr? "YES" : "NO"));    g_printf("        skip-full %s\n", (dp->skip_full? "YES" : "NO"));    g_printf("        spindle %d\n", dp->spindle);    g_printf("\n");}voiddisklist(    int		argc,    char **	argv){    disk_t *dp;    if(argc >= 4)	diskloop(argc, argv, "disklist", disklist_one);    else	for(dp = diskq.head; dp != NULL; dp = dp->next)	    disklist_one(dp);}voidshow_version(    int		argc,    char **	argv){    int i;    (void)argc;	/* Quiet unused parameter warning */    (void)argv;	/* Quiet unused parameter warning */    for(i = 0; version_info[i] != NULL; i++)	g_printf("%s", version_info[i]);}void show_config(    int argc G_GNUC_UNUSED,    char **argv G_GNUC_UNUSED){    dump_configuration();}

⌨️ 快捷键说明

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