Run pre and post backup commands for scheduled backups run manually.
authorJamie Cameron <jcameron@webmin.com>
Sat, 12 Mar 2011 18:21:58 +0000 (10:21 -0800)
committerJamie Cameron <jcameron@webmin.com>
Sat, 12 Mar 2011 18:21:58 +0000 (10:21 -0800)
https://sourceforge.net/tracker/index.php?func=detail&aid=3207620&group_id=17457&atid=117457#

backup-config/CHANGELOG
backup-config/save.cgi

index bed36ce..927a688 100644 (file)
@@ -20,3 +20,5 @@ Backup files are now given 600 permissions, to prevent reading by non-root users
 Added an option on the restore form to just show the contents of a backup.
 ---- Changes since 1.510 ----
 Added fields to the scheduled backup page for pre and post backup commands.
+---- Changes since 1.530 ----
+When a scheduled backup is run manually, and pre and post commands are now also run.
index e1d3602..1c70440 100755 (executable)
@@ -67,12 +67,29 @@ else {
 if ($in{'run'}) {
        # Execute the backup now
        &ui_print_unbuffered_header(undef, $text{'run_title'}, "");
+
+       # Run the pre-backup command, if any
+       if ($backup->{'pre'} =~ /\S/) {
+               $preout = &backquote_command(
+                       "($backup->{'pre'}) 2>&1 </dev/null");
+               print &text('email_pre',
+                       "<tt>".&html_escape($backup->{'pre'})."</tt>")."<br>\n".
+                       "<pre>".&html_escape($preout)."</pre>\n";
+               if ($?) {
+                       $err = $text{'email_prefailed'};
+                       }
+               }
+
        @mods = split(/\s+/, $backup->{'mods'});
        $nice = &nice_dest($backup->{'dest'}, 1);
-       print &text('run_doing', scalar(@mods), "<tt>$nice</tt>"),"<br>\n";
-       $err = &execute_backup(\@mods, $backup->{'dest'}, \$size, undef,
-                              $backup->{'configfile'}, $backup->{'nofiles'},
-                              [ split(/\t+/, $backup->{'others'}) ]);
+       if (!$err) {
+               print &text('run_doing', scalar(@mods),
+                           "<tt>$nice</tt>"),"<br>\n";
+               $err = &execute_backup(
+                       \@mods, $backup->{'dest'}, \$size, undef,
+                       $backup->{'configfile'}, $backup->{'nofiles'},
+                       [ split(/\t+/, $backup->{'others'}) ]);
+               }
        if ($err) {
                print "<pre>$err</pre>";
                print "$text{'run_failed'}<p>\n";
@@ -80,6 +97,16 @@ if ($in{'run'}) {
        else {
                print "$text{'run_ok'}<p>\n";
                }
+
+       # Run the post-backup command, if any
+       if (!$err && $backup->{'post'} =~ /\S/) {
+               $postout = &backquote_command(
+                       "($backup->{'post'}) 2>&1 </dev/null");
+               print &text('email_post',
+                     "<tt>".&html_escape($backup->{'post'})."</tt>")."<br>\n".
+                     "<pre>".&html_escape($postout)."</pre>\n";
+               }
+
        &webmin_log("run", "backup", $backup->{'dest'}, $backup);
        &ui_print_footer("edit.cgi?id=$in{'id'}", $text{'edit_return'},
                         "index.cgi?mode=sched", $text{'index_return'});