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@/amgtar.$$.debug") if ($debug==1);
24 $exec_prefix="@exec_prefix@";
25 $exec_prefix=$exec_prefix;
26 $amlibexecdir="@amlibexecdir@";
27 $amlibexecdir=$amlibexecdir;
29 $USE_VERSION_SUFFIXES='@USE_VERSION_SUFFIXES@';
31 if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
37 $runtar="${amlibexecdir}/runtar${suf}";
38 $gnulist = '@GNUTAR_LISTED_INCREMENTAL_DIR@';
58 #$user_selfcheck = "";
59 #$group_selfcheck = "";
62 #$group_estimate = "";
64 #$user_estimate_parse = "";
65 #$group_estimate_parse = "";
67 $user_backup = "root";
70 #$user_backup_parse = "";
71 #$group_backup_parse = "";
73 #$user_index_from_output = "";
74 #$group_index_from_output = "";
76 #$user_index_from_image = "";
77 #$group_index_from_image = "";
82 #$user_print_command = "";
83 #$group_print_command = "";
85 $user_default = "amanda";
86 $group_default = "amanda";
90 my($config, $host, $disk, $device, $level) = @_;
92 print DEBUG "STDOUT: CONFIG YES\n" if ($debug == 1);
94 print DEBUG "STDOUT: HOST YES\n" if ($debug == 1);
96 print DEBUG "STDOUT: DISK YES\n" if ($debug == 1);
97 print "MAX-LEVEL 9\n";
98 print DEBUG "STDOUT: MAX-LEVEL 9\n" if ($debug == 1);
99 print "INDEX-LINE YES\n";
100 print DEBUG "STDOUT: INDEX-LINE YES\n" if ($debug == 1);
101 print "INDEX-XML NO\n";
102 print DEBUG "STDOUT: INDEX-XML NO\n" if ($debug == 1);
103 print "MESSAGE-LINE YES\n";
104 print DEBUG "STDOUT: MESSAGE-LINE YES\n" if ($debug == 1);
105 print "MESSAGE-XML NO\n";
106 print DEBUG "STDOUT: MESSAGE-XML NO\n" if ($debug == 1);
107 print "RECORD YES\n";
108 print DEBUG "STDOUT: RECORD YES\n" if ($debug == 1);
109 print "INCLUDE-FILE YES\n";
110 print "INCLUDE-LIST YES\n";
111 print "EXCLUDE-FILE YES\n";
112 print "EXCLUDE-LIST YES\n";
113 print "COLLECTION NO\n";
116 sub command_selfcheck {
117 my($config, $host, $disk, $device, $level) = @_;
118 print DEBUG "STDOUT: OK $disk\n" if ($debug == 1);
119 print DEBUG "STDOUT: OK $device\n" if ($debug == 1);
121 print "OK $device\n";
125 #check property include/exclude
128 sub command_estimate {
129 my($config, $host, $disk, $device, $level) = @_;
130 my($listdir) = "$host$disk";
131 $listdir =~ s/\//_/g;
133 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
134 close(GNULIST) || die();
137 my($prev_level) = $level - 1;
138 if (-f "${gnulist}/${listdir}_${prev_level}") {
139 copy("${gnulist}/${listdir}_${prev_level}", "${gnulist}/${listdir}_${level}.new");
141 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
142 close(GNULIST) || die();
143 #print "ERROR file ${gnulist}/${listdir}_${level}.new doesn't exist\n";
146 command_estimate_opt_direct($config, $host, $disk, $device, $level, $listdir);
150 sub command_estimate_opt_direct {
151 my($config, $host, $disk, $device, $level, $listdir) = @_;
153 my(@cmd) = ($runtar, $config, $gnutar, "--create", "--directory", $device, "--listed-incremental", "${gnulist}/${listdir}_${level}.new", "--sparse", "--one-file-system", "--ignore-failed-read", "--totals", "--file", "/dev/null", ".");
154 #my(@cmd) = ($gnutar, "--create", "--directory", $device, "--listed-incremental", "${gnulist}/${listdir}_${level}.new", "--sparse", "--one-file-system", "--ignore-failed-read", "--totals", "--file", "/dev/null", ".");
155 print DEBUG "cmd:" , join(" ", @cmd), "\n" if ($debug == 1);
156 open3(\*WTRFH, '>&STDOUT', \*ESTIMATE, @cmd);
158 $size = parse_estimate(ESTIMATE);
161 unlink "${gnulist}/${listdir}_${level}.new";
169 print DEBUG "READ 2: $_" if ($debug == 1);
170 if ($_ =~ /^Total bytes written: (\d*)/) {
181 print DEBUG "STDOUT A: -1 -1\n" if ($debug == 1);
186 my($ksize) = int $size / (1024);
187 $ksize=32 if ($ksize<32);
188 print DEBUG "STDOUT B: $ksize 1\n" if ($debug == 1);
194 my($config, $host, $disk, $device, $level) = @_;
195 my($listdir) = "$host$disk";
197 $listdir =~ s/\//_/g;
199 print DEBUG "config =" . $config . "\n" if ($debug == 1);
200 print DEBUG "host =" . $host . "\n" if ($debug == 1);
201 print DEBUG "disk =" . $disk . "\n" if ($debug == 1);
202 print DEBUG "device =" . $device . "\n" if ($debug == 1);
203 print DEBUG "level =" . $level . "\n" if ($debug == 1);
206 open(GNULIST, ">${gnulist}/${listdir}_${level}.new") || die();
207 close(GNULIST) || die();
210 my($prev_level) = $level - 1;
211 copy("${gnulist}/${listdir}_${prev_level}",
212 "${gnulist}/${listdir}_${level}.new");
215 if(defined($opt_index)) {
216 $verbose = "--verbose";
218 my(@cmd) = ($runtar, $config, $gnutar, "--create", $verbose, "--directory", $device, "--listed-incremental", "${gnulist}/${listdir}_${level}.new", "--sparse", "--one-file-system", "--ignore-failed-read", "--totals", "--file", "-", ".");
219 #my(@cmd) = ($gnutar, "--create", $verbose, "--directory", $device, "--listed-incremental", "${gnulist}/${listdir}_${level}.new", "--sparse", "--one-file-system", "--ignore-failed-read", "--totals", "--file", "-", ".");
221 print DEBUG "cmd:" , join(" ", @cmd), "\n" if ($debug == 1);
223 open3(\*WTRFH, '>&STDOUT', \*INDEX, @cmd) || die();
225 if(defined($opt_index)) {
226 open(INDEXOUT, '>&=3') || die();
227 parse_backup(INDEX, STDERR, INDEXOUT);
231 parse_backup(INDEX, STDERR, undef);
236 if(defined($opt_record)) {
237 rename "${gnulist}/${listdir}_${level}.new",
238 "${gnulist}/${listdir}_${level}";
241 unlink "${gnulist}/${listdir}_${level}.new";
247 my($fhin, $fhout, $indexout) = @_;
250 print DEBUG "READ 3: $_" if ($debug == 1);
252 if(defined($indexout)) {
253 if(defined($opt_index)) {
255 print DEBUG "INDEXOUT: $_" if ($debug == 1);
261 if (/^Total bytes written: (\d*)/) {
263 $ksize = int ($size / 1024);
265 elsif(defined($fhout)) {
266 next if /: Directory is new$/;
267 print DEBUG "FHOUT 2: $_" if ($debug == 1);
272 if(defined($fhout)) {
274 print DEBUG "FHOUT 4: $command -1 -1\n" if ($debug == 1);
275 print $fhout "$command -1 -1\n";
278 my($ksize) = int ($size/1024);
279 print DEBUG "FHOUT 5: sendbackup: size $ksize\n" if ($debug == 1);
280 print $fhout "sendbackup: size $ksize\n";
281 print DEBUG "FHOUT 5: sendbackup: end\n" if ($debug == 1);
282 print $fhout "sendbackup: end\n";
287 sub command_index_from_output {
288 index_from_output(STDIN, STDOUT);
292 sub index_from_output {
293 my($fhin, $fhout) = @_;
296 print DEBUG "READ 4: $_" if ($debug == 1);
297 next if /^Total bytes written:/;
300 print DEBUG "FHOUT 6: $_" if ($debug == 1);
305 sub command_index_from_image {
306 my($config, $host, $disk, $device, $level) = @_;
307 open(INDEX, "$gnutar --list --file - |") || die();
308 index_from_output(INDEX, STDOUT);
311 sub command_restore {
312 my($config, $host, $disk, $device, $level) = @_;
315 my(@cmd) = ($gnutar, "--numeric-owner", "-xpGvf", "-");
316 for($i=1;defined $ARGV[$i]; $i++) {
317 push @cmd, $ARGV[$i];
319 print DEBUG "cmd:" , join(" ", @cmd), "\n" if ($debug == 1);
323 sub command_print_command {
326 require "generic-dumper"