my $in_backup_increment;
-if ( !getopts("th:n:p:r:s:b:w:vd", \%opts) ) {
+if ( !getopts("th:n:p:r:s:b:w:vdf", \%opts) ) {
print STDERR <<EOF;
usage: $0 [options]
Required options:
-p pathAdd new path prefix
-b BLOCKS BLOCKS x 512 bytes per record (default 20; same as tar)
-w writeBufSz write buffer size (default 1048576 = 1MB)
+ -f overwrite existing parts
-v verbose output
-d debug output
EOF
#
my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar";
-$max_file_size *= 1024;
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
my ($backup_id) = $sth->fetchrow_array;
$sth->finish;
+
+# delete exising backup_parts
+my $sth_delete_backup_parts = $dbh->prepare(qq{
+ delete from backup_parts
+ where backup_id = ?
+});
+$sth_delete_backup_parts->execute($backup_id);
+
+
print STDERR "backup_id: $backup_id working dir: $tar_dir, max uncompressed size $max_file_size bytes, tar $tar_file\n" if ($opts{d});
+if (-e $tar_path_final) {
+ if ($opts{f}) {
+ rmtree $tar_path_final || die "can't remove $tar_path_final: $!";
+ } else {
+ die "$tar_path_final allready exists\n";
+ }
+}
my $fh;
my $part = 0;
if ($fh) {
return if ($current_tar_size == 0);
- print STDERR " $part" if ($opts{v});
+ print STDERR " $part";
#
# Finish with two null 512 byte headers,
$items_in_part,
);
- $total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024;
+ $total_increment_size += $size;
if ($arg->{close}) {
+ sub move($$) {
+ my ($from,$to) = @_;
+ print STDERR "# rename $from -> $to\n" if ($opts{d});
+ rename $from, $to || die "can't move $from -> $to: $!\n";
+ }
+
if ($part == 1) {
- print STDERR " single";
- rename "${tar_path}/1.tar.gz", "${tar_path_final}/.tar.gz" || die "can't move tar ${tar_path}: $! ";
- rename "${tar_path}/1.md5", "${tar_path_final}/.md5" || die "can't move md5 ${tar_path}: $! ";
+ print STDERR " single" if ($opts{v});
+ move("${tar_path}/1.tar.gz", "${tar_path_final}.tar.gz");
+ move("${tar_path}/1.md5", "${tar_path_final}.md5");
+ rmtree $tar_path or die "can't remove temporary dir $tar_path: $!";
} else {
- print STDERR " [last]";
- rename "${tar_path}", "${tar_path_final}" || die "can't move tar ${tar_path}: $! ";
+ print STDERR " [last]" if ($opts{v});
+ move("${tar_path}", "${tar_path_final}");
+
+ # if this archive was single part, remove it
+ foreach my $suffix (qw/.tar.gz .md5/) {
+ my $path = $tar_path_final . $suffix;
+ unlink $path if (-e $path);
+ }
}
$sth_inc_size->execute(
# if this is first part, create directory
if ($part == 1) {
- if (-d $tar_path) {
+ if (-e $tar_path) {
print STDERR "# deleting existing $tar_path\n" if ($opts{d});
rmtree($tar_path);
}
if (seedCache($Host, $ShareName, $Num)) {
archiveWrite($fh, '/');
archiveWriteHardLinks($fh);
+ new_tar_part( close => 1 );
} else {
print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v});
- $no_files = 1;
-}
-
-new_tar_part( close => 1 );
-
-# remove temporary files if there are no files
-if ($no_files) {
+ # remove temporary files if there are no files
rmtree($tar_path);
-} elsif ($part == 1) {
- warn "FIXME: if there is only one part move to parent directory and rename";
}
#