Add initial system backup toggle to remote setup form
When adding a new remote, a toggle lets the user immediately run gniza sysbackup against the new remote. The backup forks to background with output logged to /var/log/gniza/sysbackup-<name>.log. Toggle is hidden on edit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -295,13 +295,32 @@ sub handle_add {
|
||||
}
|
||||
GnizaWHM::UI::init_remote_dir(%init_args);
|
||||
|
||||
# Fork sysbackup if toggle is on
|
||||
my $sysbackup_msg = '';
|
||||
if ($form->{'sysbackup_toggle'}) {
|
||||
my $log_file = "/var/log/gniza/sysbackup-$name.log";
|
||||
my $pid = fork();
|
||||
if (defined $pid && $pid == 0) {
|
||||
# Child: detach and exec sysbackup
|
||||
close STDIN;
|
||||
close STDOUT;
|
||||
close STDERR;
|
||||
open STDIN, '<', '/dev/null';
|
||||
open STDOUT, '>', $log_file;
|
||||
open STDERR, '>&', \*STDOUT;
|
||||
exec '/usr/local/bin/gniza', 'sysbackup', "--remote=$name";
|
||||
exit 1;
|
||||
}
|
||||
$sysbackup_msg = ' System backup started in background.' if defined $pid;
|
||||
}
|
||||
|
||||
if ($form->{'wizard'}) {
|
||||
GnizaWHM::UI::set_flash('success', "Remote '$name' created. Now set up a schedule.");
|
||||
GnizaWHM::UI::set_flash('success', "Remote '$name' created. Now set up a schedule." . $sysbackup_msg);
|
||||
print "Status: 302 Found\r\n";
|
||||
print "Location: schedules.cgi?action=add&wizard=1&remote_name=" . _uri_escape($name) . "\r\n\r\n";
|
||||
exit;
|
||||
}
|
||||
GnizaWHM::UI::set_flash('success', "Remote '$name' created successfully.");
|
||||
GnizaWHM::UI::set_flash('success', "Remote '$name' created successfully." . $sysbackup_msg);
|
||||
print "Status: 302 Found\r\n";
|
||||
print "Location: remotes.cgi\r\n\r\n";
|
||||
exit;
|
||||
@@ -632,6 +651,19 @@ sub render_remote_form {
|
||||
_field($conf, 'RETENTION_COUNT', 'Snapshots to Keep', 'Default: 30');
|
||||
print qq{</div>\n</div>\n};
|
||||
|
||||
# Initial System Backup toggle (add mode only)
|
||||
unless ($is_edit) {
|
||||
my $sysbackup_checked = $form->{'sysbackup_toggle'} ? ' checked' : '';
|
||||
print qq{<div class="card bg-white shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
|
||||
print qq{<h2 class="card-title text-sm">Initial Backup</h2>\n};
|
||||
print qq{<div class="flex items-center gap-3 mb-2.5">\n};
|
||||
print qq{ <label class="w-44 font-medium text-sm" for="sysbackup_toggle">Run system backup</label>\n};
|
||||
print qq{ <input type="checkbox" class="toggle toggle-sm toggle-success" id="sysbackup_toggle" name="sysbackup_toggle" value="1"$sysbackup_checked>\n};
|
||||
print qq{</div>\n};
|
||||
print qq{<p class="text-xs text-base-content/60 mt-2">Backs up WHM/cPanel config, installed packages, and cron jobs to the new remote immediately after creation. Runs in the background.</p>\n};
|
||||
print qq{</div>\n</div>\n};
|
||||
}
|
||||
|
||||
# Submit
|
||||
print qq{<div class="flex gap-2 mt-4">\n};
|
||||
my $btn_label = $is_edit ? 'Save Changes' : 'Create Remote';
|
||||
|
||||
Reference in New Issue
Block a user