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

📄 sendsize.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 4 页
字号:
    newp->amname = stralloc(disk);    newp->qamname = quote_string(disk);    newp->amdevice = stralloc(amdevice);    newp->qamdevice = quote_string(amdevice);    newp->dirname = amname_to_dirname(newp->amdevice);    newp->qdirname = quote_string(newp->dirname);    newp->program = stralloc(prog);    if(calcprog != NULL)	newp->calcprog = stralloc(calcprog);    else	newp->calcprog = NULL;    newp->program_is_backup_api = program_is_backup_api;    newp->spindle = spindle;    newp->est[level].needestimate = 1;    newp->options = options;    /* fill in dump-since dates */    amdp = amandates_lookup(newp->amname);    newp->est[0].dumpsince = EPOCH;    for(dumplev = 0; dumplev < DUMP_LEVELS; dumplev++) {	dumpdate = amdp->dates[dumplev];	for(estlev = dumplev+1; estlev < DUMP_LEVELS; estlev++) {	    if(dumpdate > newp->est[estlev].dumpsince)		newp->est[estlev].dumpsince = dumpdate;	}    }}voidfree_estimates(    disk_estimates_t *	est){    amfree(est->amname);    amfree(est->qamname);    amfree(est->amdevice);    amfree(est->qamdevice);    amfree(est->dirname);    amfree(est->qdirname);    amfree(est->program);    if(est->options) {	free_sl(est->options->exclude_file);	free_sl(est->options->exclude_list);	free_sl(est->options->include_file);	free_sl(est->options->include_list);	amfree(est->options->str);	amfree(est->options->auth);	amfree(est->options);    }}/* * ------------------------------------------------------------------------ * */voidcalc_estimates(    disk_estimates_t *	est){    dbprintf(_("calculating for amname %s, dirname %s, spindle %d\n"),	      est->qamname, est->qdirname, est->spindle);	    if(est->program_is_backup_api ==  1)	backup_api_calc_estimate(est);    else#ifndef USE_GENERIC_CALCSIZE    if(strcmp(est->program, "DUMP") == 0)	dump_calc_estimates(est);    else#endif#ifdef SAMBA_CLIENT      if (strcmp(est->program, "GNUTAR") == 0 &&	  est->amdevice[0] == '/' && est->amdevice[1] == '/')	smbtar_calc_estimates(est);      else#endif#ifdef GNUTAR	if (strcmp(est->program, "GNUTAR") == 0)	  gnutar_calc_estimates(est);	else#endif#ifdef SAMBA_CLIENT	  if (est->amdevice[0] == '/' && est->amdevice[1] == '/')	    dbprintf(_("Can't use CALCSIZE for samba estimate: %s %s\n"),		      est->qamname, est->qdirname);	  else#endif	    generic_calc_estimates(est);    dbprintf(_("done with amname %s dirname %s spindle %d\n"),	      est->qamname, est->qdirname, est->spindle);}/* * ------------------------------------------------------------------------ * *//* local functions */off_t getsize_dump(char *disk, char *amdevice, int level, option_t *options,		   char **errmsg);off_t getsize_smbtar(char *disk, char *amdevice, int level, option_t *options,		     char **errmsg);off_t getsize_gnutar(char *disk, char *amdevice, int level,		       option_t *options, time_t dumpsince, char **errmsg);off_t getsize_backup_api(char *program, char *disk, char *amdevice, int level,			option_t *options, time_t dumpsince, char **errmsg);off_t handle_dumpline(char *str);double first_num(char *str);voidbackup_api_calc_estimate(    disk_estimates_t *	est){    int    level;    off_t  size;    char  *errmsg = NULL, *qerrmsg;    for(level = 0; level < DUMP_LEVELS; level++) {	if (est->est[level].needestimate) {	    dbprintf(_("getting size via application API for %s %s level %d\n"),		      est->qamname, est->qamdevice, level);	    size = getsize_backup_api(est->program, est->amname, est->amdevice,				      level, est->options,				      est->est[level].dumpsince, &errmsg);	    amflock(1, "size");	    g_printf(_("%s %d SIZE %lld\n"), est->qamname, level,		   (long long)size);	    if (errmsg && errmsg[0] != '\0') {		if(am_has_feature(g_options->features,				  fe_rep_sendsize_quoted_error)) {		    qerrmsg = quote_string(errmsg);		    dbprintf(_("errmsg is %s\n"), errmsg);		    g_printf(_("%s %d ERROR %s\n"),			   est->qamname, level, qerrmsg);		    amfree(qerrmsg);		}	    }	    amfree(errmsg);	    fflush(stdout);	    amfunlock(1, "size");	}    }}voidgeneric_calc_estimates(    disk_estimates_t *	est){    int pipefd = -1, nullfd = -1;    char *cmd;    char *cmdline;    char *my_argv[DUMP_LEVELS*2+22];    char number[NUM_STR_SIZE];    int i, level, my_argc;    pid_t calcpid;    int nb_exclude = 0;    int nb_include = 0;    char *file_exclude = NULL;    char *file_include = NULL;    times_t start_time;    FILE *dumpout = NULL;    off_t size = (off_t)1;    char *line = NULL;    char *match_expr;    amwait_t wait_status;    char *errmsg = NULL, *qerrmsg;    char tmppath[PATH_MAX];    cmd = vstralloc(amlibexecdir, "/", "calcsize", versionsuffix(), NULL);    my_argc = 0;    my_argv[my_argc++] = stralloc("calcsize");    if (g_options->config)	my_argv[my_argc++] = stralloc(g_options->config);    else	my_argv[my_argc++] = stralloc("NOCONFIG");    my_argv[my_argc++] = stralloc(est->calcprog);    my_argv[my_argc++] = stralloc(est->amname);    canonicalize_pathname(est->dirname, tmppath);    my_argv[my_argc++] = stralloc(tmppath);    if(est->options->exclude_file)	nb_exclude += est->options->exclude_file->nb_element;    if(est->options->exclude_list)	nb_exclude += est->options->exclude_list->nb_element;    if(est->options->include_file)	nb_include += est->options->include_file->nb_element;    if(est->options->include_list)	nb_include += est->options->include_list->nb_element;    if(nb_exclude > 0)	file_exclude = build_exclude(est->amname,		est->amdevice, est->options, 0);    if(nb_include > 0)	file_include = build_include(est->amname,		est->amdevice, est->options, 0);    if(file_exclude) {	my_argv[my_argc++] = stralloc("-X");	my_argv[my_argc++] = file_exclude;    }    if(file_include) {	my_argv[my_argc++] = stralloc("-I");	my_argv[my_argc++] = file_include;    }    start_time = curclock();    cmdline = stralloc(my_argv[0]);    for(i = 1; i < my_argc; i++)	cmdline = vstrextend(&cmdline, " ", my_argv[i], NULL);    dbprintf(_("running: \"%s\"\n"), cmdline);    amfree(cmdline);    for(level = 0; level < DUMP_LEVELS; level++) {	if(est->est[level].needestimate) {	    g_snprintf(number, SIZEOF(number), "%d", level);	    my_argv[my_argc++] = stralloc(number); 	    dbprintf(" %s", number);	    g_snprintf(number, SIZEOF(number),			"%ld", (long)est->est[level].dumpsince);	    my_argv[my_argc++] = stralloc(number); 	    dbprintf(" %s", number);	}    }    my_argv[my_argc] = NULL;    dbprintf("\n");    fflush(stderr); fflush(stdout);    if ((nullfd = open("/dev/null", O_RDWR)) == -1) {	errmsg = vstrallocf(_("Cannot access /dev/null : %s"),			    strerror(errno));	dbprintf("%s\n", errmsg);	goto common_exit;    }    calcpid = pipespawnv(cmd, STDERR_PIPE, &nullfd, &nullfd, &pipefd, my_argv);    amfree(cmd);    dumpout = fdopen(pipefd,"r");    if (!dumpout) {	error(_("Can't fdopen: %s"), strerror(errno));	/*NOTREACHED*/    }    match_expr = vstralloc(est->qamname," %d SIZE %lld", NULL);    for(size = (off_t)-1; (line = agets(dumpout)) != NULL; free(line)) {	long long size_ = (long long)0;	if (line[0] == '\0')	    continue;	if(sscanf(line, match_expr, &level, &size_) == 2) {	    g_printf("%s\n", line); /* write to amandad */	    dbprintf(_("estimate size for %s level %d: %lld KB\n"),		      est->qamname,		      level,		      size_);	}	size = (off_t)size_;    }    amfree(match_expr);    dbprintf(_("waiting for %s %s child (pid=%d)\n"),	      my_argv[0], est->qamdevice, (int)calcpid);    waitpid(calcpid, &wait_status, 0);    if (WIFSIGNALED(wait_status)) {	errmsg = vstrallocf(_("%s terminated with signal %d: see %s"),			    "calcsize", WTERMSIG(wait_status),			    dbfn());    } else if (WIFEXITED(wait_status)) {	if (WEXITSTATUS(wait_status) != 0) {	    errmsg = vstrallocf(_("%s exited with status %d: see %s"),			        "calcsize", WEXITSTATUS(wait_status),				dbfn());	} else {	    /* Normal exit */	}    } else {	errmsg = vstrallocf(_("%s got bad exit: see %s"),			     "calcsize", dbfn());    }    dbprintf(_("after %s %s wait: child pid=%d status=%d\n"),	      my_argv[0], est->qamdevice,	      (int)calcpid, WEXITSTATUS(wait_status));    dbprintf(_(".....\n"));    dbprintf(_("estimate time for %s: %s\n"),	      est->qamname,	      walltime_str(timessub(curclock(), start_time)));common_exit:    if (errmsg && errmsg[0] != '\0') {	if(am_has_feature(g_options->features, fe_rep_sendsize_quoted_error)) {	    qerrmsg = quote_string(errmsg);	    dbprintf(_("errmsg is %s\n"), errmsg);	    g_printf("%s %d ERROR %s\n",		    est->qamname, 0, qerrmsg);	    amfree(qerrmsg);	}    }    amfree(errmsg);    for(i = 0; i < my_argc; i++) {	amfree(my_argv[i]);    }    amfree(cmd);}voiddump_calc_estimates(    disk_estimates_t *	est){    int level;    off_t size;    char *errmsg=NULL, *qerrmsg;    for(level = 0; level < DUMP_LEVELS; level++) {	if(est->est[level].needestimate) {	    dbprintf(_("getting size via dump for %s level %d\n"),		      est->qamname, level);	    size = getsize_dump(est->amname, est->amdevice,				level, est->options, &errmsg);	    amflock(1, "size");	    g_printf(_("%s %d SIZE %lld\n"),		   est->qamname, level, (long long)size);	    if (errmsg && errmsg[0] != '\0') {		if(am_has_feature(g_options->features,				  fe_rep_sendsize_quoted_error)) {		    qerrmsg = quote_string(errmsg);		    dbprintf(_("errmsg is %s\n"), errmsg);		    g_printf("%s %d ERROR %s\n",			   est->qamname, level, qerrmsg);		    amfree(qerrmsg);		}	    }	    amfree(errmsg);	    fflush(stdout);	    amfunlock(1, "size");	}    }}#ifdef SAMBA_CLIENTvoidsmbtar_calc_estimates(    disk_estimates_t *	est){    int level;    off_t size;    char  *errmsg = NULL, *qerrmsg;    for(level = 0; level < DUMP_LEVELS; level++) {	if(est->est[level].needestimate) {	    dbprintf(_("getting size via smbclient for %s level %d\n"),		      est->qamname, level);	    size = getsize_smbtar(est->amname, est->amdevice, level,				  est->options, &errmsg);	    amflock(1, "size");	    g_printf(_("%s %d SIZE %lld\n"),		   est->qamname, level, (long long)size);	    if (errmsg && errmsg[0] != '\0') {		if(am_has_feature(g_options->features,				  fe_rep_sendsize_quoted_error)) {		    qerrmsg = quote_string(errmsg);		    dbprintf(_("errmsg is %s\n"), errmsg);		    g_printf("%s %d ERROR %s\n",			   est->qamname, level, qerrmsg);		    amfree(qerrmsg);		}	    }	    amfree(errmsg);	    fflush(stdout);	    amfunlock(1, "size");	}    }}#endif#ifdef GNUTARvoidgnutar_calc_estimates(    disk_estimates_t *	est){    int level;    off_t size;    char *errmsg = NULL, *qerrmsg;    for(level = 0; level < DUMP_LEVELS; level++) {	if (est->est[level].needestimate) {	    dbprintf(_("getting size via gnutar for %s level %d\n"),		      est->qamname, level);	    size = getsize_gnutar(est->amname, est->amdevice, level,				  est->options, est->est[level].dumpsince,				  &errmsg);	    amflock(1, "size");	    g_printf(_("%s %d SIZE %lld\n"),		   est->qamname, level, (long long)size);	    if (errmsg && errmsg[0] != '\0') {		if(am_has_feature(g_options->features,				  fe_rep_sendsize_quoted_error)) {		    qerrmsg = quote_string(errmsg);		    dbprintf(_("errmsg is %s\n"), errmsg);		    g_printf(_("%s %d ERROR %s\n"),			   est->qamname, level, qerrmsg);		    amfree(qerrmsg);		}	    }	    amfree(errmsg);	    fflush(stdout);	    amfunlock(1, "size");	}    }}#endiftypedef struct regex_s {    char *regex;    int scale;} regex_scale_t;/*@ignore@*/regex_scale_t re_size[] = {#ifdef DUMP    {"  DUMP: estimated -*[0-9][0-9]* tape blocks", 1024},    {"  DUMP: [Ee]stimated [0-9][0-9]* blocks", 512},    {"  DUMP: [Ee]stimated [0-9][0-9]* bytes", 1},		/* Ultrix 4.4 */    {" UFSDUMP: estimated [0-9][0-9]* blocks", 512},		/* NEC EWS-UX */    {"dump: Estimate: [0-9][0-9]* tape blocks", 1024},		    /* OSF/1 */    {"backup: There are an estimated [0-9][0-9]* tape blocks.",1024}, /* AIX */    {"backup: estimated [0-9][0-9]* 1k blocks", 1024},		      /* AIX */    {"backup: estimated [0-9][0-9]* tape blocks", 1024},	      /* AIX */    {"backup: [0-9][0-9]* tape blocks on [0-9][0-9]* tape(s)",1024},  /* AIX */    {"backup: [0-9][0-9]* 1k blocks on [0-9][0-9]* volume(s)",1024},  /* AIX */    {"dump: Estimate: [0-9][0-9]* blocks being output to pipe",1024},							      /* DU 4.0 dump  */    {"dump: Dumping [0-9][0-9]* bytes, ", 1},		      /* DU 4.0 vdump */    {"DUMP: estimated [0-9][0-9]* KB output", 1024},		      /* HPUX */    {"DUMP: estimated [0-9][0-9]* KB\\.", 1024},		    /* NetApp */    {"  UFSDUMP: estimated [0-9][0-9]* blocks", 512},		     /* Sinix */#ifdef HAVE_DUMP_ESTIMATE    {"[0-9][0-9]* blocks, [0-9][0-9]*.[0-9][0-9]* volumes", 1024},							   /* DU 3.2g dump -E */    {"^[0-9][0-9]* blocks$", 1024},			   /* DU 4.0 dump  -E */    {"^[0-9][0-9]*$", 1},				/* Solaris ufsdump -S */#endif#endif#ifdef VDUMP    {"vdump: Dumping [0-9][0-9]* bytes, ", 1},		       /* OSF/1 vdump */#endif    #ifdef VXDUMP    {"vxdump: estimated [0-9][0-9]* blocks", 512},	     /* HPUX's vxdump */    {"  VXDUMP: estimated [0-9][0-9]* blocks", 512},		     /* Sinix */#endif#ifdef XFSDUMP    {"xfsdump: estimated dump size: [0-9][0-9]* bytes", 1},  /* Irix 6.2 xfs */#endif#ifdef GNUTAR    {"Total bytes written: [0-9][0-9]*", 1},		    /* Gnutar client */#endif#ifdef SAMBA_CLIENT#if SAMBA_VERSION >= 2#define SAMBA_DEBUG_LEVEL "0"    {"Total number of bytes: [0-9][0-9]*", 1},			 /* Samba du */#else#define SAMBA_DEBUG_LEVEL "3"    {"Total bytes listed: [0-9][0-9]*", 1},			/* Samba dir */#endif#endif    { NULL, 0 }};/*@end@*/off_tgetsize_dump(    char       *disk,    char       *amdevice,    int		level,    option_t   *options,    char      **errmsg){    int pipefd[2], nullfd, stdoutfd, killctl[2];    pid_t dumppid;    off_t size;    FILE *dumpout;    char *dumpkeys = NULL;    char *device = NULL;    char *fstype = NULL;    char *cmd = NULL;    char *name = NULL;    char *line = NULL;    char *rundump_cmd = NULL;    char level_str[NUM_STR_SIZE];    int s;    times_t start_time;    char *qdisk = quote_string(disk);    char *qdevice;    char *config;    amwait_t wait_status;#if defined(DUMP) || defined(VDUMP) || defined(VXDUMP) || defined(XFSDUMP)    int is_rundump = 1;#endif    (void)options;	/* Quiet unused parameter warning */    (void)getsize_smbtar;	/* Quiet unused parameter warning */    g_snprintf(level_str, SIZEOF(level_str), "%d", level);    device = amname_to_devname(amdevice);    qdevice = quote_string(device);    fstype = amname_to_fstype(amdevice);    dbprintf(_("calculating for device %s with %s\n"),	      qdevice, fstype);    cmd = vstralloc(amlibexecdir, "/rundump", versionsuffix(), NULL);    rundump_cmd = stralloc(cmd);    if (g_options->config)        config = g_options->config;    else        config = "NOCONFIG";    if ((stdoutfd = nullfd = open("/dev/null", O_RDWR)) == -1) {	*errmsg = vstrallocf(_("getsize_dump could not open /dev/null: %s"),			     strerror(errno));	dbprintf("%s\n", *errmsg);	amfree(cmd);	amfree(rundump_cmd);	amfree(fstype);	amfree(device);	amfree(qdevice);	amfree(qdisk);	return(-1);    }    pipefd[0] = pipefd[1] = killctl[0] = killctl[1] = -1;    if (pipe(pipefd) < 0) {	*errmsg = vstrallocf(_("getsize_dump could create data pipes: %s"),			     strerror(errno));	dbprintf("%s\n", *errmsg);	amfree(cmd);	amfree(rundump_cmd);	amfree(fstype);	amfree(device);	amfree(qdevice);	amfree(qdisk);	return(-1);    }#ifdef XFSDUMP						/* { */#ifdef DUMP						/* { */    if (strcmp(fstype, "xfs") == 0)#else							/* } { */    if (1)#endif							/* } */    {	name = stralloc(" (xfsdump)");	dbprintf(_("running \"%s%s -F -J -l %s - %s\"\n"),		  cmd, name, level_str, qdevice);    }

⌨️ 快捷键说明

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