insert first backup and update size at end
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Fri, 18 Nov 2005 19:40:47 +0000 (19:40 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Fri, 18 Nov 2005 19:40:47 +0000 (19:40 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@242 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb

index 9e9c9cc..97811b8 100755 (executable)
@@ -434,7 +434,12 @@ WHERE hostID=? AND num=? AND shareid=?
 
 $sth->{insert_backups} = $dbh->prepare(qq{
 INSERT INTO backups (hostID, num, date, type, shareid, size)
-VALUES (?,?,?,?,?,?)
+VALUES (?,?,?,?,?,-1)
+});
+
+$sth->{update_backups_size} = $dbh->prepare(qq{
+UPDATE backups SET size = ?
+WHERE hostID = ? and num = ? and date = ? and type =? and shareid = ?
 });
 
 $sth->{insert_files} = $dbh->prepare(qq{
@@ -500,15 +505,23 @@ foreach my $host_key (keys %{$hosts}) {
                        # dump some log
                        print curr_time," ", $share;
 
-                       my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
-
                        $sth->{insert_backups}->execute(
                                $hostID,
                                $backupNum,
                                $backup->{'endTime'},
                                substr($backup->{'type'},0,4),
                                $shareID,
+                       );
+
+                       my ($f, $nf, $d, $nd, $size) = recurseDir($bpc, $hostname, $files, $backupNum, $share, "", $shareID);
+
+                       $sth->{update_backups_size}->execute(
                                $size,
+                               $hostID,
+                               $backupNum,
+                               $backup->{'endTime'},
+                               substr($backup->{'type'},0,4),
+                               $shareID,
                        );
 
                        print " commit";
@@ -633,7 +646,7 @@ sub recurseDir($$$$$$$$) {
                        # daylight saving time change offset for 1h
                        my $dst_offset = 60 * 60;
 
-                       my $key_dst1 = join(" ", (
+                       my $key_dst_prev = join(" ", (
                                $shareID,
                                $dir,
                                $path_key,
@@ -641,7 +654,7 @@ sub recurseDir($$$$$$$$) {
                                $filesInBackup->{$path_key}->{'size'}
                        ));
 
-                       my $key_dst2 = join(" ", (
+                       my $key_dst_next = join(" ", (
                                $shareID,
                                $dir,
                                $path_key,
@@ -652,8 +665,8 @@ sub recurseDir($$$$$$$$) {
                        my $found;
                        if (
                                ! defined($beenThere->{$key}) &&
-                               ! defined($beenThere->{$key_dst1}) &&
-                               ! defined($beenThere->{$key_dst2}) &&
+                               ! defined($beenThere->{$key_dst_prev}) &&
+                               ! defined($beenThere->{$key_dst_next}) &&
                                ! ($found = found_in_db($key, @data))
                        ) {
                                print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);