X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC;h=d18bcefc697144e9a8dece741e3dab9ae617b86c;hp=5c17c2be9d270680308893907ceab1fb568ff9ff;hb=7dee89bfce659051d486cc66515bb7f22bbc4f09;hpb=1ce7d1541ea1279aaa0a75c16986a3fd40b608ec diff --git a/bin/BackupPC b/bin/BackupPC index 5c17c2b..d18bcef 100755 --- a/bin/BackupPC +++ b/bin/BackupPC @@ -47,7 +47,7 @@ # #======================================================================== # -# Version 1.5.0, released 2 Aug 2002. +# Version 2.0.0beta1, released 30 Mar 2003. # # See http://backuppc.sourceforge.net. # @@ -55,7 +55,7 @@ use strict; use vars qw(%Status %Info $Hosts); -use lib "__INSTALLDIR__/lib"; +use lib "/usr/local/BackupPC/lib"; use BackupPC::Lib; use BackupPC::FileZIO; @@ -70,8 +70,7 @@ use Digest::MD5; # Handle command line options ########################################################################### my %opts; -getopts("d", \%opts); -if ( @ARGV != 0 ) { +if ( !getopts("d", \%opts) || @ARGV != 0 ) { print("usage: $0 [-d]\n"); exit(1); } @@ -249,8 +248,8 @@ sub Main_Initialize exit(1); } foreach my $progName ( qw(SmbClientPath NmbLookupPath PingPath DfPath - SendmailPath) ) { - next if ( !defined($Conf{$progName}) || -x $Conf{$progName} ); + SendmailPath SshPath) ) { + next if ( $Conf{$progName} eq "" || -x $Conf{$progName} ); print(STDERR $bpc->timeStamp, "\$Conf{$progName} = '$Conf{$progName}' is not a" . " valid executable program\n"); @@ -307,16 +306,16 @@ sub Main_Initialize # Requeue any pending links. # foreach my $host ( sort(keys(%$Hosts)) ) { - if ( $Status{$host}{state} eq "backup in progress" ) { + if ( $Status{$host}{state} eq "Status_backup_in_progress" ) { # # should we restart it? skip it for now. # - $Status{$host}{state} = "idle"; - } elsif ( $Status{$host}{state} eq "link pending" - || $Status{$host}{state} eq "link running" ) { + $Status{$host}{state} = "Status_idle"; + } elsif ( $Status{$host}{state} eq "Status_link_pending" + || $Status{$host}{state} eq "Status_link_running" ) { QueueLink($host); } else { - $Status{$host}{state} = "idle"; + $Status{$host}{state} = "Status_idle"; } $Status{$host}{activeJob} = 0; } @@ -325,7 +324,7 @@ sub Main_Initialize # Write out our initial status and save our PID # StatusWrite(); - if ( open(PID, ">$TopDir/log/BackupPC.pid") ) { + if ( open(PID, ">", "$TopDir/log/BackupPC.pid") ) { print(PID $$); close(PID); } @@ -364,7 +363,7 @@ sub Main_TryToRun_nightly host => $bpc->trashJob, user => "BackupPC", reqTime => time, - cmd => "$BinDir/BackupPC_trashClean" + cmd => ["$BinDir/BackupPC_trashClean"], }); $CmdQueueOn{$bpc->trashJob} = 1; } @@ -373,7 +372,7 @@ sub Main_TryToRun_nightly host => $bpc->adminJob, user => "BackupPC", reqTime => time, - cmd => "$BinDir/BackupPC_nightly" + cmd => ["$BinDir/BackupPC_nightly"], }); $CmdQueueOn{$bpc->adminJob} = 1; $RunNightlyWhenIdle = 2; @@ -420,8 +419,8 @@ sub Main_TryToRun_CmdQueue } if ( !$pid ) { setpgrp 0,0; - exec($cmd); - print(LOG $bpc->timeStamp, "can't exec $cmd for $host\n"); + exec(@$cmd); + print(LOG $bpc->timeStamp, "can't exec @$cmd for $host\n"); exit(0); } $Jobs{$host}{pid} = $pid; @@ -430,9 +429,10 @@ sub Main_TryToRun_CmdQueue vec($FDread, $Jobs{$host}{fn}, 1) = 1; $Jobs{$host}{startTime} = time; $Jobs{$host}{reqTime} = $req->{reqTime}; + $cmd = join(" ", @$cmd); $Jobs{$host}{cmd} = $cmd; $Jobs{$host}{type} = $Status{$host}{type}; - $Status{$host}{state} = "link running"; + $Status{$host}{state} = "Status_link_running"; $Status{$host}{activeJob} = 1; $Status{$host}{endTime} = time; $CmdJob = $host if ( $host ne $bpc->trashJob ); @@ -560,11 +560,11 @@ sub Main_TryToRun_Bg_or_User_Queue vec($FDread, $Jobs{$host}{fn}, 1) = 1; $Jobs{$host}{startTime} = time; $Jobs{$host}{reqTime} = $req->{reqTime}; - $Jobs{$host}{cmd} = "$progName " . join(" ", @args); + $Jobs{$host}{cmd} = join(" ", $progName, @args); $Jobs{$host}{user} = $user; $Jobs{$host}{type} = $type; if ( !$req->{dhcp} ) { - $Status{$host}{state} = "$type starting"; + $Status{$host}{state} = "Status_".$type."_starting"; $Status{$host}{activeJob} = 1; $Status{$host}{startTime} = time; $Status{$host}{endTime} = ""; @@ -775,7 +775,7 @@ sub Main_Check_Job_Messages $Jobs{$host}{mesg} = $2; if ( $Jobs{$host}{dhcp} ) { if ( $mesg =~ /^DHCP (\S+) (\S+)/ ) { - my $newHost = $2; + my $newHost = $bpc->uriUnesc($2); if ( defined($Jobs{$newHost}) ) { print(LOG $bpc->timeStamp, "Backup on $newHost is already running\n"); @@ -788,7 +788,7 @@ sub Main_Check_Job_Messages $Jobs{$newHost} = $Jobs{$host}; delete($Jobs{$host}); $host = $newHost; - $Status{$host}{state} = "backup starting"; + $Status{$host}{state} = "Status_backup_starting"; $Status{$host}{activeJob} = 1; $Status{$host}{startTime} = $Jobs{$host}{startTime}; $Status{$host}{endTime} = ""; @@ -796,19 +796,15 @@ sub Main_Check_Job_Messages } else { print(LOG $bpc->timeStamp, "dhcp $host: $mesg\n"); } - } elsif ( $mesg =~ /^started (.*) dump, pid=(\d+), tarPid=(-?\d+)/ ) { - $Jobs{$host}{type} = $1; - $Jobs{$host}{xferPid} = $2; - $Jobs{$host}{tarPid} = $3; + } elsif ( $mesg =~ /^started (.*) dump, share=(.*)/ ) { + $Jobs{$host}{type} = $1; + $Jobs{$host}{shareName} = $2; print(LOG $bpc->timeStamp, - "Started $1 backup on $host" - . " (pid=$Jobs{$host}{pid}, xferPid=$2", - $Jobs{$host}{tarPid} > 0 - ? ", tarPid=$Jobs{$host}{tarPid}" : "", + "Started $1 backup on $host (pid=$Jobs{$host}{pid}", $Jobs{$host}{dhcpHostIP} ? ", dhcp=$Jobs{$host}{dhcpHostIP}" : "", - ")\n"); - $Status{$host}{state} = "backup in progress"; + ", share=$Jobs{$host}{shareName})\n"); + $Status{$host}{state} = "Status_backup_in_progress"; $Status{$host}{reason} = ""; $Status{$host}{type} = $1; $Status{$host}{startTime} = time; @@ -816,17 +812,14 @@ sub Main_Check_Job_Messages $Status{$host}{aliveCnt}++; $Status{$host}{dhcpCheckCnt}-- if ( $Status{$host}{dhcpCheckCnt} > 0 ); - } elsif ( $mesg =~ /^started_restore (\S+) (\S+)/ ) { - $Jobs{$host}{type} = "restore"; + } elsif ( $mesg =~ /^xferPids (.*)/ ) { $Jobs{$host}{xferPid} = $1; - $Jobs{$host}{tarPid} = $2; + } elsif ( $mesg =~ /^started_restore/ ) { + $Jobs{$host}{type} = "restore"; print(LOG $bpc->timeStamp, "Started restore on $host" - . " (pid=$Jobs{$host}{pid}, xferPid=$2", - $Jobs{$host}{tarPid} > 0 - ? ", tarPid=$Jobs{$host}{tarPid}" : "", - ")\n"); - $Status{$host}{state} = "restore in progress"; + . " (pid=$Jobs{$host}{pid})\n"); + $Status{$host}{state} = "Status_restore_in_progress"; $Status{$host}{reason} = ""; $Status{$host}{type} = "restore"; $Status{$host}{startTime} = time; @@ -834,27 +827,27 @@ sub Main_Check_Job_Messages $Status{$host}{aliveCnt}++; } elsif ( $mesg =~ /^(full|incr) backup complete/ ) { print(LOG $bpc->timeStamp, "Finished $1 backup on $host\n"); - $Status{$host}{reason} = "backup done"; + $Status{$host}{reason} = "Reason_backup_done"; delete($Status{$host}{error}); delete($Status{$host}{errorTime}); $Status{$host}{endTime} = time; } elsif ( $mesg =~ /^restore complete/ ) { print(LOG $bpc->timeStamp, "Finished restore on $host\n"); - $Status{$host}{reason} = "restore done"; + $Status{$host}{reason} = "Reason_restore_done"; delete($Status{$host}{error}); delete($Status{$host}{errorTime}); $Status{$host}{endTime} = time; } elsif ( $mesg =~ /^nothing to do/ ) { - $Status{$host}{state} = "idle"; - $Status{$host}{reason} = "nothing to do"; + $Status{$host}{state} = "Status_idle"; + $Status{$host}{reason} = "Reason_nothing_to_do"; $Status{$host}{startTime} = time; $Status{$host}{dhcpCheckCnt}-- if ( $Status{$host}{dhcpCheckCnt} > 0 ); } elsif ( $mesg =~ /^no ping response/ || $mesg =~ /^ping too slow/ ) { - $Status{$host}{state} = "idle"; - if ( $Status{$host}{reason} ne "backup failed" ) { - $Status{$host}{reason} = "no ping"; + $Status{$host}{state} = "Status_idle"; + if ( $Status{$host}{reason} ne "Reason_backup_failed" ) { + $Status{$host}{reason} = "Reason_no_ping"; $Status{$host}{startTime} = time; } $Status{$host}{deadCnt}++; @@ -862,8 +855,8 @@ sub Main_Check_Job_Messages $Status{$host}{aliveCnt} = 0; } } elsif ( $mesg =~ /^dump failed: (.*)/ ) { - $Status{$host}{state} = "idle"; - $Status{$host}{reason} = "backup failed"; + $Status{$host}{state} = "Status_idle"; + $Status{$host}{reason} = "Reason_backup_failed"; $Status{$host}{error} = $1; $Status{$host}{errorTime} = time; $Status{$host}{endTime} = time; @@ -881,6 +874,7 @@ sub Main_Check_Job_Messages $Info{"$f[0]FileCntRep"} = $f[7]; $Info{"$f[0]FileRepMax"} = $f[8]; $Info{"$f[0]FileCntRename"} = $f[9]; + $Info{"$f[0]FileLinkMax"} = $f[10]; $Info{"$f[0]Time"} = time; printf(LOG "%s%s nightly clean removed %d files of" . " size %.2fGB\n", @@ -888,11 +882,12 @@ sub Main_Check_Job_Messages $Info{"$f[0]FileCntRm"}, $Info{"$f[0]KbRm"} / (1000 * 1024)); printf(LOG "%s%s is %.2fGB, %d files (%d repeated, " - . "%d max chain), %d directories\n", + . "%d max chain, %d max links), %d directories\n", $bpc->timeStamp, ucfirst($f[0]), $Info{"$f[0]Kb"} / (1000 * 1024), $Info{"$f[0]FileCnt"}, $Info{"$f[0]FileCntRep"}, - $Info{"$f[0]FileRepMax"}, $Info{"$f[0]DirCnt"}); + $Info{"$f[0]FileRepMax"}, + $Info{"$f[0]FileLinkMax"}, $Info{"$f[0]DirCnt"}); } elsif ( $mesg =~ /^BackupPC_nightly lock_off/ ) { $RunNightlyWhenIdle = 0; } elsif ( $mesg =~ /^processState\s+(.+)/ ) { @@ -914,7 +909,7 @@ sub Main_Check_Job_Messages my $cmd = $Jobs{$host}{cmd}; $cmd =~ s/$BinDir\///g; print(LOG $bpc->timeStamp, "Finished $host ($cmd)\n"); - $Status{$host}{state} = "idle"; + $Status{$host}{state} = "Status_idle"; $Status{$host}{endTime} = time; $CmdJob = ""; $RunNightlyWhenIdle = 0 if ( $cmd eq "BackupPC_nightly" @@ -925,11 +920,11 @@ sub Main_Check_Job_Messages # processing for this host. # if ( defined($Status{$host}) - && ($Status{$host}{reason} eq "backup done" + && ($Status{$host}{reason} eq "Reason_backup_done" || $Status{$host}{needLink}) ) { QueueLink($host); } elsif ( defined($Status{$host}) ) { - $Status{$host}{state} = "idle"; + $Status{$host}{state} = "Status_idle"; } } delete($Jobs{$host}); @@ -1011,17 +1006,24 @@ sub Main_Check_Client_Messages $host = $1; my $user = $2; my $backoff = $3; + $host = $bpc->uriUnesc($host); if ( $CmdJob ne $host && defined($Status{$host}) && defined($Jobs{$host}) ) { print(LOG $bpc->timeStamp, "Stopping current backup of $host," . " request by $user (backoff=$backoff)\n"); kill(2, $Jobs{$host}{pid}); - vec($FDread, $Jobs{$host}{fn}, 1) = 0; - close($Jobs{$host}{fh}); - delete($Jobs{$host}); - $Status{$host}{state} = "idle"; - $Status{$host}{reason} = "backup canceled by $user"; + # + # Don't close the pipe now; wait until the child + # really exits later. Otherwise close() will + # block until the child has exited. + # old code: + ##vec($FDread, $Jobs{$host}{fn}, 1) = 0; + ##close($Jobs{$host}{fh}); + ##delete($Jobs{$host}); + + $Status{$host}{state} = "Status_idle"; + $Status{$host}{reason} = "Reason_backup_canceled_by_user"; $Status{$host}{activeJob} = 0; $Status{$host}{startTime} = time; $reply = "ok: backup of $host cancelled"; @@ -1050,9 +1052,11 @@ sub Main_Check_Client_Messages QueueAllPCs(); } elsif ( $cmd =~ /^backup (\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ ) { my $hostIP = $1; - $host = $2; - my $user = $3; + $host = $2; + my $user = $3; my $doFull = $4; + $host = $bpc->uriUnesc($host); + $hostIP = $bpc->uriUnesc($hostIP); if ( !defined($Status{$host}) ) { print(LOG $bpc->timeStamp, "User $user requested backup of unknown host" @@ -1091,6 +1095,8 @@ sub Main_Check_Client_Messages $host = $2; my $user = $3; my $reqFileName = $4; + $host = $bpc->uriUnesc($host); + $hostIP = $bpc->uriUnesc($hostIP); if ( !defined($Status{$host}) ) { print(LOG $bpc->timeStamp, "User $user requested restore to unknown host" @@ -1140,15 +1146,20 @@ sub Main_Check_Client_Messages } elsif ( $type =~ /^hosts/ ) { push(@values, \%Status); push(@names, qw(*Status)); - } elsif ( $type =~ /^host\((.*)\)/ - && defined($Status{$1}) ) { - push(@values, { - %{$Status{$1}}, - BgQueueOn => $BgQueueOn{$1}, - UserQueueOn => $UserQueueOn{$1}, - CmdQueueOn => $CmdQueueOn{$1}, - }); - push(@names, qw(*StatusHost)); + } elsif ( $type =~ /^host\((.*)\)/ ) { + my $h = $bpc->uriUnesc($1); + if ( defined($Status{$h}) ) { + push(@values, { + %{$Status{$h}}, + BgQueueOn => $BgQueueOn{$h}, + UserQueueOn => $UserQueueOn{$h}, + CmdQueueOn => $CmdQueueOn{$h}, + }); + push(@names, qw(*StatusHost)); + } else { + print(LOG $bpc->timeStamp, + "Unknown host $h for status request\n"); + } } else { print(LOG $bpc->timeStamp, "Unknown status request $type\n"); @@ -1159,6 +1170,7 @@ sub Main_Check_Client_Messages $reply = $dump->Dump; } elsif ( $cmd =~ /^link\s+(.+)/ ) { my($host) = $1; + $host = $bpc->uriUnesc($host); QueueLink($host); } elsif ( $cmd =~ /^log\s+(.*)/ ) { print(LOG $bpc->timeStamp, "$1\n"); @@ -1252,7 +1264,7 @@ sub StatusWrite [ \%Info, \%Status], [qw(*Info *Status)]); $dump->Indent(1); - if ( open(STATUS, ">$TopDir/log/status.pl") ) { + if ( open(STATUS, ">", "$TopDir/log/status.pl") ) { print(STATUS $dump->Dump); close(STATUS); } @@ -1326,13 +1338,13 @@ sub QueueLink my($host) = @_; return if ( $CmdQueueOn{$host} ); - $Status{$host}{state} = "link pending"; + $Status{$host}{state} = "Status_link_pending"; $Status{$host}{needLink} = 0; unshift(@CmdQueue, { host => $host, user => "BackupPC", reqTime => time, - cmd => "$BinDir/BackupPC_link $host" + cmd => ["$BinDir/BackupPC_link", $host], }); $CmdQueueOn{$host} = 1; } @@ -1366,7 +1378,7 @@ sub HostsUpdate # foreach my $host ( sort(keys(%$Hosts)) ) { next if ( defined($Status{$host}) ); - $Status{$host}{state} = "idle"; + $Status{$host}{state} = "Status_idle"; print(LOG $bpc->timeStamp, "Added host $host to backup list\n"); } foreach my $host ( sort(keys(%Status)) ) {