- if (!-d $_ARCHIVE_DIR_RESTORE) {
- mkdir($_ARCHIVE_DIR_RESTORE) or die("could not create archive WAL directory: $!");
- }
- my $status;
- if ($self->{'args'}->{'level'} > 0) {
- debug("extracting incremental backup to $cur_dir/$_ARCHIVE_DIR_RESTORE");
- $status = system($self->{'args'}->{'gnutar-path'}, '--extract',
- '--file', '-',
- '--ignore-zeros',
- '--exclude', 'empty-incremental',
- '--directory', $_ARCHIVE_DIR_RESTORE) >> 8;
- (0 == $status) or die("Failed to extract level $self->{'args'}->{'level'} backup (exit status: $status)");
- } else {
- debug("extracting base of full backup");
- if (!-d $_DATA_DIR_RESTORE) {
- mkdir($_DATA_DIR_RESTORE) or die("could not create archive WAL directory: $!");
- }
- $status = system($self->{'args'}->{'gnutar-path'}, '--extract', '--file', '-',) >> 8;
- (0 == $status) or die("Failed to extract base backup (exit status: $status)");
-
- debug("extracting archive dir to $cur_dir/$_ARCHIVE_DIR_RESTORE");
- $status = system($self->{'args'}->{'gnutar-path'}, '--extract',
- '--exclude', 'empty-incremental',
- '--file', $_ARCHIVE_DIR_TAR, '--directory', $_ARCHIVE_DIR_RESTORE) >> 8;
- (0 == $status) or die("Failed to extract archived WAL files from base backup (exit status: $status)");
- unlink($_ARCHIVE_DIR_TAR);
-
- debug("extracting data dir to $cur_dir/$_DATA_DIR_RESTORE");
- $status = system($self->{'args'}->{'gnutar-path'}, '--extract',
- '--file', $_DATA_DIR_TAR, '--directory', $_DATA_DIR_RESTORE) >> 8;
- (0 == $status) or die("Failed to extract data directory from base backup (exit status: $status)");
- unlink($_DATA_DIR_TAR);
- }
+ if (!-d $_ARCHIVE_DIR_RESTORE) {
+ mkdir($_ARCHIVE_DIR_RESTORE) or die("could not create archive WAL directory: $!");
+ }
+ my $status;
+ if ($self->{'args'}->{'level'} > 0) {
+ debug("extracting incremental backup to $cur_dir/$_ARCHIVE_DIR_RESTORE");
+ $status = system($self->{'args'}->{'gnutar-path'},
+ '--extract',
+ '--file', '-',
+ '--ignore-zeros',
+ '--exclude', 'empty-incremental',
+ '--directory', $_ARCHIVE_DIR_RESTORE) >> 8;
+ (0 == $status) or die("Failed to extract level $self->{'args'}->{'level'} backup (exit status: $status)");
+ } else {
+ debug("extracting base of full backup to $cur_dir/$_DATA_DIR_RESTORE");
+ debug("extracting archive dir to $cur_dir/$_ARCHIVE_DIR_RESTORE");
+ if (!-d $_DATA_DIR_RESTORE) {
+ mkdir($_DATA_DIR_RESTORE) or die("could not create archive WAL directory: $!");
+ }
+ my @cmd = ($self->{'args'}->{'gnutar-path'}, '--extract',
+ '--file', '-',
+ '--ignore-zero',
+ '--transform', "s,^DATA/,$_DATA_DIR_RESTORE/,S",
+ '--transform', "s,^WAL/,$_ARCHIVE_DIR_RESTORE/,S");
+ debug("run: " . join ' ',@cmd);
+ $status = system(@cmd) >> 8;
+ (0 == $status) or die("Failed to extract base backup (exit status: $status)");
+
+ if (-f $_ARCHIVE_DIR_TAR) {
+ debug("extracting archive dir to $cur_dir/$_ARCHIVE_DIR_RESTORE");
+ my @cmd = ($self->{'args'}->{'gnutar-path'}, '--extract',
+ '--exclude', 'empty-incremental',
+ '--file', $_ARCHIVE_DIR_TAR, '--directory',
+ $_ARCHIVE_DIR_RESTORE);
+ debug("run: " . join ' ',@cmd);
+ $status = system(@cmd) >> 8;
+ (0 == $status) or die("Failed to extract archived WAL files from base backup (exit status: $status)");
+ if (unlink($_ARCHIVE_DIR_TAR) == 0) {
+ debug("Failed to unlink '$_ARCHIVE_DIR_TAR': $!");
+ $self->print_to_server(
+ "Failed to unlink '$_ARCHIVE_DIR_TAR': $!",
+ $Amanda::Script_App::ERROR);
+ }
+ }
+
+ if (-f $_DATA_DIR_TAR) {
+ debug("extracting data dir to $cur_dir/$_DATA_DIR_RESTORE");
+ my @cmd = ($self->{'args'}->{'gnutar-path'}, '--extract',
+ '--file', $_DATA_DIR_TAR,
+ '--directory', $_DATA_DIR_RESTORE);
+ debug("run: " . join ' ',@cmd);
+ $status = system(@cmd) >> 8;
+ (0 == $status) or die("Failed to extract data directory from base backup (exit status: $status)");
+ if (unlink($_DATA_DIR_TAR) == 0) {
+ debug("Failed to unlink '$_DATA_DIR_TAR': $!");
+ $self->print_to_server("Failed to unlink '$_DATA_DIR_TAR': $!",
+ $Amanda::Script_App::ERROR);
+ }
+ }
+ }