bin/ftbackup
changeset 123 0c6e454093df
parent 122 51a8543685bb
child 124 6c90a6e8646c
child 128 2e8c48130af7
equal deleted inserted replaced
122:51a8543685bb 123:0c6e454093df
   204 
   204 
   205             # examine the situation and decide about the level
   205             # examine the situation and decide about the level
   206             # FIXME: currently we simply run a full dump every FULL_CYCLE
   206             # FIXME: currently we simply run a full dump every FULL_CYCLE
   207             # days, the intermediate dumps are level 1
   207             # days, the intermediate dumps are level 1
   208             foreach (reverse sort $ftp->ls) {
   208             foreach (reverse sort $ftp->ls) {
       
   209 		next if /\.tmp-\d+$/;
   209                 next if not /^(?<date>.*)\.(?<level>\d+)$/;
   210                 next if not /^(?<date>.*)\.(?<level>\d+)$/;
   210 		next if not $ftp->size(0) and str2time($+{date}) < $^T;
   211 		next if not $ftp->size(0) and str2time($+{date}) < $^T;
   211                 $last[$+{level}] = str2time $+{date};
   212                 $last[$+{level}] = str2time $+{date};
   212             }
   213             }
   213         }
   214         }
   321             die "Can't exec dumper\n";
   322             die "Can't exec dumper\n";
   322         };
   323         };
   323 
   324 
   324         if ($ftp) {
   325         if ($ftp) {
   325             verbose("sending dump to " . $ftp->pwd . "/$file.tmp-$^T\n");
   326             verbose("sending dump to " . $ftp->pwd . "/$file.tmp-$^T\n");
   326             $ftp->try(put => $dump, $file);
   327             $ftp->try(put => $dump, "$file.tmp-$^T");
   327 	    $ftp->try(rename => "$file.tmp-$^T", $file);
   328 	    $ftp->try(rename => "$file.tmp-$^T", $file);
   328         }
   329         }
   329         else {
   330         else {
   330             print while <$dump>;
   331             print while <$dump>;
   331             WARN "STOPPED after the first dump to STDOUT\n";
   332             WARN "STOPPED after the first dump to STDOUT\n";
   640 sub unlink_old_dumps($$$) {
   641 sub unlink_old_dumps($$$) {
   641     my ($ftp, $keep, $extra) = @_;
   642     my ($ftp, $keep, $extra) = @_;
   642     my @dumps;
   643     my @dumps;
   643 
   644 
   644     foreach ($ftp->ls) {
   645     foreach ($ftp->ls) {
       
   646 	if (/\.tmp-(?<timestamp>\d+)$/ and $+{timestamp} < $^T) {
       
   647 	    INFO "removing old tmp file $_";
       
   648 	    $ftp->delete($_);
       
   649 	    next;
       
   650 	};
   645         /^(?<date>.*)\.(?<level>\d+)$/ or next;
   651         /^(?<date>.*)\.(?<level>\d+)$/ or next;
   646 	if (not $ftp->size($_) and str2time($+{date}) < $^T) {
   652 	if (not $ftp->size($_) and str2time($+{date}) < $^T) {
   647 	    INFO "removing old zero size backup $_";
   653 	    INFO "removing old zero size backup $_";
   648 	    $ftp->delete($_);
   654 	    $ftp->delete($_);
   649 	    next;
   655 	    next;