* checkin with 3.2.0beta0 release header
[BackupPC.git] / bin / BackupPC_link
index 85a9388..63289aa 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/perl -T
+#!/usr/bin/perl
 #============================================================= -*-perl-*-
 #
 # BackupPC_link: link new backup into pool
@@ -21,7 +21,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001  Craig Barratt
+#   Copyright (C) 2001-2007  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
 #
 #========================================================================
 #
-# Version 1.5.0, released 2 Aug 2002.
+# Version 3.2.0beta0, released 5 April 2009.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
-use lib "__INSTALLDIR__/lib";
+no  utf8;
+use lib "/usr/local/BackupPC/lib";
 use BackupPC::Lib;
 use BackupPC::Attrib;
 use BackupPC::PoolWrite;
+use BackupPC::Storage;
 
 use File::Find;
 use File::Path;
@@ -70,7 +72,7 @@ if ( @ARGV != 1 ) {
     print("usage: $0 <host>\n");
     exit(1);
 }
-if ( $ARGV[0] !~ /^([\w\.-]+)$/ ) {
+if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) {
     print("$0: bad host name '$ARGV[0]'\n");
     exit(1);
 }
@@ -105,7 +107,8 @@ while ( 1 ) {
     #
     $CurrDumpDir = "$Dir/$Backups[$num]{num}";
     $Compress = $Backups[$num]{compress};
-    if ( open(NEW, "$Dir/NewFileList.$Backups[$num]{num}") ) {
+    if ( open(NEW, "<", "$Dir/NewFileList.$Backups[$num]{num}") ) {
+       binmode(NEW);
         while ( <NEW> ) {
             chomp;
             next if ( !/(\w+) (\d+) (.*)/ );
@@ -126,7 +129,7 @@ while ( 1 ) {
     #
     my $noFill = 1;
     my $fillFromNum;
-    if ( $Backups[$num]{type} eq "full" ) {
+    if ( $Backups[$num]{type} ne "incr" ) {
         $noFill = 0
     } elsif ( $Conf{IncrFill} ) {
         my $i;
@@ -154,6 +157,16 @@ while ( 1 ) {
     $Backups[$num]{sizeNewComp}   += $sizeNewComp;
     $Backups[$num]{noFill}         = $noFill;
     $Backups[$num]{fillFromNum}    = $fillFromNum;
+    #
+    # Save just this backup's info in case the main backups file
+    # gets corrupted
+    #
+    BackupPC::Storage->backupInfoWrite($Dir,
+                                       $Backups[$num]{num},
+                                       $Backups[$num], 1);
+    #
+    # Save the main backups file
+    #
     $bpc->BackupInfoWrite($host, @Backups);
 }
 
@@ -209,7 +222,21 @@ sub FillIncr
         #
         # Exists in the older filled backup, and not in the new, so link it
         #
-        link($name, $newName);
+        my($exists, $digest, $origSize, $outSize, $errs)
+                    = BackupPC::PoolWrite::LinkOrCopy(
+                                      $bpc,
+                                      $name, $Compress,
+                                      $newName, $Compress);
+        if ( $exists ) {
+            $nFilesExist++;
+            $sizeExist += $origSize;
+            $sizeExistComp += $outSize;
+        } elsif ( $outSize > 0 ) {
+            $nFilesNew++;
+            $sizeNew += $origSize;
+            $sizeNewComp += -s $outSize;
+            LinkNewFile($digest, $origSize, $newName);
+        }
     }
 }