5 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
6 & eval 'exec @PERL@ -S $0 $argv:q'
10 push(@INC, "@DUMPER_DIR@");
17 open(DEBUG,">>@AMANDA_DBGDIR@/gnutar.$$.debug") if ($debug==1);
20 $exec_prefix="@exec_prefix@";
21 $libexecdir="@libexecdir@";
22 $USE_VERSION_SUFFIXES='@USE_VERSION_SUFFIXES@';
24 if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
30 $runtar="${libexecdir}/runtar${suf}";
31 $gnulist = '@GNUTAR_LISTED_INCREMENTAL_DIR@';
36 $level_incrementals = 9;
38 @index_generation = ("direct","parse","output","image");
39 @parse_estimate = ("direct","parse");
40 @parse_backup = ("direct","parse");
41 @backup_type = ("full","level","diff");
47 #$user_selfcheck = "";
48 #$group_selfcheck = "";
51 #$group_estimate = "";
53 #$user_estimate_parse = "";
54 #$group_estimate_parse = "";
56 $user_backup = "root";
59 #$user_backup_parse = "";
60 #$group_backup_parse = "";
62 #$user_index_from_output = "";
63 #$group_index_from_output = "";
65 #$user_index_from_image = "";
66 #$group_index_from_image = "";
71 #$user_print_command = "";
72 #$group_print_command = "";
74 $user_default = "amanda";
75 $group_default = "amanda";
78 sub command_selfcheck {
79 print DEBUG "STDOUT: OK selfcheck\n" if ($debug == 1);
80 print "OK selfcheck\n";
83 sub command_estimate_full {
85 command_estimate_level(0, $disk);
88 sub command_estimate_level {
89 my($level, $disk) = @_;
90 my($listdir) = "$host$disk";
93 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
94 close(GNULIST) || die();
97 my($prev_level) = $level - 1;
98 copy("${gnulist}/${listdir}_${prev_level}", "${gnulist}/${listdir}_${level}.new");
100 if($option_estimate_direct == 1) {
101 command_estimate_opt_direct($disk, $level, $listdir);
104 command_estimate_opt_parse($disk, $level, $listdir);
108 #sub command_estimate_diff {
111 sub command_estimate_opt_direct {
112 my($disk, $level, $listdir) = @_;
114 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);
115 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();
117 $size = parse_estimate(ESTIMATE);
120 unlink "${gnulist}/${listdir}_${level}.new";
124 sub command_estimate_opt_parse {
125 my($disk, $level, $listdir) = @_;
127 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 .");
130 print DEBUG "READ: $_" if ($debug == 1);
131 print DEBUG "STDOUT: $_" if ($debug == 1);
137 unlink "${gnulist}/${listdir}_${level}.new";
140 sub command_estimate_parse {
141 my($size) = parse_estimate(STDIN);
150 print DEBUG "READ: $_" if ($debug == 1);
151 if ($_ =~ /^Total bytes written: (\d*)$/) {
162 print DEBUG "STDOUT: -1 -1\n" if ($debug == 1);
167 my($ksize) = $size / 1024;
168 print DEBUG "STDOUT: $ksize 1024\n" if ($debug == 1);
169 print "$ksize 1024\n";
173 sub command_backup_full {
175 command_backup_level(0, $disk);
178 sub command_backup_level {
179 my($level, $disk) = @_;
180 my($listdir) = "$host$disk";
182 $listdir =~ s/\//_/g;
185 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
186 close(GNULIST) || die();
189 my($prev_level) = $level - 1;
190 copy("${gnulist}/${listdir}_${prev_level}",
191 "${gnulist}/${listdir}_${level}.new");
194 if($option_index_direct == 1 || $option_index_parse == 1) {
195 $verbose = "--verbose";
197 my($cmd) = "$gnutar --create $verbose --directory $disk --listed-incremental ${gnulist}/${listdir}_${level}.new --sparse --one-file-system --ignore-failed-read --totals --file - .";
199 if($option_backup_parse == 1 && $option_index_direct == 0 &&
200 $option_index_parse == 0) {
204 open3(\*WTRFH, '>&STDOUT', \*INDEX, $cmd) || die();
206 if($option_index_direct == 1 || $option_index_parse == 1) {
207 open(INDEXOUT, '>&=3') || die();
208 parse_backup(INDEX, STDERR, INDEXOUT);
212 parse_backup(INDEX, STDERR, undef);
218 if(!defined($option_no_record)) {
219 rename "${gnulist}/${listdir}_${level}.new",
220 "${gnulist}/${listdir}_${level}";
223 unlink "${gnulist}/${listdir}_${level}.new";
228 #sub command_backup_diff {
231 sub command_backup_parse {
232 $option_backup_direct = 1;
233 $option_backup_parse = 0;
234 parse_backup(STDIN, STDOUT, undef);
239 my($fhin, $fhout, $indexout) = @_;
242 print DEBUG "READ: $_" if ($debug == 1);
244 if(defined($indexout)) {
245 if($option_index_direct == 1) {
247 print DEBUG "INDEXOUT: $_" if ($debug == 1);
250 elsif($option_index_parse == 1) {
251 print DEBUG "INDEXOUT: $_" if ($debug == 1);
257 if (/^Total bytes written: (\d*)$/) {
259 if(defined($fhout) && $option_backup_parse == 1) {
260 print DEBUG "FHOUT: $_" if ($debug == 1);
264 elsif(defined($fhout)) {
265 if($option_backup_direct == 1) {
266 print DEBUG "FHOUT: $_" if ($debug == 1);
269 elsif($option_backup_parse == 1) {
270 print DEBUG "FHOUT: $_" if ($debug == 1);
276 if(defined($fhout) && $option_backup_direct == 1) {
278 print DEBUG "FHOUT: $command -1 -1\n" if ($debug == 1);
279 print $fhout "$command -1 -1\n";
282 my($ksize) = $size/1024;
283 print DEBUG "FHOUT: $ksize 1024\n" if ($debug == 1);
284 print $fhout "$ksize 1024\n";
289 sub command_index_from_output {
290 index_from_output(STDIN, STDOUT);
294 sub index_from_output {
295 my($fhin, $fhout) = @_;
298 print DEBUG "READ: $_" if ($debug == 1);
299 next if /^Total bytes written:/;
302 print DEBUG "FHOUT: $_" if ($debug == 1);
307 sub command_index_from_image {
308 open(INDEX, "$gnutar --list --file - |") || die();
309 index_from_output(INDEX, STDOUT);
312 #sub command_restore {
315 sub command_print_command {
318 require "generic-dumper"