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

📄 amrecover.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* disk name may be specified by mount point (logical name) or       device name, have to determine */    g_printf(_("Trying disk %s ...\n"), *mpt_guess);    disk_try = stralloc2("DISK ", *mpt_guess);		/* try logical name */    if (exchange(disk_try) == -1)	exit(1);    amfree(disk_try);    if (server_happy())    {	*dn_guess = stralloc(*mpt_guess);		/* logical is okay */	amfree(fsname);	return 1;    }    g_printf(_("Trying disk %s ...\n"), fsname);    disk_try = stralloc2("DISK ", fsname);		/* try device name */    if (exchange(disk_try) == -1)	exit(1);    amfree(disk_try);    if (server_happy())    {	*dn_guess = stralloc(fsname);			/* dev name is okay */	amfree(fsname);	return 1;    }    /* neither is okay */    amfree(*mpt_guess);    amfree(fsname);    return 2;}voidquit(void){    quit_prog = 1;    (void)converse("QUIT");}char *localhost = NULL;#ifdef DEFAULT_TAPE_SERVER# define DEFAULT_TAPE_SERVER_FAILOVER (DEFAULT_TAPE_SERVER)#else# define DEFAULT_TAPE_SERVER_FAILOVER (NULL)#endifintmain(    int		argc,    char **	argv){    in_port_t my_port;    struct servent *sp;    int i;    time_t timer;    char *lineread = NULL;    struct sigaction act, oact;    extern char *optarg;    extern int optind;    char cwd[STR_SIZE], *dn_guess = NULL, *mpt_guess = NULL;    char *service_name;    char *line = NULL;    struct tm *tm;    /*     * Configure program for internationalization:     *   1) Only set the message locale for now.     *   2) Set textdomain for all amanda related programs to "amanda"     *      We don't want to be forced to support dozens of message catalogs.     */      setlocale(LC_MESSAGES, "C");    textdomain("amanda");     safe_fd(-1, 0);    set_pname("amoldrecover");    /* Don't die when child closes pipe */    signal(SIGPIPE, SIG_IGN);    dbopen(DBG_SUBDIR_CLIENT);    localhost = alloc(MAX_HOSTNAME_LENGTH+1);    if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) {	error(_("cannot determine local host name\n"));	/*NOTREACHED*/    }    localhost[MAX_HOSTNAME_LENGTH] = '\0';    config = newstralloc(config, DEFAULT_CONFIG);    dbrename(config, DBG_SUBDIR_CLIENT);    check_running_as(RUNNING_AS_ROOT);    amfree(server_name);    server_name = getenv("AMANDA_SERVER");    if(!server_name) server_name = DEFAULT_SERVER;    server_name = stralloc(server_name);    amfree(tape_server_name);    tape_server_name = getenv("AMANDA_TAPESERVER");    if(!tape_server_name) tape_server_name = DEFAULT_TAPE_SERVER;    tape_server_name = stralloc(tape_server_name);    config_init(CONFIG_INIT_CLIENT, NULL);    if (argc > 1 && argv[1][0] != '-')    {	/*	 * If the first argument is not an option flag, then we assume	 * it is a configuration name to match the syntax of the other	 * Amanda utilities.	 */	char **new_argv;	new_argv = (char **) alloc((size_t)((argc + 1 + 1) * sizeof(*new_argv)));	new_argv[0] = argv[0];	new_argv[1] = "-C";	for (i = 1; i < argc; i++)	{	    new_argv[i + 1] = argv[i];	}	new_argv[i + 1] = NULL;	argc++;	argv = new_argv;    }    while ((i = getopt(argc, argv, "C:s:t:d:U")) != EOF)    {	switch (i)	{	    case 'C':		config = newstralloc(config, optarg);		break;	    case 's':		server_name = newstralloc(server_name, optarg);		break;	    case 't':		tape_server_name = newstralloc(tape_server_name, optarg);		break;	    case 'd':		tape_device_name = newstralloc(tape_device_name, optarg);		break;	    case 'U':	    case '?':		(void)g_printf(USAGE);		return 0;	}    }    if (optind != argc)    {	(void)g_fprintf(stderr, USAGE);	exit(1);    }    amfree(disk_name);    amfree(mount_point);    amfree(disk_path);    dump_date[0] = '\0';    /* Don't die when child closes pipe */    signal(SIGPIPE, SIG_IGN);    /* set up signal handler */    act.sa_handler = sigint_handler;    sigemptyset(&act.sa_mask);    act.sa_flags = 0;    if (sigaction(SIGINT, &act, &oact) != 0) {	error(_("error setting signal handler: %s"), strerror(errno));	/*NOTREACHED*/    }    service_name = stralloc2("amandaidx", SERVICE_SUFFIX);    g_printf(_("AMRECOVER Version %s. Contacting server on %s ...\n"),	   version(), server_name);      if ((sp = getservbyname(service_name, "tcp")) == NULL) {	error(_("%s/tcp unknown protocol"), service_name);	/*NOTREACHED*/    }    amfree(service_name);    server_socket = stream_client_privileged(server_name,					     (in_port_t)ntohs((in_port_t)sp->s_port),					     0,					     0,					     &my_port,					     0);    if (server_socket < 0) {	error(_("cannot connect to %s: %s"), server_name, strerror(errno));	/*NOTREACHED*/    }    if (my_port >= IPPORT_RESERVED) {        aclose(server_socket);	error(_("did not get a reserved port: %d"), my_port);	/*NOTREACHED*/    }    /* get server's banner */    if (grab_reply(1) == -1) {        aclose(server_socket);	exit(1);    }    if (!server_happy())    {	dbclose();	aclose(server_socket);	exit(1);    }    /* do the security thing */    line = get_security();    if (converse(line) == -1) {        aclose(server_socket);	exit(1);    }    if (!server_happy()) {        aclose(server_socket);	exit(1);    }    memset(line, '\0', strlen(line));    amfree(line);    /* try to get the features from the server */    {	char *our_feature_string = NULL;	char *their_feature_string = NULL;	our_features = am_init_feature_set();	our_feature_string = am_feature_to_string(our_features);	line = stralloc2("FEATURES ", our_feature_string);	if(exchange(line) == 0) {	    their_feature_string = stralloc(server_line+13);	    indexsrv_features = am_string_to_feature(their_feature_string);	}	else {	    indexsrv_features = am_set_default_feature_set();        }	amfree(our_feature_string);	amfree(their_feature_string);	amfree(line);    }    /* set the date of extraction to be today */    (void)time(&timer);    tm = localtime(&timer);    if (tm)	strftime(dump_date, sizeof(dump_date), "%Y-%m-%d", tm);    else	error(_("BAD DATE"));    g_printf(_("Setting restore date to today (%s)\n"), dump_date);    line = stralloc2("DATE ", dump_date);    if (converse(line) == -1) {        aclose(server_socket);	exit(1);    }    amfree(line);    line = stralloc2("SCNF ", config);    if (converse(line) == -1) {        aclose(server_socket);	exit(1);    }    amfree(line);    if (server_happy())    {	/* set host we are restoring to this host by default */	amfree(dump_hostname);	set_host(localhost);	if (dump_hostname)	{            /* get a starting disk and directory based on where	       we currently are */	    switch (guess_disk(cwd, sizeof(cwd), &dn_guess, &mpt_guess))	    {		case 1:		    /* okay, got a guess. Set disk accordingly */		    g_printf(_("$CWD '%s' is on disk '%s' mounted at '%s'.\n"),			   cwd, dn_guess, mpt_guess);		    set_disk(dn_guess, mpt_guess);		    set_directory(cwd);		    if (server_happy() && strcmp(cwd, mpt_guess) != 0)		        g_printf(_("WARNING: not on root of selected filesystem, check man-page!\n"));		    amfree(dn_guess);		    amfree(mpt_guess);		    break;		case 0:		    g_printf(_("$CWD '%s' is on a network mounted disk\n"),			   cwd);		    g_printf(_("so you must 'sethost' to the server\n"));		    /* fake an unhappy server */		    server_line[0] = '5';		    break;		case 2:		case -1:		default:		    g_printf(_("Use the setdisk command to choose dump disk to recover\n"));		    /* fake an unhappy server */		    server_line[0] = '5';		    break;	    }	}    }    quit_prog = 0;    do    {	if ((lineread = readline("amrecover> ")) == NULL) {	    clearerr(stdin);	    putchar('\n');	    break;	}	if (lineread[0] != '\0') 	{	    add_history(lineread);	    process_line(lineread);	/* act on line's content */	}	amfree(lineread);    } while (!quit_prog);    dbclose();    aclose(server_socket);    return 0;}char *get_security(void){    struct passwd *pwptr;    if((pwptr = getpwuid(getuid())) == NULL) {	error(_("can't get login name for my uid %ld"), (long)getuid());	/*NOTREACHED*/    }    return stralloc2("SECURITY USER ", pwptr->pw_name);}

⌨️ 快捷键说明

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