Option to just show contents of backup before restoring
authorJamie Cameron <jcameron@webmin.com>
Thu, 22 Oct 2009 05:46:30 +0000 (22:46 -0700)
committerJamie Cameron <jcameron@webmin.com>
Thu, 22 Oct 2009 05:46:30 +0000 (22:46 -0700)
backup-config/CHANGELOG
backup-config/backup-config-lib.pl
backup-config/index.cgi
backup-config/lang/en
backup-config/restore.cgi

index 30fade6..b6e2223 100644 (file)
@@ -16,3 +16,5 @@ When backing up or restoring from an FTP or SSH server, an optional port number
 ---- Changes since 1.440 ----
 Converted commands in the module's API file to POD format, and added more details about each function.
 Backup files are now given 600 permissions, to prevent reading by non-root users.
+---- Changes since 1.490 ----
+Added an option on the restore form to just show the contents of a backup.
index 0e526d7..2d1c824 100755 (executable)
@@ -415,7 +415,7 @@ elsif ($mode == 2) {
 return undef;
 }
 
-=head2 execute_restore(&mods, source, &files, apply)
+=head2 execute_restore(&mods, source, &files, apply, [show-only])
 
 Restore configuration files from the specified source for the listed modules.
 Returns undef on success, or an error message.
@@ -521,7 +521,7 @@ foreach my $m (@{$_[0]}) {
 
 # Call module pre functions
 foreach my $m (@{$_[0]}) {
-       if ($m && &foreign_check($m)) {
+       if ($m && &foreign_check($m) && !$_[4]) {
                &foreign_require($m, "backup_config.pl");
                if (&foreign_defined($m, "pre_restore")) {
                        local $err = &foreign_call($m, "pre_restore", \@files);
@@ -534,27 +534,33 @@ foreach my $m (@{$_[0]}) {
        }
 
 # Lock all files being extracted
-local $f;
-foreach $f (@files) {
-       &lock_file($f);
+if (!$_[4]) {
+       local $f;
+       foreach $f (@files) {
+               &lock_file($f);
+               }
        }
 
 # Extract contents (only files specified by manifests)
+local $flag = $_[4] ? "t" : "x";
 local $qfiles = join(" ", map { s/^\///; quotemeta($_) }
                                &unique(@files));
 if ($gzipped) {
-       &execute_command("cd / ; gunzip -c $qfile | tar xf - $qfiles",
+       &execute_command("cd / ; gunzip -c $qfile | tar ${flag}f - $qfiles",
                         undef, \$out, \$out);
        }
 else {
-       &execute_command("cd / ; tar xf $qfile $qfiles", undef, \$out, \$out);
+       &execute_command("cd / ; tar ${flag}f $qfile $qfiles",
+                        undef, \$out, \$out);
        }
 local $ex = $?;
 
 # Un-lock all files being extracted
-local $f;
-foreach $f (@files) {
-       &unlock_file($f);
+if (!$_[4]) {
+       local $f;
+       foreach $f (@files) {
+               &unlock_file($f);
+               }
        }
 
 # Check for tar error
@@ -563,7 +569,7 @@ if ($ex) {
        return &text('backup_euntar', "<pre>$out</pre>");
        }
 
-if ($_[3]) {
+if ($_[3] && !$_[4]) {
        # Call all module apply functions
        foreach $m (@{$_[0]}) {
                if (&foreign_defined($m, "post_restore")) {
index 087fb9e..7febafb 100755 (executable)
@@ -87,9 +87,10 @@ print &ui_table_row($text{'edit_dest2'},
                    &show_backup_destination("src", $config{'dest'}, 1));
 
 print &ui_table_row($text{'index_apply'},
-                   &ui_radio("apply", $config{'apply'} ? 1 : 0,
-                             [ [ 1, $text{'yes'} ],
-                               [ 0, $text{'no'} ] ]));
+                   &ui_yesno_radio("apply", $config{'apply'} ? 1 : 0));
+
+print &ui_table_row($text{'index_test'},
+                   &ui_yesno_radio("test", 0));
 
 print &ui_table_end();
 print &ui_form_end([ [ 'restore', $text{'index_now2'} ] ]);
index ddbbc20..81fcfb4 100644 (file)
@@ -14,6 +14,7 @@ index_return2=backup and restore forms
 index_header2=Restore configuration now
 index_now2=Restore Now
 index_apply=Apply configurations?
+index_test=Just show what will be restored?
 index_jobs=Scheduled Backups
 index_nostrftime=Warning - some backup jobs use % in their filenames, but strftime substitution is not enabled on the Module Config page.
 index_tabsched=Scheduled backups
@@ -80,8 +81,10 @@ backup_done=.. complete. Final backup size was $1, containing $2 files.
 restore_err=Restore failed
 restore_title=Restore Configuration
 restore_doing=Starting restore of module configuration files from $1 ..
+restore_testing=Extracting contents of backup from $1 ..
 restore_failed=.. failed! $1
 restore_done=.. complete. $1 files were restored.
+restore_done2=.. files in the backup are :
 
 nice_ftp=$2 on $1 via FTP
 nice_ftpp=$2 on $1 port $3 via FTP
index 826c9df..7bb952b 100755 (executable)
@@ -21,12 +21,20 @@ if ($mode == 3) {
        $src = $temp;
        }
 &ui_print_header(undef, $text{'restore_title'}, "");
-print &text('restore_doing', &nice_dest($src)),"<p>\n";
-$err = &execute_restore(\@mods, $src, \@files, $in{'apply'});
+print &text($in{'test'} ? 'restore_testing' : 'restore_doing',
+           &nice_dest($src)),"<p>\n";
+$err = &execute_restore(\@mods, $src, \@files, $in{'apply'}, $in{'test'});
 &unlink_file($temp) if ($mode == 3);
 if ($err) {
        print &text('restore_failed', $err),"<p>\n";
        }
+elsif ($in{'test'}) {
+       print $text{'restore_done2'},"<p>\n";
+       print &ui_table_start(undef, "width=100%", 2);
+       print &ui_table_row(undef,
+           "<pre>".join("\n", map { &html_escape($_) } @files)."</pre>", 2);
+       print &ui_table_end();
+       }
 else {
        print &text('restore_done', scalar(@files)),"<p>\n";
        }