--- smeserver-affa-0.9.0/root/sbin/e-smith/affa.createBackupFileOption 2008-03-07 18:41:40.000000000 +0100 +++ smeserver-affa-0.9.0/root/sbin/e-smith/affa 2008-03-07 18:41:40.000000000 +0100 @@ -29,6 +29,7 @@ use esmith::DB::db; use esmith::templates; use File::Path; +use Cwd; use Filesys::DiskFree; use Getopt::Long; use Mail::Send; @@ -37,11 +38,11 @@ $ENV{LANG} = "en_US"; # Filesys::DiskFree only works with english LANG setting -my $VERSION='_VERSIONSTRING_'; +my $VERSION='0.9.0-5'; # sub prototypes -sub affaErrorExit( $$ ); +sub affaErrorExit($); sub affaExit($); sub checkArchiveExists($$$); sub checkConnection(); @@ -50,6 +51,7 @@ sub cleanup(); sub compareRPMLists($); sub countUnit($); +sub createBackupFile(); sub cronSetup(); sub dbg($); sub deleteJob(); @@ -115,10 +117,9 @@ sub unmount($$); sub updateReportDB(); - +my $cwd=getcwd; chdir "/tmp"; - my $defaultEmail='admin'; my $rsyncLocal = '/usr/bin/rsync'; my $rsyncRemote = '/usr/bin/rsync'; @@ -181,7 +182,8 @@ "backup"=>\$opts{'run'}, # same as --run "version"=>\$opts{'version'}, "help"=>\$opts{'help'}, - "jobs"=>\$opts{'jobs'}, + "_shorthelp"=>\$opts{'shorthelp'}, + "_jobs"=>\$opts{'jobs'}, "make-cronjobs"=>\$opts{'make-cronjobs'}, "list-archives"=>\$opts{'list-archives'}, "csv"=>\$opts{'csv'}, @@ -191,6 +193,8 @@ "send-keys"=>\$opts{'send-keys'}, "revoke-keys"=>\$opts{'revoke-keys'}, "check-connections"=>\$opts{'check-connections'}, + "create-backup-file"=>\$opts{'create-backup-file'}, + "outfile=s"=>\$opts{'outfile'}, "host=s"=>\$opts{'keys-host'}, "remoteOS=s"=>\$opts{'remoteOS'}, "port=s"=>\$opts{'keys-port'}, @@ -211,12 +215,6 @@ my $remoteOS; -if( not $getRes ) - { - showHelp(1); - affaErrorExit( 117, "Missing arguments"); - } - my %job; getDefaultConfig(); @@ -235,6 +233,11 @@ listJobs(); exit 0; } +if( $opts{'shorthelp'} ) + { + showHelp(1); + exit 0; + } lg( $runninglog ); @@ -315,6 +318,11 @@ checkConnectionsAll(); affaExit('Done.'); } +elsif( $opts{'create-backup-file'} ) + { + createBackupFile(); + affaExit('Done.'); + } elsif( $opts{'kill'} ) { $jobname = 'kill'; @@ -334,14 +342,14 @@ affaExit('Done.'); } - if ( not $opts{'run'} or not $ARGV[0] ) { showHelp(1); - affaErrorExit( 137, "Missing arguments"); + affaErrorExit( "Missing arguments"); } + # run job $jobname = $ARGV[0]; @@ -349,14 +357,14 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 140, "$txt" ); + affaErrorExit( "$txt" ); } $Command = defined $ARGV[1] ? lc($ARGV[1]) : 'scheduled'; $Command =~ /([a-z]*)/i; $Command = $1; # untaint if( not $Command =~ /^(scheduled|daily|weekly|monthly|yearly)$/ ) { - affaErrorExit( 100, "Unkown command '$Command'"); + affaErrorExit( "Unkown command '$Command'"); } getJobConfig( $jobname ); @@ -368,7 +376,7 @@ # check if same job already running $Command eq "scheduled" and getLock($lockfile) - and affaErrorExit( 101, "Lock found. Another job (pid=" . getLock($lockfile) . ") is still running." ); + and affaErrorExit( "Lock found. Another job (pid=" . getLock($lockfile) . ") is still running." ); setLock() if $Command eq "scheduled"; $SIG{'TERM'} = 'SignalHandler'; @@ -525,7 +533,7 @@ } else { - affaErrorExit( 102, "rsync failed with status $status."); + affaErrorExit( "rsync failed with status $status."); } } @@ -614,7 +622,7 @@ } else { - affaErrorExit( 103, "Job '$jobname' undefined."); + affaErrorExit( "Job '$jobname' undefined."); } $job{'sshPort'}=22 if not $job{'sshPort'}; $job{'EmailAddresses'}=$defaultEmail if not $job{'EmailAddresses'}; @@ -757,13 +765,13 @@ { lg( "Checking rsyncd connection to " . $job{'remoteHostName'} ); @cmd=($rsyncLocal, '-dq', ($job{'rsyncdUser'} ? $job{'rsyncdUser'}.'@' : '') . $job{'remoteHostName'} . "::'" . $job{'rsyncdModule'} . "'"); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 104, "Rsyncd connection to ". $job{'remoteHostName'}. " failed. Did you set the rsyncdUser, rsyncdPassword and rsyncdModule properties correctly?" ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Rsyncd connection to ". $job{'remoteHostName'}. " failed. Did you set the rsyncdUser, rsyncdPassword and rsyncdModule properties correctly?" ); } else { lg( "Checking SSH connection to " . $job{'remoteHostName'} ); @cmd=('/usr/bin/ssh', '-p', $job{'sshPort'}, '-o', 'StrictHostKeyChecking=yes', '-o', "HostKeyAlias=$jobname", '-o', "ConnectTimeout=$job{'ConnectionCheckTimeout'}",'-o','PasswordAuthentication=no', $sshQuiet, $job{'remoteHostName'},'true'); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 104, "SSH connection to ". $job{'remoteHostName'}. " failed. Did you send the public key?" ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "SSH connection to ". $job{'remoteHostName'}. " failed. Did you send the public key?" ); } } @@ -781,7 +789,7 @@ lg( "signaling pre-backup event on ". $job{'remoteHostName'} ); @cmd=('/usr/bin/ssh', '-o', "HostKeyAlias=$jobname", '-p', $job{'sshPort'}, $sshQuiet, $job{'remoteHostName'},"/sbin/e-smith/signal-event pre-backup desktop"); } - not ExecCmd( @cmd, 0 ) or affaErrorExit( 105, "signaling pre-backup event failed." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "signaling pre-backup event failed." ); } sub signalPostBackupEvent() @@ -825,7 +833,7 @@ "'/sbin/e-smith/affa-rpmlist.sh>$rpmlist'" ); } - not ExecCmd( @cmd, 0 ) or affaErrorExit( 107, "writing list of installed RPMs failed." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "writing list of installed RPMs failed." ); } @@ -837,7 +845,7 @@ my $RPMPath="home/e-smith/db/affa-rpmlist"; my %remoteRPM; dbg( "Reading remote RPM list" ); - open( RP, "$localRPMList/$RPMPath" ) or affaErrorExit( 108, "Couldn't open $localRPMList/$RPMPath" ); + open( RP, "$localRPMList/$RPMPath" ) or affaErrorExit( "Couldn't open $localRPMList/$RPMPath" ); while( ) { my @z = split( " ", $_); @@ -876,7 +884,7 @@ dbg("MD5Filename=$MD5Filename"); if( not -f $MD5Filename ) { - open( RP, ">$RPMFilename" ) or affaErrorExit( 109, "Couldn't open $RPMFilename for writing."); + open( RP, ">$RPMFilename" ) or affaErrorExit( "Couldn't open $RPMFilename for writing."); my $out=''; foreach my $k (@missing) @@ -916,7 +924,7 @@ $msg->to($job{'EmailAddresses'}); $msg->set("From", "\"Affa Backup Server\" "); my $fh = $msg->open; - open( RP, "<$RPMFilename" ) or affaErrorExit( 110, "Couldn't open $RPMFilename."); + open( RP, "<$RPMFilename" ) or affaErrorExit( "Couldn't open $RPMFilename."); while( ) { print $fh $_; @@ -927,7 +935,7 @@ } unlink( glob( "$job{'RootDir'}/$jobname/.md5-rpms-missing-*" ) ); - open( RP, ">$MD5Filename" ) or affaErrorExit( 111, "Couldn't open $MD5Filename for writing."); + open( RP, ">$MD5Filename" ) or affaErrorExit( "Couldn't open $MD5Filename for writing."); print RP "md5sum of content of file $RPMFilename\n"; close( RP ); } @@ -1108,7 +1116,7 @@ close( WD ); chmod( 0700, "/usr/lib/affa/$WDName" ); my @cmd=('/usr/bin/ssh', '-o', "HostKeyAlias=$jobname", '-p', $job{'sshPort'}, $job{'remoteHostName'}, "/bin/rm", "-f", "/etc/cron.hourly/$WDName-reminder" ); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 118, "Couldn't delete /etc/cron.hourly/$WDName-reminder on remote host." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't delete /etc/cron.hourly/$WDName-reminder on remote host." ); remoteCopy("/usr/lib/affa/$WDName","/etc/cron.hourly/" ); } @@ -1174,19 +1182,19 @@ { return if not $job{'preJobCommand'}; lg( "Executing preJobCommand $job{'preJobCommand'}"); - affaErrorExit( 113, "Couldn't execute preJobCommand $job{'preJobCommand'}") if not -x $job{'preJobCommand'}; + affaErrorExit( "Couldn't execute preJobCommand $job{'preJobCommand'}") if not -x $job{'preJobCommand'}; my @cmd = ( $job{'preJobCommand'}, $job{'remoteHostName'}, $jobname, $Command ); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 114, "Executing preJobCommand $job{'preJobCommand'} failed." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Executing preJobCommand $job{'preJobCommand'} failed." ); } sub execPostJobCommand($) { return if not $job{'postJobCommand'}; lg( "Executing postJobCommand $job{'postJobCommand'}"); - affaErrorExit( 115, "Couldn't execute postJobCommand $job{'postJobCommand'}") if not -x $job{'postJobCommand'}; + affaErrorExit( "Couldn't execute postJobCommand $job{'postJobCommand'}") if not -x $job{'postJobCommand'}; my @cmd = ( $job{'postJobCommand'}, $job{'remoteHostName'}, $jobname, $Command, shift(@_) ); $job{'postJobCommand'}=''; # don't execute again in affaErrorExit() - not ExecCmd( @cmd, 0 ) or affaErrorExit( 116, "Executing postJobCommand $job{'postJobCommand'} failed." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Executing postJobCommand $job{'postJobCommand'} failed." ); } sub listJobs() @@ -1289,7 +1297,7 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 135, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); updateReportDB(); @@ -1525,7 +1533,7 @@ my $s="Couldn't mount $dev $AutomountPoint"; if( $Command ) { - affaErrorExit( 130, $s ); + affaErrorExit( $s ); } else { @@ -1623,7 +1631,7 @@ my $txt="Error: Archive $archive not found."; print "$txt\n"; lg($txt); $txt = "Run 'affa --list-archives $jobname' to view available archives.\n"; print "$txt\n"; - affaErrorExit( 123, "." ); + affaErrorExit( "." ); } } @@ -1637,7 +1645,7 @@ if( not $affa->get($jobname)||'' ) { $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 136, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); my $dir = opendir( DIR, "$job{'RootDir'}/$jobname" ); @@ -1669,7 +1677,7 @@ chomp( $input ); if( $input ne 'proceed' ) { - affaErrorExit( 146, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } foreach my $k ( reverse sort keys %archives ) { @@ -1688,19 +1696,19 @@ if( not $affa->get($jobname)||'' ) { $txt= "Error: Job '$jobname' undefined."; print("$txt\n"); - affaErrorExit( 147, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); (my $newdir=$ARGV[1])=~s/\/$//; if( not $newdir ) { $txt= "Error: New RootDir not given."; print("$txt\n"); - affaErrorExit( 148, "$txt" ); + affaErrorExit( "$txt" ); } if( not $newdir=~/^\// or $newdir=~/\.\./ ) { $txt= "Error: Full path required for NEWROOTDIR."; print("$txt\n"); - affaErrorExit( 150, "$txt" ); + affaErrorExit( "$txt" ); } if( not -d $newdir ) { @@ -1714,7 +1722,7 @@ if( $input ne 'yes' ) { $interactive=0; - affaErrorExit( 149, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } File::Path::mkpath( $newdir, 0, 0700 ) } @@ -1760,7 +1768,7 @@ if( not $affa->get($jobname)||'' ) { $txt= "Error: Job '$jobname' undefined."; print("$txt\n"); - affaErrorExit( 141, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); my $newname=$ARGV[1]||''; @@ -1768,12 +1776,12 @@ if( not $newname ) { $txt= "Error: No new jobname given."; print("$txt\n"); - affaErrorExit( 142, "$txt" ); + affaErrorExit( "$txt" ); } if( $affa->get($newname) ) { $txt= "Error: A job 'mars' already exists."; print("$txt\n"); - affaErrorExit( 143, "$txt" ); + affaErrorExit( "$txt" ); } if( -f "/home/e-smith/db/affa-report/$jobname" ) { @@ -1821,7 +1829,7 @@ if( not $affa->get($jobname)||'' ) { $txt= "Error: Job '$jobname' undefined."; print("$txt\n"); - affaErrorExit( 144, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); my $dir = opendir( DIR, "$job{'RootDir'}/$jobname" ); @@ -1846,7 +1854,7 @@ chomp( $input ); if( $input ne 'proceed' ) { - affaErrorExit( 133, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } revokeKeys($jobname) if $opts{'revoke-keys'}; if( $dir ) @@ -1883,7 +1891,7 @@ if( not $affa->get($jobname)||'' ) { $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 145, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); @@ -1896,7 +1904,7 @@ if( getLock("$lockdir/$jobname") ) { print "Job '$jobname' is running. Wait for completion. Then run affa --full-restore again.\n"; - affaErrorExit( 131, "affa job 'jobname' is running." ); + affaErrorExit( "affa job 'jobname' is running." ); } # check if archive exists @@ -1917,7 +1925,7 @@ if( $input ne 'proceed' ) { $interactive=0; - affaErrorExit( 132, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } $txt="Signaling pre-restore event on $job{'remoteHostName'}"; lg( $txt ); print "$txt\n"; @@ -2004,7 +2012,7 @@ lg( $txt ); print "$txt\n"; $txt="Try option --full-restore instead."; lg( $txt ); print "$txt\n"; - affaErrorExit( 134, "Cannot rise from my own backup." ); + affaErrorExit( "Cannot rise from my own backup." ); } @@ -2036,7 +2044,7 @@ if( not $interactive ) { print "Wait for completion of the running jobs or kill them. Then run affa --rise again.\n"; - affaErrorExit( 124, "affa jobs are running." ); + affaErrorExit( "affa jobs are running." ); } stopServices(); @@ -2074,7 +2082,7 @@ if( $input ne 'proceed' ) { $interactive=0; - affaErrorExit( 128, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } print "Signaling pre-restore event\n"; @@ -2097,7 +2105,7 @@ # This allows us to run the --rise option remotely and connect to the restored server my $srcconfigPath="/var/affa/$ServerBasename/scheduled.0/home/e-smith/db/configuration"; my $srcconfig = esmith::ConfigDB->open_ro($srcconfigPath) - or affaErrorExit( 126, "Couldn't open source config db $srcconfigPath"); + or affaErrorExit( "Couldn't open source config db $srcconfigPath"); $config->set_prop("EthernetDriver1","type", $srcconfig->get("EthernetDriver1")->value); $config->set_prop("EthernetDriver2","type", $srcconfig->get("EthernetDriver2")->value); $config->set_prop("InternalInterface","Driver", $srcconfig->get_prop("InternalInterface","Driver")); @@ -2116,7 +2124,7 @@ $interactive=1; # search server base backup my $dir = opendir( DIR, "/var/affa/" ); - affaErrorExit( 125, "Couldn't open directory /var/affa/" ) if not $dir; + affaErrorExit( "Couldn't open directory /var/affa/" ) if not $dir; my $archive; my $a=''; while( defined ($archive=readdir(DIR)) ) @@ -2124,7 +2132,7 @@ next if not $archive =~ /AFFA\.[a-z][a-z0-9\-]*\..*-\d*\.\d*\.\d*\.\d*/; $a=$archive; } - affaErrorExit( 127, "No server base backup found." ) if not $a and not -f "$a/scheduled.0"; + affaErrorExit( "No server base backup found." ) if not $a and not -f "$a/scheduled.0"; stopServices(); print "\nWARNING: You will loose all data of your current server installation!\n"; my $input=''; @@ -2137,7 +2145,7 @@ if( $input ne 'proceed' ) { $interactive=0; - affaErrorExit( 122, "Terminated by user" ) if $input ne 'proceed'; + affaErrorExit( "Terminated by user" ) if $input ne 'proceed'; } print "Signaling pre-restore event\n"; @@ -2262,7 +2270,7 @@ $me->set_prop($p,$v); } my @cmd=('/sbin/e-smith/affa','--run', $ServerBasename); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 121, "Couldn't backup myself" ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't backup myself" ); print "Done.\n"; } @@ -2303,7 +2311,7 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 139, "$txt" ); + affaErrorExit( "$txt" ); } $HostKeyAliasOption="-o HostKeyAlias=$jobname"; getJobConfig($jobname); @@ -2318,11 +2326,11 @@ $s="Generating DSA keys..."; print "$s\n"; lg($s); @cmd=("/usr/bin/ssh-keygen",$sshQuiet,"-t","dsa","-N ''","-f", "/root/.ssh/id_dsa" ); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 119, "Couldn't generate DSA keys" ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't generate DSA keys" ); $s="Successfully created DSA key pair."; print "$s\n"; lg($s); } - open( PUBK, $kf ) or affaErrorExit( 156, "Could not open $kf" ); + open( PUBK, $kf ) or affaErrorExit( "Could not open $kf" ); my $pubk=trim(); close( PUBK ); my $cmd; @@ -2365,7 +2373,7 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 153, "$txt" ); + affaErrorExit( "$txt" ); } $HostKeyAliasOption="-o HostKeyAlias=$jobname"; getJobConfig($jobname); @@ -2373,7 +2381,7 @@ $port = $job{'sshPort'} ? $job{'sshPort'} : 22; } - open( PUBK, $kf ) or affaErrorExit( 154, "Could not open $kf" ); + open( PUBK, $kf ) or affaErrorExit( "Could not open $kf" ); my $pubk=trim(); close( PUBK ); @@ -2397,7 +2405,7 @@ { $s="Deleting public key on $remotehost failed."; print "$s\n"; - affaErrorExit( 155, $s ); + affaErrorExit( $s ); } $s="Public key deleted on $remotehost"; print "$s\n"; lg($s); @@ -2433,6 +2441,80 @@ } } + +sub createBackupFile() + { + my $jobname=$ARGV[0]||''; + my $archive=$ARGV[1]||'scheduled.0'; + my $txt; + + if( not $affa->get($jobname)||'' ) + { + $txt= "Job '$jobname' undefined"; print("Error: $txt\n"); + affaErrorExit( "$txt" ); + } + getJobConfig( $jobname ); + + if( $job{'AutomountDevice'} and $job{'AutomountPoint'} ) + { + mount( $job{'AutomountDevice'}, $job{'AutomountPoint'}, $job{'AutomountOptions'} ); + } + + # check if a job is running + if( getLock("$lockdir/$jobname") ) + { + print "Job '$jobname' is running. Wait for completion. Then run affa --create-backup-file again.\n"; + affaErrorExit( "affa job 'jobname' is running." ); + } + + # check if archive exists + checkArchiveExists($job{'RootDir'},$jobname,$archive); + + my $outfile=$opts{'outfile'}; + $outfile=$cwd if not $outfile; + $outfile .= '/smeserver.tgz' if -d $outfile; + + if( -f $outfile ) + { + $txt= "File $outfile already exists."; print("Error: $txt\n"); + affaErrorExit( "$txt" ); + } + + unless ( open( OUT, ">$outfile" ) ) + { + $txt= "Could not open $outfile for writing."; print("Error: $txt\n"); + affaErrorExit( "$txt" ); + } + close( OUT ); + unlink( $outfile ); + + my $affastatus = esmith::DB::db->open("/home/e-smith/db/affa-report/$jobname"); + my $size=$affastatus->get_prop( $archive, 'TotalFileSize' ) || 0; + $size =~ s/(\d*).*/$1/; + my $f; + my $restore_list=''; + my $dir = opendir( DIR, "$job{'RootDir'}/$jobname/$archive" ); + while( defined ($f=readdir(DIR)) ) + { + next if $f =~ /^(.AFFA-REPORT|$jobname-setup.pl|\.|\.\.)$/; + $restore_list.="$f "; + } + close(DIR); + my @cmd=('/bin/tar', '-C', "$job{'RootDir'}/$jobname/$archive/", '-cf - ', $restore_list, + '|', '/usr/bin/pv -i 0.3', "-s $size", + '|', '/bin/gzip', + "> $outfile" + ); + my $status=ExecCmd( @cmd, 0 ); + if( $status!=0 ) + { + unlink( $outfile ); + $txt= "Could not create $outfile."; print("Error: $txt\n"); + affaErrorExit( "$txt" ); + } + $txt="Backup file '$outfile' created."; print("$txt\n"); lg( $txt); + } + sub showSchedule() { my $res=$opts{15} ? 15 : 30; @@ -2523,7 +2605,7 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 138, "$txt" ); + affaErrorExit( "$txt" ); } getJobConfig( $jobname ); my $msg = new Mail::Send; @@ -2564,7 +2646,7 @@ chmod( 0700, "/usr/lib/affa/$WDName" ); remoteCopy("/usr/lib/affa/$WDName", "/tmp/"); my @cmd=('/usr/bin/ssh', '-p', $job{'sshPort'}, '-o', "HostKeyAlias=$jobname", $sshQuiet, $job{'remoteHostName'},"/tmp/$WDName"); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 152, "Couldn't run /usr/lib/affa/$WDName on remote host." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't run /usr/lib/affa/$WDName on remote host." ); } sub trim($) @@ -2764,7 +2846,7 @@ "--rsync-path='$rsyncRemote'", "--rsh='/usr/bin/ssh -o HostKeyAlias=$jobname -p $job{'sshPort'}'", $src, $job{'remoteHostName'}.":$dst" ); - not ExecCmd( @cmd, 0 ) or affaErrorExit( 151, "Couldn't copy $src to remote host." ); + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't copy $src to remote host." ); } sub showVersion() @@ -2808,6 +2890,7 @@ print " or affa --revoke-key JOB\n"; print " or affa --revoke-key --host=TARGETHOST [--port=PORT] [--remoteOS=cygwin]\n"; print " or affa --check-connections\n"; + print " or affa --create-backup-file JOB [ARCHIVE] [--outfile=FILE]\n"; print " or affa --kill JOB\n"; print " or affa --version\n"; print " or affa --help\n"; @@ -2831,7 +2914,7 @@ if( not $affa->get($jobname)||'' ) { my $txt= "Error: Job '$jobname' undefined"; print("$txt\n"); - affaErrorExit( 157, "$txt" ); + affaErrorExit( "$txt" ); } my $pid=getLock("$lockdir/$jobname"); if( $pid ) @@ -2857,7 +2940,7 @@ lg("$Command run killed"); if( $Command eq "scheduled" ) { - affaErrorExit( 1, "Caught interrupt signal $sig"); + affaErrorExit( "Caught interrupt signal $sig"); } else { @@ -2866,13 +2949,15 @@ } } -sub affaErrorExit( $$ ) +sub affaErrorExit($) { - (my $err, my $msg) = @_; + (my $msg) = @_; + my $err=(caller)[2]; + my $sub=(caller(1))[3]||''; lg( "Error $err: $msg" ); print "Error $err: $msg\n" if $interactive==1; emptyTrash() if $Command eq "scheduled"; - execPostJobCommand($err) if $err != 115; + execPostJobCommand($err) if $sub ne 'main::execPostJobCommand'; unmountAll(); sendErrorMesssage(); removeLock(); --- smeserver-affa-0.9.0/root/etc/profile.d/affa.sh.createBackupFileOption 2008-01-18 16:50:15.000000000 +0100 +++ smeserver-affa-0.9.0/root/etc/profile.d/affa.sh 2008-03-07 19:40:21.000000000 +0100 @@ -4,13 +4,13 @@ case $COMP_CWORD in # option 1) - COMPREPLY=( $(/sbin/e-smith/affa | grep " affa $cur"|awk '{print $3}' ) ) + COMPREPLY=( $(/sbin/e-smith/affa --_shorthelp | grep " affa $cur"|awk '{print $3}' ) ) ;; # job 2) - /sbin/e-smith/affa --help | grep -qs -- "${COMP_WORDS[1]}.*JOB" + /sbin/e-smith/affa --_shorthelp | grep -qs -- "${COMP_WORDS[1]}.*JOB" if [ "$?" == 0 ] ; then - COMPREPLY=( $(/sbin/e-smith/affa --jobs | grep "^$cur" ) ) + COMPREPLY=( $(/sbin/e-smith/affa --_jobs | grep "^$cur" ) ) fi ;; esac