|
Lines 23-28
Link Here
|
| 23 |
use File::Temp qw( tempdir ); |
23 |
use File::Temp qw( tempdir ); |
| 24 |
use POSIX qw( strftime ); |
24 |
use POSIX qw( strftime ); |
| 25 |
|
25 |
|
|
|
26 |
# command line options |
| 27 |
my $archive_name = ''; |
| 28 |
my $archive_type = ''; |
| 29 |
my $help = '0'; |
| 30 |
my $store_pt = '0'; |
| 31 |
my @ext2_parts = (); |
| 32 |
my $verbose = '0'; |
| 33 |
my $files_info = ''; |
| 34 |
my $comment_file = ''; |
| 35 |
my $complete_backup = ''; |
| 36 |
my $multi_volume = undef; |
| 37 |
my $temp_dir = '/tmp'; |
| 38 |
|
| 26 |
# return all harddisks present in system |
39 |
# return all harddisks present in system |
| 27 |
sub harddisks($) |
40 |
sub harddisks($) |
| 28 |
{ |
41 |
{ |
|
Lines 61-66
Link Here
|
| 61 |
if ($ix > 0) |
74 |
if ($ix > 0) |
| 62 |
{ |
75 |
{ |
| 63 |
my $dirs = substr($f, 0, $ix); |
76 |
my $dirs = substr($f, 0, $ix); |
|
|
77 |
if ($verbose) { |
| 78 |
print "Running: /bin/mkdir -p $dirs 2> /dev/null\n"; |
| 79 |
} |
| 64 |
system("/bin/mkdir -p $dirs 2> /dev/null"); # create directory with parents |
80 |
system("/bin/mkdir -p $dirs 2> /dev/null"); # create directory with parents |
| 65 |
} |
81 |
} |
| 66 |
} |
82 |
} |
|
Lines 115-134
Link Here
|
| 115 |
return $result; |
131 |
return $result; |
| 116 |
} |
132 |
} |
| 117 |
|
133 |
|
| 118 |
|
|
|
| 119 |
# command line options |
| 120 |
my $archive_name = ''; |
| 121 |
my $archive_type = ''; |
| 122 |
my $help = '0'; |
| 123 |
my $store_pt = '0'; |
| 124 |
my @ext2_parts = (); |
| 125 |
my $verbose = '0'; |
| 126 |
my $files_info = ''; |
| 127 |
my $comment_file = ''; |
| 128 |
my $complete_backup = ''; |
| 129 |
my $multi_volume = undef; |
| 130 |
my $temp_dir = '/tmp'; |
| 131 |
|
| 132 |
# parse command line options |
134 |
# parse command line options |
| 133 |
GetOptions('archive-name=s' => \$archive_name, |
135 |
GetOptions('archive-name=s' => \$archive_name, |
| 134 |
'archive-type=s' => \$archive_type, 'help' => \$help, |
136 |
'archive-type=s' => \$archive_type, 'help' => \$help, |
|
Lines 210-218
Link Here
|
| 210 |
} |
212 |
} |
| 211 |
|
213 |
|
| 212 |
# create parent temporary directory |
214 |
# create parent temporary directory |
| 213 |
system("/bin/mkdir -p $temp_dir"); |
215 |
system("/bin/mkdir -p '$temp_dir'"); |
|
|
216 |
if (! -d $temp_dir) { |
| 217 |
die "Cannot create directory $temp_dir: ".$!; |
| 218 |
} |
| 214 |
|
219 |
|
| 215 |
my $tmp_dir_root = tempdir($temp_dir."/backup_tmp_XXXXXXXX", CLEANUP => 1); # remove directory content at exit |
220 |
my $tmp_dir_root = tempdir($temp_dir."/backup_tmp_XXXXXXXX", CLEANUP => 1); # remove directory content at exit |
|
|
221 |
system("/bin/mkdir -p '$tmp_dir_root'"); |
| 222 |
if (! -d $tmp_dir_root) { |
| 223 |
die "Cannot create directory $tmp_dir_root: ".$!; |
| 224 |
} |
| 216 |
|
225 |
|
| 217 |
my $tmp_dir = $tmp_dir_root."/tmp"; |
226 |
my $tmp_dir = $tmp_dir_root."/tmp"; |
| 218 |
if (!mkdir($tmp_dir)) |
227 |
if (!mkdir($tmp_dir)) |
|
Lines 244-250
Link Here
|
| 244 |
print OUT "info/packages_info.gz\n"; |
253 |
print OUT "info/packages_info.gz\n"; |
| 245 |
$files_num++; |
254 |
$files_num++; |
| 246 |
|
255 |
|
| 247 |
|
|
|
| 248 |
# store host name |
256 |
# store host name |
| 249 |
use Sys::Hostname; |
257 |
use Sys::Hostname; |
| 250 |
my $host = hostname(); |
258 |
my $host = hostname(); |
|
Lines 490-498
Link Here
|
| 490 |
|
498 |
|
| 491 |
if ($line =~ /^\/.+/) |
499 |
if ($line =~ /^\/.+/) |
| 492 |
{ |
500 |
{ |
| 493 |
if (-r remove_escape($line) or -l remove_escape($line)) # output only readable files from files-info |
501 |
my $esc_line = remove_escape($line); |
| 494 |
# symlinked files need not to be readable |
502 |
|
| 495 |
{ |
503 |
# if (-r $esc_line or -l $esc_line) # output only readable files from files-info |
|
|
504 |
# # symlinked files need not to be readable |
| 505 |
# { |
| 496 |
print FILES_INFO $line."\n"; |
506 |
print FILES_INFO $line."\n"; |
| 497 |
|
507 |
|
| 498 |
if (defined $opened) |
508 |
if (defined $opened) |
|
Lines 504-517
Link Here
|
| 504 |
else |
514 |
else |
| 505 |
{ |
515 |
{ |
| 506 |
# star doesn't use escape sequences |
516 |
# star doesn't use escape sequences |
| 507 |
print PKGLIST remove_escape($line)."\n"; |
517 |
print PKGLIST $esc_line."\n"; |
| 508 |
} |
518 |
} |
| 509 |
} |
519 |
} |
| 510 |
} |
520 |
# } |
| 511 |
else |
521 |
# else |
| 512 |
{ |
522 |
# { |
| 513 |
print "/File not readable: $line\n"; |
523 |
# print "/File not readable: $line\n"; |
| 514 |
} |
524 |
# } |
| 515 |
} |
525 |
} |
| 516 |
else |
526 |
else |
| 517 |
{ |
527 |
{ |
|
Lines 639-650
Link Here
|
| 639 |
close(FILES_INFO); |
649 |
close(FILES_INFO); |
| 640 |
|
650 |
|
| 641 |
# compress file packages_info (avg. ratio is ~10:1) |
651 |
# compress file packages_info (avg. ratio is ~10:1) |
| 642 |
while (!-e $tmp_dir.'/packages_info.gz') { |
652 |
my $wait_sec = 60; |
|
|
653 |
if (-e "$tmp_dir/packages_info") { |
| 654 |
print "Gzipping $tmp_dir/packages_info\n"; |
| 643 |
system("/usr/bin/gzip -9 $tmp_dir/packages_info"); |
655 |
system("/usr/bin/gzip -9 $tmp_dir/packages_info"); |
| 644 |
warn 'Cannot create '.$tmp_dir.'/packages_info.gz: '.$!."\n"; |
656 |
while ($wait_sec > 0 && ! -e "$tmp_dir/packages_info.gz") { |
| 645 |
sleep(15); |
657 |
--$wait_sec; |
|
|
658 |
sleep(1); |
| 659 |
} |
| 660 |
} elsif (! -e "$tmp_dir/packages_info.gz") { |
| 661 |
print ("No such file : $tmp_dir/packages_info"); |
| 646 |
} |
662 |
} |
| 647 |
|
663 |
|
|
|
664 |
if (! -e "$tmp_dir/packages_info.gz") { |
| 665 |
print 'Cannot create '.$tmp_dir.'/packages_info.gz: '.$!."\n"; |
| 666 |
} |
| 667 |
|
| 648 |
close(OUT); |
668 |
close(OUT); |
| 649 |
|
669 |
|
| 650 |
|
670 |
|
|
Lines 671-677
Link Here
|
| 671 |
# -L <size> volume size in kiB |
691 |
# -L <size> volume size in kiB |
| 672 |
# -V <str> volume prefix label |
692 |
# -V <str> volume prefix label |
| 673 |
|
693 |
|
| 674 |
my $tar_command = "(export LC_ALL=C; tar -c --files-from $tmp_dir/files --ignore-failed-read -C $tmp_dir_root/tmp -S"; |
694 |
my $tar_command = "(export LC_ALL=C; cd $tmp_dir_root/tmp; tar -c --files-from $tmp_dir/files --ignore-failed-read -C $tmp_dir_root/tmp -S"; |
| 675 |
|
695 |
|
| 676 |
if ($verbose) |
696 |
if ($verbose) |
| 677 |
{ |
697 |
{ |
|
Lines 781-786
Link Here
|
| 781 |
# create standard (no multi volume) archive |
801 |
# create standard (no multi volume) archive |
| 782 |
$tar_command .= " -f $archive_name 2> /dev/null)"; |
802 |
$tar_command .= " -f $archive_name 2> /dev/null)"; |
| 783 |
|
803 |
|
|
|
804 |
print "Tar command: $tar_command\n"; |
| 784 |
system($tar_command); |
805 |
system($tar_command); |
| 785 |
} |
806 |
} |
| 786 |
|
807 |
|