[slbackup-commit] CVS update: slbackup/src SLBackup.pm slbackup-cron

werner-guest@alioth.debian.org werner-guest@alioth.debian.org
Tue, 07 Dec 2004 08:27:30 -0700


  User: werner-guest
  Date: 04/12/07 08:27:30

  Modified:    src      SLBackup.pm slbackup-cron
  Log:
  more-than-one-patch-commit (living without net)
  
  Revision  Changes    Path
  1.3       +7 -2      slbackup/src/SLBackup.pm
  
  Index: SLBackup.pm
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup/src/SLBackup.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SLBackup.pm	28 Nov 2004 19:50:00 -0000	1.2
  +++ SLBackup.pm	7 Dec 2004 15:27:30 -0000	1.3
  @@ -62,7 +62,7 @@
   #  -1: failed reading $dir
   #  -2: one or more of the script failed while executing
   sub run_scripts {
  -    my ($dir, $logfile) = @_;
  +    my ($dir, $logfile, $debug) = @_;
   
       open (LOG, ">>$logfile") or die ("Unable to open $logfile\n");
       logger ("Start running executables in $dir.");
  @@ -85,6 +85,11 @@
   	if ( -x $script ) {
   	    my $output = `$script 2>&1`;
   	    my $retval = $?;
  +	    if ($debug) {
  +		logger ("Debug-output from $script:\n $output\n" .
  +			"Debug-output from $script ended.");
  +	    }
  +
   	    if ( $retval eq 0) {
   		logger ("Successfully run $script: \n$output");
   	    } elsif ( $retval ne 0 ) {
  
  
  
  1.12      +94 -19    slbackup/src/slbackup-cron
  
  Index: slbackup-cron
  ===================================================================
  RCS file: /cvsroot/slbackup/slbackup/src/slbackup-cron,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- slbackup-cron	28 Nov 2004 19:50:01 -0000	1.11
  +++ slbackup-cron	7 Dec 2004 15:27:30 -0000	1.12
  @@ -1,28 +1,88 @@
   #!/usr/bin/perl
   #
  -# Script to be run by cron each night to backup locations specified in
  -# /etc/slbackup/slbackup.conf
  +# Script to be run by cron each night (or whatever) to backup locations
  +# specified in the configuration file (/etc/slbackup/slbackup.conf by default).
   #
   # $Id$
   #
   
  -use strict;
  +#use strict; # failed with the getopt's
   use Config::General;
   use POSIX qw(strftime);
   use Net::DNS;
   use SLBackup;
   
  -my $logfile = "/var/log/slbackup/slbackup.log";
  -my $scripts_predir = "/etc/slbackup/pre.d";
  -my $scripts_postdir = "/etc/slbackup/post.d";
  -my $scripts_logfile = "/var/log/slbackup/run_scripts.log";
  +
  +sub usage() {
  +    print  <<_EOUSAGE_;
  +Usage: $0 [-c <file>] [-o <logfile> ] [-r <predir>] [-o <postdir>]
  +          [-s <scriptlog>]
  +    -c <conffile>   Name and location of the configurationfile (default is
  +                    /etc/slbackup/slbackup.conf).
  +    -l <logfile>    Name and location for the logfile (default is
  +                    /var/log/slbackup/slbackup.log).
  +    -r <predir>     Name and location of the directory that contains
  +                    the scripts that shall run before the backup session
  +                    starts (default is /etc/slbackup/pre.d/).
  +    -o <postdir>    Name and location of the directory that contains
  +                    the scripts that shall run after the backup session
  +                    has finished (default is /etc/slbackup/post.d/).
  +    -s <scriptlog>  Name and location of the logfile pre- and
  +                    post-scripts (default is 
  +                    /var/log/slbackup/run_scripts.log).
  +    -h              Display this usage-info.
  +    -v              Verbose output to the logfile(s).
  +_EOUSAGE_
  +    exit 0;
  +}
  +
  +## handle commandline options
  +# thanks to /usr/share/vim/vim63/tools/shtags.pl :)
  +
  +# initialization
  +my $program;
  +$program = $0 =~ s,.*/,,;
  +require 'getopts.pl';
  +
  +# parse commandline
  +&Getopts ("c:l:r:o:s:hv") || &usage();
  +my $conffile = $opt_c || "/etc/slbackup/slbackup.conf";
  +my $logfile = $opt_l || "/var/log/slbackup/slbackup.log";
  +my $scripts_predir = $opt_r || "/etc/slbackup/pre.d";
  +my $scripts_postdir = $opt_o || "/etc/slbackup/post.d";
  +my $scripts_logfile = $opt_s || "/var/log/slbackup/run_scripts.log";
  +my $debug = 1 if $opt_v;
  +my $debug = 0 if ! $opt_v;
  +&usage() if $opt_h;
  +
  +
  +# debug-output
  +if ($debug) {
  +    logger ("Debug-output:" .
  +	    "  conffile        : $conffile" .
  +	    "  logfile         : $logfile" .
  +	    "  scripts_predir  : $scripts_predir" .
  +	    "  scripts_postdir : $scripts_postdir" .
  +	    "  scripts_logfile : $scripts_logfile" .
  +	    "End debug-output.");
  +}
   
   # open logfile
   open (LOG, ">>$logfile") or die ("Unable to open $logfile\n");
   logger ("Starting slbackup:");
   
  +# fetch configuration
  +if (-r $conffile) {
  +    my $config = &slbackup_readconfig($conffile);
  +} else {
  +    logger ("Unable to read config file ($conffile), exiting.");
  +    logger ("Finished slbackup.");
  +    close (LOG);
  +    dir ("Unable to open config file ($conffile), \nexiting ");
  +}
  +
   # run executables in $scripts_predir
  -my $retval_predir = &run_scripts($scripts_predir, $scripts_logfile);
  +my $retval_predir = &run_scripts($scripts_predir, $scripts_logfile, $debug);
   if ( $retval_predir eq 1 ) {
       logger ("Successfully running scripts in $scripts_predir.");
   } elsif ( $retval_predir eq -1 ) {
  @@ -34,10 +94,6 @@
   	    "$scripts_predir");
   }    
   
  -# fetch configuration
  -my $conffile = '/etc/slbackup/slbackup.conf';
  -my $config = &slbackup_readconfig($conffile);
  -
   # run rdiff-backup for each client in configuration
   for my $key (keys %{$config->{client}}) {
       my $client = $config->{client}->{$key};
  @@ -59,16 +115,14 @@
   	}
   	
   	# check if server_address is valid:
  -	if (!$config->{server_address} =~ '^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$')
  -	{
  +	if (!$config->{server_address} =~ '^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$') {
   	    # server_address doesn't seem to be an IP...
   	    # let's try to look up the host's addresses:
   	    
   	    my $dns_res   = Net::DNS::Resolver->new;
   	    my $query = $dns_res->search($config->{server_address});
   	    
  -	    if (!$query)
  -	    {
  +	    if (!$query) {
   		logger ("Couldn't resolve host " .
   			"\'$config->{server_address}\' ");
   		logger ("Failed backing up clients.");
  @@ -103,11 +157,32 @@
   	    logger ("Failed backing up clients.");
   	    last;
   	}
  -	
  +
  +	# test that the destination dir exists
  +	my $testcondition = "test -d $config->{server_destdir} " .
  +	    "&& echo -n ok";
  +	$sshteststr = "ssh $config->{server_user}" . "@" . 
  +		"$config->{server_address} '$testcondition'";
  +	if (`$sshteststr` ne `echo -n ok`) {
  +	    logger ("Destination directory (server_destdir) does not seem \n" . 
  +		    "to exist on the backup server... please fix!");
  +	    logger ("Failed backing up clients.");
  +	    last;
  +	}
  +
   	# the server-part of the configuration shall be ok, so
   	# build server-part of execstr and continue
   	$execstr_serverpart = 
   	    "$config->{server_user}\@$config->{server_address}::";
  +    } else {
  +	# the server is the localhost, then checking that the destination
  +	# directory exists
  +	if (! -d $config->{server_destdir}) {
  +	    logger ("Destination directory (server_destdir) does not seem \n" . 
  +		    "to exist on the backup server... please fix!");
  +	    logger ("Failed backing up clients.");
  +	    last;
  +	}
       }
   
       # check if destination directory on backup server is represented in
  @@ -296,7 +371,7 @@
   }
   
   # run executables in $scripts_postdir
  -my $retval_postdir = &run_scripts($scripts_postdir, $scripts_logfile);
  +my $retval_postdir = &run_scripts($scripts_postdir, $scripts_logfile, $debug);
   if ( $retval_postdir eq 1 ) {
       logger ("Successfully running of scripts in $scripts_postdir.");
   } elsif ( $retval_postdir eq -1 ) {