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

📄 amaddclient.pl

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 PL
📖 第 1 页 / 共 2 页
字号:
#!@PERL@## Copyright (c) 2006 Zmanda Inc.  All Rights Reserved.## This program is free software; you can redistribute it and/or modify it# under the terms of the GNU General Public License version 2 as published# by the Free Software Foundation.## This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License# for more details.## You should have received a copy of the GNU General Public License along# with this program; if not, write to the Free Software Foundation, Inc.,# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA## Contact information: Zmanda Inc, 505 N Mathlida Ave, Suite 120# Sunnyvale, CA 94085, USA, or: http://www.zmanda.com#use Getopt::Long;use Time::Local;use File::Copy;use Socket;   # for gethostbynamemy $confdir="@CONFIG_DIR@";my $tmpdir="@AMANDA_DBGDIR@";my $prefix="@prefix@";my $localstatedir="@localstatedir@";my $amandahomedir="$localstatedir/lib/amanda";my $amanda_user="@CLIENT_LOGIN@";my $amanda_group="disk";my $def_root_user="root";my $def_dumptype="user-tar";my $sp_diskfile=0;# Get the version suffix.my $USE_VERSION_SUFFIXES = '@USE_VERSION_SUFFIXES@';my $suf = '';if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {        $suf='-@VERSION@';}sub usage {        print "$0 $suf\n";              print "\t\t--config <config>         Required. Ex: DailySet1\n";       	print "\t\t--client <FQDN-name>      Required. Ex: server.zmanda.com\n";        print "\t\t--diskdev <directory>     Required. Ex: /home\n";	print "\t\t--m                       Modify exisiting entry\n";	print "\t\t[--dumptype <dumptype>    Default: user-tar]\n";        print "\t\t[--includefile <string>   glob expression of file(s) to include]\n";	print "\t\t[--includelist <file>     file contains glob expressions to include]\n";	print "\t\t[ specify either --includefile or --includelist ]\n";	print "\t\t[--excludefile <string>   glob expression of file(s) to exclude]\n";	print "\t\t[--excludelist <file>     file contains glob expressions to exclude]\n";	print "\t\t[ specify either --excludefile or --excludelist ]\n";	print "\t\t[--user <username>          name of user running amrecover on the client]\n";	print "\t\t[--auth <string>            authentication used when running amrecover]\n";	print "\t\t[--gnutar_list_dir <string> directory where gnutar keep its state file on the client]\n";	print "\t\t[--amandates <string>       file where amanda keep the date of dumplevel on the client]\n";	print "\t\t[--batch                    batch mode used when copying file to client]\n";	print "\t\t[--no-client-update         do not update files on the client";        print "\t\t[--help]\n";}sub mprint {    for $fh ( STDOUT, LOG ) {	print $fh @_;    }}sub log_and_die {    print LOG @_;    die @_;}sub is_user_right {    my $user = `whoami`;    chomp($user);    ( $user eq $amanda_user ) ||	die ("ERROR: $0 must be run by $amanda_user\n");}# alphabetics, numerics, and underscores, # hyphen, at sign, dot and "/" are oksub is_tainted {  local($arg) = @_; if ( $arg  =~ /^([-\@\/\w.]+)$/ ) {        return 0; # ok    } else {        return 1; # bad, tainted input    }}# modify existing entry. # only got here if -m is used and entry is found.sub dle_mod {    my $open_seen=0;     # '{' is seen    my $include_done=0;  # original include line is parsed    my $exclude_done=0;  # original exclude line is parsed    my $ok=0;            # 1 if target entry is found    @ARGV = ("$confdir/$config/disklist");    $^I = ".tmp"; # allow inplace editing    while (<>) {	my ($one, $two, $three ) = split(/\s+/, $_);	# if include or exclude is not previously there, 	# take care of them here	if ( $one eq "}" ) {	    $open_seen=0;		if ( $include_done==0 && $ok ) {		   print "include list \"$includelist\"\n" if ( $includelist );		   print "include file \"$includefile\"\n" if ( $includefile );		    }		if ( $exclude_done==0 && $ok ) {		   print "exclude list \"$excludelist\"\n" if ( $excludelist );		   print "exclude file \"$excludefile\"\n" if ( $excludefile );		    }	    $ok=0; # reset, done with one entry	}   		# take care of entry that has '{'	if ( $open_seen==1 ) {	    if ( !$two  && !$three ) {   # inside {, dumptype line has 1 field only		s/$one/$dumptype/ if ( $dumptype );	    } elsif ( $two && $three ) { # inside {, include/exclude line		if ( $one eq "include" ) {		    if ( $includelist ) {			s/$two.*$/list "$includelist"/;		    } elsif ( $includefile ) {			s/$two.*$/file "$includefile"/;		    }		    $include_done=1;		}		if ( $one eq "exclude" ) {		    if ( $excludelist ) {			s/$two.*$/list "$excludelist"/;		    } elsif ( $excludefile ) {			s/$two.*$/file "$excludefile"/;		    }		    $exclude_done=1;		}	    }	}  # inside '{'		# entry which previously doesn't have include/exclude	if (( $one eq $client ) && ($two eq $diskdev) ) {	    $ok=1;	    if ( $three && ($three ne "{") ) {		if ( $sp_diskfile==1 ) {  #previously don't have include/exclude		    $three = $dumptype if ( $dumptype );		    $includeline="include list \"$includelist\""   if ( $includelist );		    $includeline="include file \"$includefile\""   if ( $includefile );		    $excludeline="exclude list \"$excludelist\"\n" if ( $excludelist );		    $excludeline="exclude file \"$excludefile\"\n" if ( $excludefile );		    s/$three/{\n$three\n$includeline\n$excludeline}/;		} else {		    s/$three/$dumptype/ if ( $dumptype ); #easy one, just replace dumptype.		    $ok=0; #done with one entry		}	    } else {		$open_seen=1;	    }	}	print;    }  # while loop    unlink("$confdir/$config/disklist.tmp");    exit 0;}    #mainmy $ret=0;          $ret= GetOptions (      "config=s"=>\$config,                        "client=s"=>\$client,                        "diskdev=s"=>\$diskdev,                        "dumptype=s"=>\$dumptype,                        "includefile=s"=>\$includefile,                        "includelist=s"=>\$includelist,                        "excludefile=s"=>\$excludefile,                        "excludelist=s"=>\$excludelist,			"user=s"=>\$root_user,			"auth=s"=>\$auth,			"gnutar_list_dir=s"=>\$tarlist,			"amandates=s"=>\$amandates,			"batch!"=>\$batch,			"m!"=>\$mod,			"no-client-update!"=>\$no_client_update,                        "help!"=>\$help			);unless ( $ret ) {    &usage;    exit 1;}if($help) {    &usage;    exit 0;}unless (defined $config && defined $client && defined $diskdev ) {    print STDERR "--config, --client and --diskdev are required.\n";    &usage;    exit 1;}else {    die ("ERROR: Invalid data in config.\n")  if is_tainted($config);    die ("ERROR: Invalid data in client.\n")  if is_tainted($client);}if ( defined $includefile && defined $includelist ) {    print STDERR "Specify either --includefile or --includelist, not both.\n";    &usage;    exit 1;}   if ( defined $excludefile && defined $excludelist ) {    print STDERR "Specify either --excludefile or --excludelist, not both.\n";    &usage;    exit 1;}   $oldPATH = $ENV{'PATH'};$ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin:/usr/ucb"; # force known path$date=`date +%Y%m%d%H%M%S`;chomp($date);my $logfile="$tmpdir/amaddclient.$date.debug";&is_user_right;open (LOG, ">$logfile") || die "ERROR: Cannot create logfile : $!\n";print STDOUT "Logging to $logfile\n";my $lhost=`hostname`;

⌨️ 快捷键说明

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