/[smecontribs]/rpms/smeserver-affa/contribs7/smeserver-affa-0.9.0-createBackupFileOption.patch
ViewVC logotype

Annotation of /rpms/smeserver-affa/contribs7/smeserver-affa-0.9.0-createBackupFileOption.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Mon Mar 10 20:29:34 2008 UTC (16 years, 4 months ago) by slords
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
Import on branch contribs7 of package smeserver-affa-0.10.0-0.el4.sme.src.rpm

1 mweinber 1.1 --- smeserver-affa-0.9.0/root/sbin/e-smith/affa.createBackupFileOption 2008-03-07 18:41:40.000000000 +0100
2     +++ smeserver-affa-0.9.0/root/sbin/e-smith/affa 2008-03-07 18:41:40.000000000 +0100
3     @@ -29,6 +29,7 @@
4     use esmith::DB::db;
5     use esmith::templates;
6     use File::Path;
7     +use Cwd;
8     use Filesys::DiskFree;
9     use Getopt::Long;
10     use Mail::Send;
11     @@ -37,11 +38,11 @@
12    
13     $ENV{LANG} = "en_US"; # Filesys::DiskFree only works with english LANG setting
14    
15     -my $VERSION='_VERSIONSTRING_';
16     +my $VERSION='0.9.0-5';
17    
18    
19     # sub prototypes
20     -sub affaErrorExit( $$ );
21     +sub affaErrorExit($);
22     sub affaExit($);
23     sub checkArchiveExists($$$);
24     sub checkConnection();
25     @@ -50,6 +51,7 @@
26     sub cleanup();
27     sub compareRPMLists($);
28     sub countUnit($);
29     +sub createBackupFile();
30     sub cronSetup();
31     sub dbg($);
32     sub deleteJob();
33     @@ -115,10 +117,9 @@
34     sub unmount($$);
35     sub updateReportDB();
36    
37     -
38     +my $cwd=getcwd;
39     chdir "/tmp";
40    
41     -
42     my $defaultEmail='admin';
43     my $rsyncLocal = '/usr/bin/rsync';
44     my $rsyncRemote = '/usr/bin/rsync';
45     @@ -181,7 +182,8 @@
46     "backup"=>\$opts{'run'}, # same as --run
47     "version"=>\$opts{'version'},
48     "help"=>\$opts{'help'},
49     - "jobs"=>\$opts{'jobs'},
50     + "_shorthelp"=>\$opts{'shorthelp'},
51     + "_jobs"=>\$opts{'jobs'},
52     "make-cronjobs"=>\$opts{'make-cronjobs'},
53     "list-archives"=>\$opts{'list-archives'},
54     "csv"=>\$opts{'csv'},
55     @@ -191,6 +193,8 @@
56     "send-keys"=>\$opts{'send-keys'},
57     "revoke-keys"=>\$opts{'revoke-keys'},
58     "check-connections"=>\$opts{'check-connections'},
59     + "create-backup-file"=>\$opts{'create-backup-file'},
60     + "outfile=s"=>\$opts{'outfile'},
61     "host=s"=>\$opts{'keys-host'},
62     "remoteOS=s"=>\$opts{'remoteOS'},
63     "port=s"=>\$opts{'keys-port'},
64     @@ -211,12 +215,6 @@
65     my $remoteOS;
66    
67    
68     -if( not $getRes )
69     - {
70     - showHelp(1);
71     - affaErrorExit( 117, "Missing arguments");
72     - }
73     -
74     my %job;
75     getDefaultConfig();
76    
77     @@ -235,6 +233,11 @@
78     listJobs();
79     exit 0;
80     }
81     +if( $opts{'shorthelp'} )
82     + {
83     + showHelp(1);
84     + exit 0;
85     + }
86    
87     lg( $runninglog );
88    
89     @@ -315,6 +318,11 @@
90     checkConnectionsAll();
91     affaExit('Done.');
92     }
93     +elsif( $opts{'create-backup-file'} )
94     + {
95     + createBackupFile();
96     + affaExit('Done.');
97     + }
98     elsif( $opts{'kill'} )
99     {
100     $jobname = 'kill';
101     @@ -334,14 +342,14 @@
102     affaExit('Done.');
103     }
104    
105     -
106     if ( not $opts{'run'} or not $ARGV[0] )
107     {
108     showHelp(1);
109     - affaErrorExit( 137, "Missing arguments");
110     + affaErrorExit( "Missing arguments");
111     }
112    
113    
114     +
115     # run job
116    
117     $jobname = $ARGV[0];
118     @@ -349,14 +357,14 @@
119     if( not $affa->get($jobname)||'' )
120     {
121     my $txt= "Job '$jobname' undefined"; print("$txt\n");
122     - affaErrorExit( 140, "$txt" );
123     + affaErrorExit( "$txt" );
124     }
125    
126     $Command = defined $ARGV[1] ? lc($ARGV[1]) : 'scheduled';
127     $Command =~ /([a-z]*)/i; $Command = $1; # untaint
128     if( not $Command =~ /^(scheduled|daily|weekly|monthly|yearly)$/ )
129     {
130     - affaErrorExit( 100, "Unkown command '$Command'");
131     + affaErrorExit( "Unkown command '$Command'");
132     }
133    
134     getJobConfig( $jobname );
135     @@ -368,7 +376,7 @@
136    
137     # check if same job already running
138     $Command eq "scheduled" and getLock($lockfile)
139     - and affaErrorExit( 101, "Lock found. Another job (pid=" . getLock($lockfile) . ") is still running." );
140     + and affaErrorExit( "Lock found. Another job (pid=" . getLock($lockfile) . ") is still running." );
141    
142     setLock() if $Command eq "scheduled";
143     $SIG{'TERM'} = 'SignalHandler';
144     @@ -525,7 +533,7 @@
145     }
146     else
147     {
148     - affaErrorExit( 102, "rsync failed with status $status.");
149     + affaErrorExit( "rsync failed with status $status.");
150     }
151     }
152    
153     @@ -614,7 +622,7 @@
154     }
155     else
156     {
157     - affaErrorExit( 103, "Job '$jobname' undefined.");
158     + affaErrorExit( "Job '$jobname' undefined.");
159     }
160     $job{'sshPort'}=22 if not $job{'sshPort'};
161     $job{'EmailAddresses'}=$defaultEmail if not $job{'EmailAddresses'};
162     @@ -757,13 +765,13 @@
163     {
164     lg( "Checking rsyncd connection to " . $job{'remoteHostName'} );
165     @cmd=($rsyncLocal, '-dq', ($job{'rsyncdUser'} ? $job{'rsyncdUser'}.'@' : '') . $job{'remoteHostName'} . "::'" . $job{'rsyncdModule'} . "'");
166     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 104, "Rsyncd connection to ". $job{'remoteHostName'}. " failed. Did you set the rsyncdUser, rsyncdPassword and rsyncdModule properties correctly?" );
167     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Rsyncd connection to ". $job{'remoteHostName'}. " failed. Did you set the rsyncdUser, rsyncdPassword and rsyncdModule properties correctly?" );
168     }
169     else
170     {
171     lg( "Checking SSH connection to " . $job{'remoteHostName'} );
172     @cmd=('/usr/bin/ssh', '-p', $job{'sshPort'}, '-o', 'StrictHostKeyChecking=yes', '-o', "HostKeyAlias=$jobname", '-o', "ConnectTimeout=$job{'ConnectionCheckTimeout'}",'-o','PasswordAuthentication=no', $sshQuiet, $job{'remoteHostName'},'true');
173     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 104, "SSH connection to ". $job{'remoteHostName'}. " failed. Did you send the public key?" );
174     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "SSH connection to ". $job{'remoteHostName'}. " failed. Did you send the public key?" );
175     }
176     }
177    
178     @@ -781,7 +789,7 @@
179     lg( "signaling pre-backup event on ". $job{'remoteHostName'} );
180     @cmd=('/usr/bin/ssh', '-o', "HostKeyAlias=$jobname", '-p', $job{'sshPort'}, $sshQuiet, $job{'remoteHostName'},"/sbin/e-smith/signal-event pre-backup desktop");
181     }
182     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 105, "signaling pre-backup event failed." );
183     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "signaling pre-backup event failed." );
184     }
185    
186     sub signalPostBackupEvent()
187     @@ -825,7 +833,7 @@
188     "'/sbin/e-smith/affa-rpmlist.sh>$rpmlist'"
189     );
190     }
191     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 107, "writing list of installed RPMs failed." );
192     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "writing list of installed RPMs failed." );
193     }
194    
195    
196     @@ -837,7 +845,7 @@
197     my $RPMPath="home/e-smith/db/affa-rpmlist";
198     my %remoteRPM;
199     dbg( "Reading remote RPM list" );
200     - open( RP, "$localRPMList/$RPMPath" ) or affaErrorExit( 108, "Couldn't open $localRPMList/$RPMPath" );
201     + open( RP, "$localRPMList/$RPMPath" ) or affaErrorExit( "Couldn't open $localRPMList/$RPMPath" );
202     while( <RP> )
203     {
204     my @z = split( " ", $_);
205     @@ -876,7 +884,7 @@
206     dbg("MD5Filename=$MD5Filename");
207     if( not -f $MD5Filename )
208     {
209     - open( RP, ">$RPMFilename" ) or affaErrorExit( 109, "Couldn't open $RPMFilename for writing.");
210     + open( RP, ">$RPMFilename" ) or affaErrorExit( "Couldn't open $RPMFilename for writing.");
211    
212     my $out='';
213     foreach my $k (@missing)
214     @@ -916,7 +924,7 @@
215     $msg->to($job{'EmailAddresses'});
216     $msg->set("From", "\"Affa Backup Server\" <noreply\@$SystemName.$DomainName>");
217     my $fh = $msg->open;
218     - open( RP, "<$RPMFilename" ) or affaErrorExit( 110, "Couldn't open $RPMFilename.");
219     + open( RP, "<$RPMFilename" ) or affaErrorExit( "Couldn't open $RPMFilename.");
220     while( <RP> )
221     {
222     print $fh $_;
223     @@ -927,7 +935,7 @@
224     }
225    
226     unlink( glob( "$job{'RootDir'}/$jobname/.md5-rpms-missing-*" ) );
227     - open( RP, ">$MD5Filename" ) or affaErrorExit( 111, "Couldn't open $MD5Filename for writing.");
228     + open( RP, ">$MD5Filename" ) or affaErrorExit( "Couldn't open $MD5Filename for writing.");
229     print RP "md5sum of content of file $RPMFilename\n";
230     close( RP );
231     }
232     @@ -1108,7 +1116,7 @@
233     close( WD );
234     chmod( 0700, "/usr/lib/affa/$WDName" );
235     my @cmd=('/usr/bin/ssh', '-o', "HostKeyAlias=$jobname", '-p', $job{'sshPort'}, $job{'remoteHostName'}, "/bin/rm", "-f", "/etc/cron.hourly/$WDName-reminder" );
236     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 118, "Couldn't delete /etc/cron.hourly/$WDName-reminder on remote host." );
237     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't delete /etc/cron.hourly/$WDName-reminder on remote host." );
238     remoteCopy("/usr/lib/affa/$WDName","/etc/cron.hourly/" );
239     }
240    
241     @@ -1174,19 +1182,19 @@
242     {
243     return if not $job{'preJobCommand'};
244     lg( "Executing preJobCommand $job{'preJobCommand'}");
245     - affaErrorExit( 113, "Couldn't execute preJobCommand $job{'preJobCommand'}") if not -x $job{'preJobCommand'};
246     + affaErrorExit( "Couldn't execute preJobCommand $job{'preJobCommand'}") if not -x $job{'preJobCommand'};
247     my @cmd = ( $job{'preJobCommand'}, $job{'remoteHostName'}, $jobname, $Command );
248     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 114, "Executing preJobCommand $job{'preJobCommand'} failed." );
249     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Executing preJobCommand $job{'preJobCommand'} failed." );
250     }
251    
252     sub execPostJobCommand($)
253     {
254     return if not $job{'postJobCommand'};
255     lg( "Executing postJobCommand $job{'postJobCommand'}");
256     - affaErrorExit( 115, "Couldn't execute postJobCommand $job{'postJobCommand'}") if not -x $job{'postJobCommand'};
257     + affaErrorExit( "Couldn't execute postJobCommand $job{'postJobCommand'}") if not -x $job{'postJobCommand'};
258     my @cmd = ( $job{'postJobCommand'}, $job{'remoteHostName'}, $jobname, $Command, shift(@_) );
259     $job{'postJobCommand'}=''; # don't execute again in affaErrorExit()
260     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 116, "Executing postJobCommand $job{'postJobCommand'} failed." );
261     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Executing postJobCommand $job{'postJobCommand'} failed." );
262     }
263    
264     sub listJobs()
265     @@ -1289,7 +1297,7 @@
266     if( not $affa->get($jobname)||'' )
267     {
268     my $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
269     - affaErrorExit( 135, "$txt" );
270     + affaErrorExit( "$txt" );
271     }
272     getJobConfig( $jobname );
273     updateReportDB();
274     @@ -1525,7 +1533,7 @@
275     my $s="Couldn't mount $dev $AutomountPoint";
276     if( $Command )
277     {
278     - affaErrorExit( 130, $s );
279     + affaErrorExit( $s );
280     }
281     else
282     {
283     @@ -1623,7 +1631,7 @@
284     my $txt="Error: Archive $archive not found."; print "$txt\n"; lg($txt);
285     $txt = "Run 'affa --list-archives $jobname' to view available archives.\n";
286     print "$txt\n";
287     - affaErrorExit( 123, "." );
288     + affaErrorExit( "." );
289     }
290     }
291    
292     @@ -1637,7 +1645,7 @@
293     if( not $affa->get($jobname)||'' )
294     {
295     $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
296     - affaErrorExit( 136, "$txt" );
297     + affaErrorExit( "$txt" );
298     }
299     getJobConfig( $jobname );
300     my $dir = opendir( DIR, "$job{'RootDir'}/$jobname" );
301     @@ -1669,7 +1677,7 @@
302     chomp( $input );
303     if( $input ne 'proceed' )
304     {
305     - affaErrorExit( 146, "Terminated by user" ) if $input ne 'proceed';
306     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
307     }
308     foreach my $k ( reverse sort keys %archives )
309     {
310     @@ -1688,19 +1696,19 @@
311     if( not $affa->get($jobname)||'' )
312     {
313     $txt= "Error: Job '$jobname' undefined."; print("$txt\n");
314     - affaErrorExit( 147, "$txt" );
315     + affaErrorExit( "$txt" );
316     }
317     getJobConfig( $jobname );
318     (my $newdir=$ARGV[1])=~s/\/$//;
319     if( not $newdir )
320     {
321     $txt= "Error: New RootDir not given."; print("$txt\n");
322     - affaErrorExit( 148, "$txt" );
323     + affaErrorExit( "$txt" );
324     }
325     if( not $newdir=~/^\// or $newdir=~/\.\./ )
326     {
327     $txt= "Error: Full path required for NEWROOTDIR."; print("$txt\n");
328     - affaErrorExit( 150, "$txt" );
329     + affaErrorExit( "$txt" );
330     }
331     if( not -d $newdir )
332     {
333     @@ -1714,7 +1722,7 @@
334     if( $input ne 'yes' )
335     {
336     $interactive=0;
337     - affaErrorExit( 149, "Terminated by user" ) if $input ne 'proceed';
338     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
339     }
340     File::Path::mkpath( $newdir, 0, 0700 )
341     }
342     @@ -1760,7 +1768,7 @@
343     if( not $affa->get($jobname)||'' )
344     {
345     $txt= "Error: Job '$jobname' undefined."; print("$txt\n");
346     - affaErrorExit( 141, "$txt" );
347     + affaErrorExit( "$txt" );
348     }
349     getJobConfig( $jobname );
350     my $newname=$ARGV[1]||'';
351     @@ -1768,12 +1776,12 @@
352     if( not $newname )
353     {
354     $txt= "Error: No new jobname given."; print("$txt\n");
355     - affaErrorExit( 142, "$txt" );
356     + affaErrorExit( "$txt" );
357     }
358     if( $affa->get($newname) )
359     {
360     $txt= "Error: A job 'mars' already exists."; print("$txt\n");
361     - affaErrorExit( 143, "$txt" );
362     + affaErrorExit( "$txt" );
363     }
364     if( -f "/home/e-smith/db/affa-report/$jobname" )
365     {
366     @@ -1821,7 +1829,7 @@
367     if( not $affa->get($jobname)||'' )
368     {
369     $txt= "Error: Job '$jobname' undefined."; print("$txt\n");
370     - affaErrorExit( 144, "$txt" );
371     + affaErrorExit( "$txt" );
372     }
373     getJobConfig( $jobname );
374     my $dir = opendir( DIR, "$job{'RootDir'}/$jobname" );
375     @@ -1846,7 +1854,7 @@
376     chomp( $input );
377     if( $input ne 'proceed' )
378     {
379     - affaErrorExit( 133, "Terminated by user" ) if $input ne 'proceed';
380     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
381     }
382     revokeKeys($jobname) if $opts{'revoke-keys'};
383     if( $dir )
384     @@ -1883,7 +1891,7 @@
385     if( not $affa->get($jobname)||'' )
386     {
387     $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
388     - affaErrorExit( 145, "$txt" );
389     + affaErrorExit( "$txt" );
390     }
391     getJobConfig( $jobname );
392    
393     @@ -1896,7 +1904,7 @@
394     if( getLock("$lockdir/$jobname") )
395     {
396     print "Job '$jobname' is running. Wait for completion. Then run affa --full-restore again.\n";
397     - affaErrorExit( 131, "affa job 'jobname' is running." );
398     + affaErrorExit( "affa job 'jobname' is running." );
399     }
400    
401     # check if archive exists
402     @@ -1917,7 +1925,7 @@
403     if( $input ne 'proceed' )
404     {
405     $interactive=0;
406     - affaErrorExit( 132, "Terminated by user" ) if $input ne 'proceed';
407     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
408     }
409    
410     $txt="Signaling pre-restore event on $job{'remoteHostName'}"; lg( $txt ); print "$txt\n";
411     @@ -2004,7 +2012,7 @@
412     lg( $txt ); print "$txt\n";
413     $txt="Try option --full-restore instead.";
414     lg( $txt ); print "$txt\n";
415     - affaErrorExit( 134, "Cannot rise from my own backup." );
416     + affaErrorExit( "Cannot rise from my own backup." );
417     }
418    
419    
420     @@ -2036,7 +2044,7 @@
421     if( not $interactive )
422     {
423     print "Wait for completion of the running jobs or kill them. Then run affa --rise again.\n";
424     - affaErrorExit( 124, "affa jobs are running." );
425     + affaErrorExit( "affa jobs are running." );
426     }
427    
428     stopServices();
429     @@ -2074,7 +2082,7 @@
430     if( $input ne 'proceed' )
431     {
432     $interactive=0;
433     - affaErrorExit( 128, "Terminated by user" ) if $input ne 'proceed';
434     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
435     }
436    
437     print "Signaling pre-restore event\n";
438     @@ -2097,7 +2105,7 @@
439     # This allows us to run the --rise option remotely and connect to the restored server
440     my $srcconfigPath="/var/affa/$ServerBasename/scheduled.0/home/e-smith/db/configuration";
441     my $srcconfig = esmith::ConfigDB->open_ro($srcconfigPath)
442     - or affaErrorExit( 126, "Couldn't open source config db $srcconfigPath");
443     + or affaErrorExit( "Couldn't open source config db $srcconfigPath");
444     $config->set_prop("EthernetDriver1","type", $srcconfig->get("EthernetDriver1")->value);
445     $config->set_prop("EthernetDriver2","type", $srcconfig->get("EthernetDriver2")->value);
446     $config->set_prop("InternalInterface","Driver", $srcconfig->get_prop("InternalInterface","Driver"));
447     @@ -2116,7 +2124,7 @@
448     $interactive=1;
449     # search server base backup
450     my $dir = opendir( DIR, "/var/affa/" );
451     - affaErrorExit( 125, "Couldn't open directory /var/affa/" ) if not $dir;
452     + affaErrorExit( "Couldn't open directory /var/affa/" ) if not $dir;
453     my $archive;
454     my $a='';
455     while( defined ($archive=readdir(DIR)) )
456     @@ -2124,7 +2132,7 @@
457     next if not $archive =~ /AFFA\.[a-z][a-z0-9\-]*\..*-\d*\.\d*\.\d*\.\d*/;
458     $a=$archive;
459     }
460     - affaErrorExit( 127, "No server base backup found." ) if not $a and not -f "$a/scheduled.0";
461     + affaErrorExit( "No server base backup found." ) if not $a and not -f "$a/scheduled.0";
462     stopServices();
463     print "\nWARNING: You will loose all data of your current server installation!\n";
464     my $input='';
465     @@ -2137,7 +2145,7 @@
466     if( $input ne 'proceed' )
467     {
468     $interactive=0;
469     - affaErrorExit( 122, "Terminated by user" ) if $input ne 'proceed';
470     + affaErrorExit( "Terminated by user" ) if $input ne 'proceed';
471     }
472    
473     print "Signaling pre-restore event\n";
474     @@ -2262,7 +2270,7 @@
475     $me->set_prop($p,$v);
476     }
477     my @cmd=('/sbin/e-smith/affa','--run', $ServerBasename);
478     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 121, "Couldn't backup myself" );
479     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't backup myself" );
480     print "Done.\n";
481     }
482    
483     @@ -2303,7 +2311,7 @@
484     if( not $affa->get($jobname)||'' )
485     {
486     my $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
487     - affaErrorExit( 139, "$txt" );
488     + affaErrorExit( "$txt" );
489     }
490     $HostKeyAliasOption="-o HostKeyAlias=$jobname";
491     getJobConfig($jobname);
492     @@ -2318,11 +2326,11 @@
493     $s="Generating DSA keys...";
494     print "$s\n"; lg($s);
495     @cmd=("/usr/bin/ssh-keygen",$sshQuiet,"-t","dsa","-N ''","-f", "/root/.ssh/id_dsa" );
496     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 119, "Couldn't generate DSA keys" );
497     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't generate DSA keys" );
498     $s="Successfully created DSA key pair.";
499     print "$s\n"; lg($s);
500     }
501     - open( PUBK, $kf ) or affaErrorExit( 156, "Could not open $kf" );
502     + open( PUBK, $kf ) or affaErrorExit( "Could not open $kf" );
503     my $pubk=trim(<PUBK>);
504     close( PUBK );
505     my $cmd;
506     @@ -2365,7 +2373,7 @@
507     if( not $affa->get($jobname)||'' )
508     {
509     my $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
510     - affaErrorExit( 153, "$txt" );
511     + affaErrorExit( "$txt" );
512     }
513     $HostKeyAliasOption="-o HostKeyAlias=$jobname";
514     getJobConfig($jobname);
515     @@ -2373,7 +2381,7 @@
516     $port = $job{'sshPort'} ? $job{'sshPort'} : 22;
517     }
518    
519     - open( PUBK, $kf ) or affaErrorExit( 154, "Could not open $kf" );
520     + open( PUBK, $kf ) or affaErrorExit( "Could not open $kf" );
521     my $pubk=trim(<PUBK>);
522     close( PUBK );
523    
524     @@ -2397,7 +2405,7 @@
525     {
526     $s="Deleting public key on $remotehost failed.";
527     print "$s\n";
528     - affaErrorExit( 155, $s );
529     + affaErrorExit( $s );
530     }
531     $s="Public key deleted on $remotehost";
532     print "$s\n"; lg($s);
533     @@ -2433,6 +2441,80 @@
534     }
535     }
536    
537     +
538     +sub createBackupFile()
539     + {
540     + my $jobname=$ARGV[0]||'';
541     + my $archive=$ARGV[1]||'scheduled.0';
542     + my $txt;
543     +
544     + if( not $affa->get($jobname)||'' )
545     + {
546     + $txt= "Job '$jobname' undefined"; print("Error: $txt\n");
547     + affaErrorExit( "$txt" );
548     + }
549     + getJobConfig( $jobname );
550     +
551     + if( $job{'AutomountDevice'} and $job{'AutomountPoint'} )
552     + {
553     + mount( $job{'AutomountDevice'}, $job{'AutomountPoint'}, $job{'AutomountOptions'} );
554     + }
555     +
556     + # check if a job is running
557     + if( getLock("$lockdir/$jobname") )
558     + {
559     + print "Job '$jobname' is running. Wait for completion. Then run affa --create-backup-file again.\n";
560     + affaErrorExit( "affa job 'jobname' is running." );
561     + }
562     +
563     + # check if archive exists
564     + checkArchiveExists($job{'RootDir'},$jobname,$archive);
565     +
566     + my $outfile=$opts{'outfile'};
567     + $outfile=$cwd if not $outfile;
568     + $outfile .= '/smeserver.tgz' if -d $outfile;
569     +
570     + if( -f $outfile )
571     + {
572     + $txt= "File $outfile already exists."; print("Error: $txt\n");
573     + affaErrorExit( "$txt" );
574     + }
575     +
576     + unless ( open( OUT, ">$outfile" ) )
577     + {
578     + $txt= "Could not open $outfile for writing."; print("Error: $txt\n");
579     + affaErrorExit( "$txt" );
580     + }
581     + close( OUT );
582     + unlink( $outfile );
583     +
584     + my $affastatus = esmith::DB::db->open("/home/e-smith/db/affa-report/$jobname");
585     + my $size=$affastatus->get_prop( $archive, 'TotalFileSize' ) || 0;
586     + $size =~ s/(\d*).*/$1/;
587     + my $f;
588     + my $restore_list='';
589     + my $dir = opendir( DIR, "$job{'RootDir'}/$jobname/$archive" );
590     + while( defined ($f=readdir(DIR)) )
591     + {
592     + next if $f =~ /^(.AFFA-REPORT|$jobname-setup.pl|\.|\.\.)$/;
593     + $restore_list.="$f ";
594     + }
595     + close(DIR);
596     + my @cmd=('/bin/tar', '-C', "$job{'RootDir'}/$jobname/$archive/", '-cf - ', $restore_list,
597     + '|', '/usr/bin/pv -i 0.3', "-s $size",
598     + '|', '/bin/gzip',
599     + "> $outfile"
600     + );
601     + my $status=ExecCmd( @cmd, 0 );
602     + if( $status!=0 )
603     + {
604     + unlink( $outfile );
605     + $txt= "Could not create $outfile."; print("Error: $txt\n");
606     + affaErrorExit( "$txt" );
607     + }
608     + $txt="Backup file '$outfile' created."; print("$txt\n"); lg( $txt);
609     + }
610     +
611     sub showSchedule()
612     {
613     my $res=$opts{15} ? 15 : 30;
614     @@ -2523,7 +2605,7 @@
615     if( not $affa->get($jobname)||'' )
616     {
617     my $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
618     - affaErrorExit( 138, "$txt" );
619     + affaErrorExit( "$txt" );
620     }
621     getJobConfig( $jobname );
622     my $msg = new Mail::Send;
623     @@ -2564,7 +2646,7 @@
624     chmod( 0700, "/usr/lib/affa/$WDName" );
625     remoteCopy("/usr/lib/affa/$WDName", "/tmp/");
626     my @cmd=('/usr/bin/ssh', '-p', $job{'sshPort'}, '-o', "HostKeyAlias=$jobname", $sshQuiet, $job{'remoteHostName'},"/tmp/$WDName");
627     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 152, "Couldn't run /usr/lib/affa/$WDName on remote host." );
628     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't run /usr/lib/affa/$WDName on remote host." );
629     }
630    
631     sub trim($)
632     @@ -2764,7 +2846,7 @@
633     "--rsync-path='$rsyncRemote'",
634     "--rsh='/usr/bin/ssh -o HostKeyAlias=$jobname -p $job{'sshPort'}'",
635     $src, $job{'remoteHostName'}.":$dst" );
636     - not ExecCmd( @cmd, 0 ) or affaErrorExit( 151, "Couldn't copy $src to remote host." );
637     + not ExecCmd( @cmd, 0 ) or affaErrorExit( "Couldn't copy $src to remote host." );
638     }
639    
640     sub showVersion()
641     @@ -2808,6 +2890,7 @@
642     print " or affa --revoke-key JOB\n";
643     print " or affa --revoke-key --host=TARGETHOST [--port=PORT] [--remoteOS=cygwin]\n";
644     print " or affa --check-connections\n";
645     + print " or affa --create-backup-file JOB [ARCHIVE] [--outfile=FILE]\n";
646     print " or affa --kill JOB\n";
647     print " or affa --version\n";
648     print " or affa --help\n";
649     @@ -2831,7 +2914,7 @@
650     if( not $affa->get($jobname)||'' )
651     {
652     my $txt= "Error: Job '$jobname' undefined"; print("$txt\n");
653     - affaErrorExit( 157, "$txt" );
654     + affaErrorExit( "$txt" );
655     }
656     my $pid=getLock("$lockdir/$jobname");
657     if( $pid )
658     @@ -2857,7 +2940,7 @@
659     lg("$Command run killed");
660     if( $Command eq "scheduled" )
661     {
662     - affaErrorExit( 1, "Caught interrupt signal $sig");
663     + affaErrorExit( "Caught interrupt signal $sig");
664     }
665     else
666     {
667     @@ -2866,13 +2949,15 @@
668     }
669     }
670    
671     -sub affaErrorExit( $$ )
672     +sub affaErrorExit($)
673     {
674     - (my $err, my $msg) = @_;
675     + (my $msg) = @_;
676     + my $err=(caller)[2];
677     + my $sub=(caller(1))[3]||'';
678     lg( "Error $err: $msg" );
679     print "Error $err: $msg\n" if $interactive==1;
680     emptyTrash() if $Command eq "scheduled";
681     - execPostJobCommand($err) if $err != 115;
682     + execPostJobCommand($err) if $sub ne 'main::execPostJobCommand';
683     unmountAll();
684     sendErrorMesssage();
685     removeLock();
686     --- smeserver-affa-0.9.0/root/etc/profile.d/affa.sh.createBackupFileOption 2008-01-18 16:50:15.000000000 +0100
687     +++ smeserver-affa-0.9.0/root/etc/profile.d/affa.sh 2008-03-07 19:40:21.000000000 +0100
688     @@ -4,13 +4,13 @@
689     case $COMP_CWORD in
690     # option
691     1)
692     - COMPREPLY=( $(/sbin/e-smith/affa | grep " affa $cur"|awk '{print $3}' ) )
693     + COMPREPLY=( $(/sbin/e-smith/affa --_shorthelp | grep " affa $cur"|awk '{print $3}' ) )
694     ;;
695     # job
696     2)
697     - /sbin/e-smith/affa --help | grep -qs -- "${COMP_WORDS[1]}.*JOB"
698     + /sbin/e-smith/affa --_shorthelp | grep -qs -- "${COMP_WORDS[1]}.*JOB"
699     if [ "$?" == 0 ] ; then
700     - COMPREPLY=( $(/sbin/e-smith/affa --jobs | grep "^$cur" ) )
701     + COMPREPLY=( $(/sbin/e-smith/affa --_jobs | grep "^$cur" ) )
702     fi
703     ;;
704     esac

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed