5 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
6 & eval 'exec @PERL@ -S $0 $argv:q'
9 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
10 $ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
13 push(@INC, "@DUMPER_DIR@");
20 open(DEBUG,">>@AMANDA_DBGDIR@/gnutar.$$.debug") if ($debug==1);
23 $exec_prefix="@exec_prefix@";
24 $libexecdir="@libexecdir@";
25 $USE_VERSION_SUFFIXES='@USE_VERSION_SUFFIXES@';
27 if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
33 $runtar="${libexecdir}/runtar${suf}";
34 $gnulist = '@GNUTAR_LISTED_INCREMENTAL_DIR@';
39 $level_incrementals = 9;
41 @index_generation = ("direct","parse","output","image");
42 @parse_estimate = ("direct","parse");
43 @parse_backup = ("direct","parse");
44 @backup_type = ("full","level","diff");
50 #$user_selfcheck = "";
51 #$group_selfcheck = "";
54 #$group_estimate = "";
56 #$user_estimate_parse = "";
57 #$group_estimate_parse = "";
59 $user_backup = "root";
62 #$user_backup_parse = "";
63 #$group_backup_parse = "";
65 #$user_index_from_output = "";
66 #$group_index_from_output = "";
68 #$user_index_from_image = "";
69 #$group_index_from_image = "";
74 #$user_print_command = "";
75 #$group_print_command = "";
77 $user_default = "amanda";
78 $group_default = "amanda";
81 sub command_selfcheck {
82 print DEBUG "STDOUT: OK selfcheck\n" if ($debug == 1);
83 print "OK selfcheck\n";
86 sub command_estimate_full {
88 command_estimate_level(0, $disk);
91 sub command_estimate_level {
92 my($level, $disk) = @_;
93 my($listdir) = "$host$disk";
96 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
97 close(GNULIST) || die();
100 my($prev_level) = $level - 1;
101 copy("${gnulist}/${listdir}_${prev_level}", "${gnulist}/${listdir}_${level}.new");
103 if($option_estimate_direct == 1) {
104 command_estimate_opt_direct($disk, $level, $listdir);
107 command_estimate_opt_parse($disk, $level, $listdir);
111 #sub command_estimate_diff {
114 sub command_estimate_opt_direct {
115 my($disk, $level, $listdir) = @_;
117 print DEBUG "$gnutar --create --directory $disk --listed-incremental ${gnulist}/${listdir}_${level}.new --sparse --one-file-system --ignore-failed-read --totals --file /dev/null .\n" if ($debug == 1);
118 open3(\*WTRFH, '>&STDOUT', \*ESTIMATE, "$gnutar --create --directory $disk --listed-incremental ${gnulist}/${listdir}_${level}.new --sparse --one-file-system --ignore-failed-read --totals --file /dev/null .") || die();
120 $size = parse_estimate(ESTIMATE);
123 unlink "${gnulist}/${listdir}_${level}.new";
127 sub command_estimate_opt_parse {
128 my($disk, $level, $listdir) = @_;
130 open3(\*WTRFH, '>&STDOUT',\*ESTIMATE,"$gnutar --create --directory $disk --listed-incremental ${gnulist}/${listdir}_${level}.new --sparse --one-file-system --ignore-failed-read --totals --file /dev/null .");
133 print DEBUG "READ: $_" if ($debug == 1);
134 print DEBUG "STDOUT: $_" if ($debug == 1);
140 unlink "${gnulist}/${listdir}_${level}.new";
143 sub command_estimate_parse {
144 my($size) = parse_estimate(STDIN);
153 print DEBUG "READ: $_" if ($debug == 1);
154 if ($_ =~ /^Total bytes written: (\d*)$/) {
165 print DEBUG "STDOUT: -1 -1\n" if ($debug == 1);
170 my($ksize) = $size / 1024;
171 print DEBUG "STDOUT: $ksize 1024\n" if ($debug == 1);
172 print "$ksize 1024\n";
176 sub command_backup_full {
178 command_backup_level(0, $disk);
181 sub command_backup_level {
182 my($level, $disk) = @_;
183 my($listdir) = "$host$disk";
185 $listdir =~ s/\//_/g;
188 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
189 close(GNULIST) || die();
192 my($prev_level) = $level - 1;
193 copy("${gnulist}/${listdir}_${prev_level}",
194 "${gnulist}/${listdir}_${level}.new");
197 if($option_index_direct == 1 || $option_index_parse == 1) {
198 $verbose = "--verbose";
200 my($cmd) = "$gnutar --create $verbose --directory $disk --listed-incremental ${gnulist}/${listdir}_${level}.new --sparse --one-file-system --ignore-failed-read --totals --file - .";
202 if($option_backup_parse == 1 && $option_index_direct == 0 &&
203 $option_index_parse == 0) {
207 open3(\*WTRFH, '>&STDOUT', \*INDEX, $cmd) || die();
209 if($option_index_direct == 1 || $option_index_parse == 1) {
210 open(INDEXOUT, '>&=3') || die();
211 parse_backup(INDEX, STDERR, INDEXOUT);
215 parse_backup(INDEX, STDERR, undef);
221 if(!defined($option_no_record)) {
222 rename "${gnulist}/${listdir}_${level}.new",
223 "${gnulist}/${listdir}_${level}";
226 unlink "${gnulist}/${listdir}_${level}.new";
231 #sub command_backup_diff {
234 sub command_backup_parse {
235 $option_backup_direct = 1;
236 $option_backup_parse = 0;
237 parse_backup(STDIN, STDOUT, undef);
242 my($fhin, $fhout, $indexout) = @_;
245 print DEBUG "READ: $_" if ($debug == 1);
247 if(defined($indexout)) {
248 if($option_index_direct == 1) {
250 print DEBUG "INDEXOUT: $_" if ($debug == 1);
253 elsif($option_index_parse == 1) {
254 print DEBUG "INDEXOUT: $_" if ($debug == 1);
260 if (/^Total bytes written: (\d*)$/) {
262 if(defined($fhout) && $option_backup_parse == 1) {
263 print DEBUG "FHOUT: $_" if ($debug == 1);
267 elsif(defined($fhout)) {
268 if($option_backup_direct == 1) {
269 print DEBUG "FHOUT: $_" if ($debug == 1);
272 elsif($option_backup_parse == 1) {
273 print DEBUG "FHOUT: $_" if ($debug == 1);
279 if(defined($fhout) && $option_backup_direct == 1) {
281 print DEBUG "FHOUT: $command -1 -1\n" if ($debug == 1);
282 print $fhout "$command -1 -1\n";
285 my($ksize) = $size/1024;
286 print DEBUG "FHOUT: $ksize 1024\n" if ($debug == 1);
287 print $fhout "$ksize 1024\n";
292 sub command_index_from_output {
293 index_from_output(STDIN, STDOUT);
297 sub index_from_output {
298 my($fhin, $fhout) = @_;
301 print DEBUG "READ: $_" if ($debug == 1);
302 next if /^Total bytes written:/;
305 print DEBUG "FHOUT: $_" if ($debug == 1);
310 sub command_index_from_image {
311 open(INDEX, "$gnutar --list --file - |") || die();
312 index_from_output(INDEX, STDOUT);
315 #sub command_restore {
318 sub command_print_command {
321 require "generic-dumper"