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

📄 amaddclient.pl

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 PL
📖 第 1 页 / 共 2 页
字号:
chomp($lhost);# get our own canonical name, if possible (we don't sweat the IPv6 stuff here)my $host=(gethostbyname($lhost))[0];unless ( $host ) {    $host = $lhost;  #gethostbyname() failed, go with hostname output}my $found=0;my $fhs;# make sure dumptype is defined in dumptypes or amanda.conf fileif ( defined $dumptype ) { for $fhs ( "$confdir/template.d/dumptypes", "$confdir/$config/amanda.conf" ) {    open (DTYPE, $fhs) ||	&log_and_die ("ERROR: Cannot open $fhs file : $!\n");    while (<DTYPE>) {	if (/^\s*define\s*dumptype\s*$dumptype\s*{/) {	    $found=1;	    last;	}	}	close (DTYPE);    }    unless ( $found ) {        &log_and_die ("ERROR: $dumptype not defined in $confdir/template.d/dumptypes or $confdir/$config/amanda.conf\n");    }}# create disklist file    unless ( -e "$confdir/$config"  ) {	&log_and_die ("ERROR: $confdir/$config not found\n");    }    $found=0;    if (defined $includefile || defined $includelist 		    || defined $excludefile || defined $excludelist) {	$sp_diskfile=1;	}    unless ( -e "$confdir/$config/disklist" ) {	 # create it if necessary        open (DLE, ">$confdir/$config/disklist") || 	    &log_and_die ("ERROR: Cannot create $confdir/$config/disklist file : $!\n");	print DLE "#This file is generated by amaddclient.\n";	print DLE "#Don't edit it manually, otherwise, 'amaddclient -m ...' might not work\n";    }    open (DLE, "+<$confdir/$config/disklist")    # open for read/write	|| &log_and_die ("ERROR: Cannot open $confdir/$config/disklist file : $!\n");    while (<DLE>) {	my ($lclient, $ldiskdev, $dontcare ) = split(/\s+/, $_);	if (( $lclient eq $client ) && ($ldiskdev eq $diskdev) ) {	    $found=1;	    last;	}    }# if found and -m, do modification and exit     if ( defined $mod ) {	if ( $found ) {	&dle_mod;    } else {	&log_and_die ("ERROR: $client $diskdev not found, cannot modify\n");    }    }unless ( defined $dumptype ) {    $dumptype=$def_dumptype;}     if ( $found==1 ) {	&mprint("$confdir/$config/disklist has '$client $diskdev ...' entry, file not updated\n"); }    else {	print DLE "$client  $diskdev ";	print DLE "{\n$dumptype\n" if ($sp_diskfile);	if ( defined $includefile ) {	    print DLE "include file \"$includefile\"\n";	}	elsif ( defined $includelist ) {	    print DLE "include list \"$includelist\"\n";	}	if ( defined $excludefile ) {	    print DLE "exclude file \"$excludefile\"\n";	}	elsif ( defined $excludelist ) {	    print DLE "exclude list \"$excludelist\"\n";	}        print DLE "}\n" if ($sp_diskfile);        print DLE "  $dumptype\n" if ($sp_diskfile==0);	&mprint ("$confdir/$config/disklist updated\n");	close (DLE);    }# update .amandahosts on server and client    my $scp="scp";    my $scp_opt1="-p";   # p: preserve mode    my $scp_opt2="-o ConnectTimeout=15";   #timeout after 15 seconds    my $ssh="ssh";    my $ssh_opt="-x"; # -x as a placeholder, otherwise ssh complains    my $mkdir="mkdir";    my $client_conf_dir="$confdir/$config";    my $amanda_client_conf="$client_conf_dir/amanda-client.conf";    my $file="$amandahomedir/.amandahosts";    my $client_file="$amandahomedir/amanda-client.conf-$client";      if ( defined $batch ) {    $scp_opt1="-Bp";    $ssh_opt="-o BatchMode=yes";  }        &mprint ("updating $file on $host\n");    unless ( defined $root_user ) {    $root_user=$def_root_user;  }    $found=0;    open (HFILE, "+<$file") 	|| &log_and_die ("ERROR: Cannot open $file : $!\n");		while (<HFILE>) {	    if (/^\s*$client\s*$root_user\s*amindexd\s*amidxtaped\s/) {		$found=1;		last;	    }	}    if ( $found==1 ) {	&mprint ("$file contains $client $root_user, file not updated\n") ; }    else {	print HFILE "$client  $root_user amindexd amidxtaped\n";	close (HFILE);    }# update client .amandahostsunless ( $no_client_update ) {         &mprint ("Attempting to update $file on $client\n");    chdir ("$amandahomedir");    system "$scp", "$scp_opt1", "$scp_opt2", "$amanda_user\@$client:$file", "$file.tmp";    $exit_value  = $? >> 8;    if ( $exit_value !=0 ) {	&mprint ("WARNING: $scp from $client not successful.\n");	&mprint ("Check $client:$file file.\n");	&mprint ("If entry '$host $amanda_user' is not present,\n");	&mprint ("append the entry to the file manually.\n");    }    else {     $found=0;    unless ( -e "$file.tmp" ) {	&mprint ("WARNING: $file.tmp not found\n"); }    else {	open (CFILE, "+<$file.tmp") 	    || &log_and_die ("ERROR: Cannot open $file.tmp file : $!\n");	while (<CFILE>) {	    if (/^\s*$host\s*$amanda_user\s*amdump\s/) {		$found=1;		last;	    }	}	if ( $found==1 ) {	    &mprint ("$file contains $host $amanda_user, file not updated\n") ; }	else {	    print CFILE "$host  $amanda_user amdump\n";	    close (CFILE);	    	    #make sure permission mode is correct	    chmod (0600, "$file.tmp");	    system "$scp", "$scp_opt1", "$scp_opt2", "$file.tmp", "$client:$file";	    $exit_value  = $? >> 8;	    if ( $exit_value !=0 ) {		&mprint ("WARNING: $scp to $client not successful.\n");		&mprint ("Check $client:$file file.\n");		&mprint ("If entry '$host $amanda_user amdump' is not present,\n");		&mprint ("append the entry to the file manually.\n");	    }    	}     }    unlink ("$file.tmp") || &mprint("unlink $file.tmp failed: $!\n");    &mprint ("$client:$file updated successfully\n");  }  }# done updating client .amandahosts#create amanda-client.conf and scp over to clientunless ( $no_client_update ) {&mprint ("Creating amanda-client.conf for $client\n");$auth="bsdtcp" unless ( defined $auth ); open (ACFILE, ">$client_file") || &log_and_die ("ERROR: Cannot open $client_file file : $!\n"); print ACFILE "#amanda-client.conf - Amanda client configuration file.\n"; print ACFILE "conf            \"$config\"\n"; print ACFILE "index_server    \"$host\"\n"; print ACFILE "tape_server     \"$host\"\n"; print ACFILE "#  auth  - authentication scheme to use between server and client.\n"; print ACFILE "#          Valid values are 'bsdtcp' or 'ssh'\n"; print ACFILE "auth            \"$auth\"\n"; print ACFILE "# ssh keys file if ssh auth is used\n"; print ACFILE "ssh_keys        \"$amandahomedir/.ssh/id_rsa_amrecover\"\n"; print ACFILE "gnutar_list_dir \"$tarlist\"\n" if ( defined $tarlist ); print ACFILE "amandates       \"$amandates\"\n" if ( defined $amandates ); close (ACFILE);&mprint ("Creating  $client_conf_dir on $client\n");system "$ssh", "$ssh_opt", "$amanda_user\@$client", "$mkdir", "$client_conf_dir";$exit_value  = $? >> 8;if ( $exit_value !=0 ) {  &mprint ("WARNING: Cannot create $client_conf_dir on $client\n");  &mprint ("Please copy $client_file to $client manually\n");} else {   chmod (0600, "$client_file");  system "$scp", "$scp_opt1", "$scp_opt2", "$client_file", "$amanda_user\@$client:$amanda_client_conf";  $exit_value  = $? >> 8;  if ( $exit_value !=0 ) {    &mprint ("WARNING: Cannot copy $client_file to $client\n");    &mprint ("Please copy $client_file to $client:$client_conf_dir manually\n");  } else {    &mprint ("Copy $client_file to $client successfully\n");    unlink($client_file);  }      }}#create gnutar_list_dirif ( defined $tarlist && !defined $no_update_client ) { system "$ssh", "$ssh_opt", "$amanda_user\@$client", "$mkdir", "$gnutar_list_dir"; $exit_value  = $? >> 8;if ( $exit_value !=0 ) {  &mprint ("WARNING: Cannot create $gnutar_list_dir on $client\n");   &mprint ("Please create $gnutar_list_dir on $client manually\n");} else {   &mprint ("$client_file created on $client successfully\n");}}&mprint ("File /var/lib/amanda/example/xinetd.amandaclient contains the latest Amanda client daemon configuration.\n");&mprint ("Please merge it to /etc/xinetd.d/amandaclient.\n"); $ENV{'PATH'} = $oldPATH;close (LOG);#THE END				           

⌨️ 快捷键说明

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