X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_dump;h=cc633f9b868b5192f1618eee4a665f5b1751c458;hp=89e4bfea51662593983879d4d6d0bdb8c1a78603;hb=d1bfa4d92bec24954f2e7877f6531644bb84e8f3;hpb=2441b9094f3f6e4f2a3a4fe67781780e6f6890bd diff --git a/bin/BackupPC_dump b/bin/BackupPC_dump index 89e4bfe..cc633f9 100755 --- a/bin/BackupPC_dump +++ b/bin/BackupPC_dump @@ -1,11 +1,11 @@ -#!/bin/perl +#!/usr/bin/perl #============================================================= -*-perl-*- # # BackupPC_dump: Dump a single client. # # DESCRIPTION # -# Usage: BackupPC_dump [-i] [-f] [-d] [-e] [-v] +# Usage: BackupPC_dump [-i] [-f] [-F] [-I] [-d] [-e] [-v] # # Flags: # @@ -14,6 +14,13 @@ # # -f Do a full dump, overriding any scheduling. # +# -I Do an increment dump if the regular schedule requires a +# full or incremental, otherwise do nothing (a full is done +# if no dumps have yet succeeded) +# +# -F Do a full dump if the regular schedule requires a +# full or incremental, otherwise do nothing +# # -d Host is a DHCP pool address, and the client argument # just an IP address. We lookup the NetBios name from # the IP address. @@ -52,7 +59,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001-2007 Craig Barratt +# Copyright (C) 2001-2009 Craig Barratt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,7 +77,7 @@ # #======================================================================== # -# Version 3.2.0beta0, released 17 Jan 2009. +# Version 3.2.0, released 31 Jul 2010. # # See http://backuppc.sourceforge.net. # @@ -105,14 +112,19 @@ my $Abort; $bpc->ChildInit(); my %opts; -if ( !getopts("defiv", \%opts) || @ARGV != 1 ) { - print("usage: $0 [-d] [-e] [-f] [-i] [-v] \n"); +if ( !getopts("defivFI", \%opts) || @ARGV != 1 ) { + print("usage: $0 [-d] [-e] [-f] [-i] [-F] [-I] [-v] \n"); exit(1); } if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) { print("$0: bad client name '$ARGV[0]'\n"); exit(1); } +if ( (defined($opts{f}) + defined($opts{i}) + defined($opts{F}) + defined($opts{I})) > 1 ) { + print("$0: exiting because you can only use one of -f, -i, -F, and -I\n"); + exit(1); +} + my $client = $1; # BackupPC's client name (might not be real host name) my $hostIP; # this is the IP address my $host; # this is the real host name @@ -315,6 +327,7 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0 || !defined($p->{hourBegin}) || !defined($p->{hourEnd}) ); + my $matchWday = $wday; if ( $p->{hourBegin} > $p->{hourEnd} ) { $blackout = $p->{hourBegin} <= $currHours || $currHours <= $p->{hourEnd}; @@ -324,14 +337,14 @@ if ( !$opts{i} && !$opts{f} && $Conf{BlackoutGoodCnt} >= 0 # weekday check (eg: Monday 11pm-1am means Monday 2300 to # Tuesday 0100, not Monday 2300-2400 plus Monday 0000-0100). # - $wday--; - $wday += 7 if ( $wday < 0 ); + $matchWday--; + $matchWday += 7 if ( $matchWday < 0 ); } } else { $blackout = $p->{hourBegin} <= $currHours && $currHours <= $p->{hourEnd}; } - if ( $blackout && grep($_ == $wday, @{$p->{weekDays}}) ) { + if ( $blackout && grep($_ == $matchWday, @{$p->{weekDays}}) ) { # print(LOG $bpc->timeStamp, "skipping because of blackout" # . " (alive $StatusHost{aliveCnt} times)\n"); print(STDERR "Skipping $client because of blackout\n") @@ -387,15 +400,21 @@ for ( my $i = 0 ; $i < @Backups ; $i++ ) { # # Decide whether we do nothing, or a full or incremental backup. # +my $needs_full = (time - $lastFullTime > $Conf{FullPeriod} * 24 * 3600 + && time - $lastIncrTime > $Conf{IncrPeriod} * 24 * 3600); +my $needs_incr = (time - $lastIncrTime > $Conf{IncrPeriod} * 24 * 3600 + && time - $lastFullTime > $Conf{IncrPeriod} * 24 * 3600); + if ( $lastFullTime == 0 || $opts{f} - || (!$opts{i} && (time - $lastFullTime > $Conf{FullPeriod} * 24*3600 - && time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600)) ) { + || (!$opts{i} && !$opts{I} && $needs_full) + || ( $opts{F} && $needs_incr) ) { $type = "full"; $incrLevel = 0; $incrBaseBkupNum = $lastBkupNum; -} elsif ( $opts{i} || (time - $lastIncrTime > $Conf{IncrPeriod} * 24*3600 - && time - $lastFullTime > $Conf{IncrPeriod} * 24*3600) ) { +} elsif ( $opts{i} + || $needs_incr + || ($opts{I} && $needs_full) ) { $type = "incr"; # # For an incremental backup, figure out which level we should @@ -604,6 +623,7 @@ $NeedPostCmd = 1; # # Now backup each of the shares # +my $shareDuplicate = {}; for my $shareName ( @$ShareNames ) { local(*RH, *WH); @@ -613,11 +633,17 @@ for my $shareName ( @$ShareNames ) { $shareName = encode("utf8", $shareName); $stat{xferOK} = $stat{hostAbort} = undef; $stat{hostError} = $stat{lastOutputLine} = undef; - if ( -d "$Dir/new/$shareName" ) { + if ( $shareName eq "" ) { + print(LOG $bpc->timeStamp, + "unexpected empty share name skipped\n"); + next; + } + if ( $shareDuplicate->{$shareName} ) { print(LOG $bpc->timeStamp, "unexpected repeated share name $shareName skipped\n"); next; } + $shareDuplicate->{$shareName} = 1; UserCommandRun("DumpPreShareCmd", $shareName); if ( $? && $Conf{UserCmdCheckStatus} ) { @@ -896,6 +922,10 @@ for my $shareName ( @$ShareNames ) { # last; } + # + # Wait for any child processes to exit + # + # 1 while ( wait() >= 0 ); } # @@ -987,6 +1017,8 @@ print(LOG $bpc->timeStamp, BackupExpire($client); +UserCommandRun("DumpPostFinishCmd"); # XXX ASA search integration + print("$type backup complete\n"); ###########################################################################