r8506@llin: dpavlin | 2005-10-13 19:26:50 +0200
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Thu, 13 Oct 2005 18:32:59 +0000 (18:32 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Thu, 13 Oct 2005 18:32:59 +0000 (18:32 +0000)
 added parts to backups, make split calculate suffix length, added ability
 to join parts of increments if media size changes

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@196 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_incPartsUpdate
bin/BackupPC_updatedb
sql/04_backups_parts.sql [new file with mode: 0644]

index edf2afc..b9f30aa 100755 (executable)
@@ -64,7 +64,8 @@ select
        hosts.name as host,
        shares.name as share,
        backups.num as num,
-       inc_size
+       inc_size,
+       parts
 from backups
        join shares on backups.hostid = shares.hostid
                and shares.id = backups.shareid
@@ -76,7 +77,7 @@ order by backups.date
 
 $sth->execute();
 
-my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ? where id = ? });
+my $sth_inc_size = $dbh->prepare(qq{ update backups set inc_size = ?, parts = ? where id = ? });
 my $sth_inc_deleted = $dbh->prepare(qq{ update backups set inc_deleted = ? where id = ? });
 
 %BackupPC::SearchLib::Conf = %Conf;
@@ -93,7 +94,7 @@ while (my $row = $sth->fetchrow_hashref) {
 
        # re-create archive?
        if ($row->{'inc_size'} == -1 || $size == -1 || $row->{'inc_size'} != $size) {
-               my $cmd = qq{$tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file};
+               my $cmd = qq{rm -Rf $tar_dir/$tar_file && $tarIncCreate -h "$row->{'host'}" -s "$row->{'share'}" -n $row->{'num'} | gzip -9 > $tar_dir/$tar_file};
                print STDERR "## $cmd\n" if ($debug);
 
                system($cmd) == 0 or die "failed: $?";
@@ -104,18 +105,33 @@ while (my $row = $sth->fetchrow_hashref) {
        if ($size > 45) {
 
                my $max_size = $Conf{'MaxArchiveSize'} || die "problem with MaxArchieSize parametar";
+               $max_size *= 1024;      # convert to bytes
+
+               my $parts = int( ($size + $max_size - 1) / $max_size );
+
+               if (-d "$tar_dir/$tar_file" && $parts != $row->{'parts'}) {
+                       print " join";
+
+                       my $in = my $out = "$tar_dir/$tar_file";
+                       $out .= '.tmp';
+
+                       # FIXME I should really order parts manually!
+                       system("cat $in/part* > $out && rm -Rf $in && mv $out $in") == 0 or die "can't join $in: $?";
+               }
 
                if ($size > $max_size && ! -d "$tar_dir/$tar_file") {
-                       print " split";
+                       print " split/$parts";
                        my $in = my $out = "$tar_dir/$tar_file";
                        $out .= '.tmp';
                        rename $in, $out || die "can't rename $in: $!";
                        mkdir $in || die "can't mkdir $in: $!";
-                       system("split -d -b $max_size $out $in/part") == 0 or die "can't split $out: $!";
+
+                       my $suffix_len = length("$parts");
+                       system("split -d -b $max_size -a $suffix_len $out $in/part") == 0 or die "can't split $out: $?";
                        unlink $out || die "can't unlink $out: $!";
                }
 
-               $sth_inc_size->execute($size, $row->{'backup_id'});
+               $sth_inc_size->execute($size, $parts, $row->{'backup_id'});
                $sth_inc_deleted->execute(0, $row->{'backup_id'});
 
                printf(" %1.2f MB", ($size / 1024 / 1024));
index 25147db..f716e46 100755 (executable)
@@ -310,6 +310,7 @@ if ($opt{c}) {
                        size    bigint          not null,
                        inc_size bigint         not null default -1,
                        inc_deleted boolean     default false,
+                       parts   integer         not null default 1,
                        PRIMARY KEY(id)
                );            
 
@@ -344,7 +345,7 @@ if ($opt{c}) {
                create table archive_burned (
                        archive_id int references archive(id),
                        date date default now(),
-                       iso_size int default -1
+                       iso_size bigint default -1
                );
 
        });
diff --git a/sql/04_backups_parts.sql b/sql/04_backups_parts.sql
new file mode 100644 (file)
index 0000000..cbeeb5f
--- /dev/null
@@ -0,0 +1,3 @@
+alter table backups add column parts int ;
+alter table backups alter parts set default 1 ;
+update backups set parts = 1 ;