📄 amserverconfig.pl
字号:
{ if (defined $tapedev){ $tapedev="file:/".$tapedev; } unless ( $tpchanger ) { $tpchanger="chg-disk"; } unless ( $tapedev ) { $tapedev="$def_tapedev/$config"; } unless ( $changerfile ) { $changerfile="$confdir/$config/changer.conf"; } unless ( $changerdev ) { $changerdev="/dev/null";} unless ( $tapetype ) { $tapetype="HARDDISK"; } } elsif ($template eq "single-tape") { unless ($tpchanger) {$tpchanger="chg-manual";} unless ($tapedev) {$tapedev="/dev/nst0";} unless ($changerfile) {$changerfile="$confdir/$config/chg-manual.conf";} unless ($changerdev) {$changerdev="/dev/null";} unless ($tapetype) {$tapetype="HP-DAT";} } elsif ($template eq "tape-changer") { unless ($tpchanger){$tpchanger="chg-zd-mtx";} unless ($tapedev){ $tapedev="/dev/nst0";} unless ($changerfile){$changerfile="$confdir/$config/changer.conf";} unless ($changerdev) {$changerdev="/dev/sg1";} unless ($tapetype) {$tapetype="HP-DAT";} } else # S3 case { unless ($tpchanger){$tpchanger="chg-multi";} unless ($changerfile){$changerfile="$confdir/$config/changer.conf";} unless ($tapetype) {$tapetype="HP-DAT";} } open (CONF, ">$confdir/$config/amanda.conf") || &log_and_die ("ERROR: Cannot create amanda.conf file: $!\n", 1); chmod ($amanda_conf_perm, "$confdir/$config/amanda.conf") || &log_and_die ("ERROR: Cannot set amanda.conf file access permission: $!\n", 1); print CONF "org \"$config\"\t\t# your organization name for reports\n"; print CONF "mailto \"$mailto\"\t# space separated list of operators at your site\n"; print CONF "dumpcycle $dumpcycle\t\t# the number of days in the normal dump cycle\n"; print CONF "runspercycle $runspercycle\t\t# the number of amdump runs in dumpcycle days\n"; print CONF "tapecycle $tapecycle\t# the number of tapes in rotation\n"; print CONF "runtapes $runtapes\t\t# number of tapes to be used in a single run of amdump\n"; print CONF "tpchanger \"$tpchanger\"\t# the tape-changer glue script\n"; print CONF "tapedev \"$tapedev\"\t# the no-rewind tape device\n"; print CONF "changerfile \"$changerfile\"\t# tape changer configuration parameter file\n"; print CONF "changerdev \"$changerdev\"\t# tape changer configuration parameter device\n"; print CONF "tapetype $tapetype\t# what kind of tape it is\n"; print CONF "labelstr \"$labelstr\"\t# label constraint regex: all tapes must match\n"; print CONF "dtimeout $def_dtimeout\t# number of idle seconds before a dump is aborted\n"; print CONF "ctimeout $def_ctimeout\t# max number of secconds amcheck waits for each client\n"; print CONF "etimeout $def_etimeout\t# number of seconds per filesystem for estimates\n"; print CONF "define dumptype global {\n"; print CONF " comment \"Global definitions\"\n"; print CONF " auth \"bsdtcp\"\n}\n"; print CONF "define dumptype gui-base {\n"; print CONF " global\n"; print CONF " program \"GNUTAR\"\n"; print CONF " comment \"gui base dumptype dumped with tar\"\n"; print CONF " compress none\n"; print CONF " index yes\n}\n"; if ($tapetype eq "HARDDISK") { print CONF "define tapetype HARDDISK {\n"; print CONF " comment \"Virtual Tapes\"\n"; print CONF " length 5000 mbytes\n}\n"; } print CONF "includefile \"advanced.conf\"\n"; print CONF "includefile \"$confdir/template.d/dumptypes\"\n"; print CONF "includefile \"$confdir/template.d/tapetypes\"\n"; close (CONF); mprint ("custom amanda.conf created\n"); }sub check_xinetd{ &mprint ("/var/lib/amanda/example/xinetd.amandaserver contains the latest Amanda server daemon configuration.\n"); &mprint ("Please merge it to /etc/xinetd.d/amandaserver.\n");}sub build_amanda_ssh_key{ if ( -e "$amandahomedir/.ssh/id_rsa_amdump.pub" ) { if ( -e "$amandahomedir/.ssh/client_authorized_key" ) { &mprint ("$amandahomedir/.ssh/client_authorized_keys exists.\n"); } else { open(NEWAUTH, ">$amandahomedir/.ssh/client_authorized_keys") || (&mprint("WARNING: open $amandahomedir/.ssh/client_authorized_key failed: $!\n"), return); open(PUB, "$amandahomedir/.ssh/id_rsa_amdump.pub") || (&mprint("WARNING: open $amandahomedir/.ssh/id_rsa_amdump.pub failed: $!\n"), return); print NEWAUTH "from=\"$host\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,command=\"/usr/lib/amanda/amandad -auth=ssh amdump\" "; while (<PUB>) { print NEWAUTH; } close NEWAUTH; close PUB; &mprint("$amandahomedir/.ssh/client_authorized_keys created. Please append to /var/lib/amanda/.ssh/authorized_keys file on Amanda clients\n"); } }}sub copy_chg_manual_conf { if ( $template eq "single-tape" && !defined $changerfile && !defined $tpchanger) { my $my_changerfile="$confdir/$config/chg-manual.conf"; copy("$datadir/chg-manual.conf", $my_changerfile) || &mprint ("copy $datadir/chg-manual.conf to $my_changerfile failed: $!\n"); }}#mainmy $ret=0;$ret = GetOptions ("template=s"=>\$template, "no-vtape!"=>\$novtape, "tapetype=s"=>\$tapetype, "tpchanger=s"=>\$tpchanger, "tapedev=s"=>\$tapedev, "changerfile=s"=>\$changerfile, "changerdev=s"=>\$changerdev, "labelstr=s"=>\$labelstr, "mailto=s"=>\$mailto, "dumpcycle=s"=>\$dumpcycle, "runspercycle=i"=>\$runspercycle, "runtapes=i"=>\$runtapes, "tapecycle=i"=>\$tapecycle, "help!"=>\$help );unless ( $ret ) { &usage; exit 1;}if($help) { &usage; exit 0;}unless ( $#ARGV == 0 ) { print STDERR "ERROR: config name is required.\n"; &usage; exit 1;}else { if ( "$ARGV[0]" =~ /^([-\@\w.]+)$/ ) { $config = $1; # now untainted } else { die ("ERROR: Invalid data in config name.\n"); # log this somewhere }}$oldPATH = $ENV{'PATH'};$ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin:/usr/ucb"; # force known pathdelete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};$date=`date +%Y%m%d%H%M%S`;chomp($date);my $logfile="$tmpdir/amserverconfig.$date.debug";&is_user_right;unless ( -e "$tmpdir" ) { mkdir ("$tmpdir", $def_perm) || die ("ERROR: mkdir: $tmpdir failed: $!\n");}open (LOG, ">$logfile") || die ("ERROR: Cannot create logfile: $!\n");print STDOUT "Logging to $logfile\n";my $lhost=`hostname`;chomp($lhost);# get our own canonical name, if possible (we don't sweat the IPv6 stuff here)$host=(gethostbyname($lhost))[0];unless ( $host ) { $host = $lhost; #gethostbyname() failed, go with hostname output}&create_conf_dir;if ( defined $template ) {# validate user input to template chomp($template); my $found = 0; @valid_templates = ( "harddisk", "single-tape", "tape-changer", "s3"); foreach $elt (@valid_templates) { if ($elt eq lc($template)) { $found = 1; last; } } unless ( $found ) { print STDERR "valid inputs to --templates are harddisk, single-tape, tape-changer or S3\n"; &usage; exit 1;}# if tape-changer is chosen, check if mtx is installed if ($template eq "tape-changer") { my $ok = 0; for $dir ("/usr/sbin", "/usr/local/sbin", "/usr/local/bin", "/usr/bin", "/bin","/opt/csw/sbin",split(":",$oldPATH)) { if ( -e "$dir/mtx" ) { $ok = 1; last; } } unless ($ok) { &mprint ("ERROR: mtx binary not found, tape-changer template will not work and is not installed.\n"); &log_and_die ("ERROR: Please install mtx and rerun the same command.\n", 0); } unless ($changerfile) {$changerfile="$confdir/$config/changer.conf";} open (CCONF, ">$changerfile") || &log_and_die ("ERROR: Cannot create $changerfile: $!\n", 1); close (CCONF); } elsif ($template eq "S3" ) { unless ($changerfile) {$changerfile="$confdir/$config/changer.conf";} open (CCONF, ">$changerfile") || &log_and_die ("ERROR: Cannot create $changerfile: $!\n", 1); close (CCONF); }}&check_gnutarlist_dir;# copy dumptypes and tapetypes files if none exists.my $dtype="$confdir/template.d/dumptypes";my $ttype="$confdir/template.d/tapetypes";unless ( -e $dtype ) { copy("$datadir/dumptypes", $dtype ) || &log_and_die ("ERROR: copy dumptypes failed: $!\n", 1);}unless ( -e $ttype ) { copy("$datadir/tapetypes", $ttype ) || &log_and_die ("ERROR: copy tapetypes file to $ttype failed: $!\n", 1);}# update $def_config value to the specified config value in advanced.conf open(ADV, "$datadir/advanced.conf") || &log_and_die ("ERROR: Cannot open advanced.conf file: $!\n", 1); open(NEWADV, ">$confdir/$config/advanced.conf") || &log_and_die ("ERROR: Cannot create advanced.conf file: $!\n", 1); while (<ADV>) { $_ =~ s/$def_config/$config/; print NEWADV $_; } close(ADV); close(NEWADV); &mprint ("$confdir/$config/advanced.conf created and updated\n");&create_curinfo_index_dir;&touch_list_files;if ( defined $template ) {# if any other parameters are provided, create a workable custom config if ( defined $tapetype || defined $tpchanger || defined $tapedev || defined $changerdev || defined $labelstr || defined $mailto || defined $dumpcycle || defined $runspercycle || defined $runtapes || defined $tapecycle ) { &mprint("Creating custom configuration using templates\n"); create_customconf(); if ( $template ne "harddisk" ) { &create_holding; } else { if (defined $labelstr) { if ($labelstr=~/^([-\w.]+)$/) { &create_vtape unless ( defined $novtape ); } else { &mprint ("WARNING: Only alphanumeric string is supported in labelstr when using template to create vtapes. "); &mprint ("If you want to use regex in labelstr, please create vtapes manually.\n"); } } } } else { $template_only=1; $tapedev="$def_tapedev/$config"; ©_template_file($template); if ($template ne "harddisk") { unless ( -e "$amandahomedir/holdings/$config" ) { &create_holding; } } else { # harddisk and template only unless ( -e "$amandahomedir/vtapes/$config" || defined $novtape ) { &create_vtape; } } } ©_chg_manual_conf; } else {&create_customconf;}&check_xinetd;&build_amanda_ssh_key;if ( $vtape_err ) { &mprint("Error in creating virtual tape, please check log and create virtual tape manually.\n"); exit 1;}if ( $holding_err ) { &mprint("Error in creating holding disk, please check log and create holding disk manually.\n"); exit 1;}if ( $vtape_err==0 && $holding_err==0) { &mprint("DONE.\n"); exit 0;}$ENV{'PATH'} = $oldPATH;# THE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -