2007-04-12 20:24:50 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# backup_form.cgi
|
|
|
|
# Display a form for backing up this database, or all databases
|
|
|
|
|
|
|
|
require './mysql-lib.pl';
|
|
|
|
&ReadParse();
|
|
|
|
if ($in{'all'}) {
|
|
|
|
@alldbs = &list_databases();
|
|
|
|
@dbs = grep { &can_edit_db($_) } @alldbs;
|
|
|
|
@alldbs == @dbs || &error($text{'dbase_ecannot'});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
|
|
|
|
}
|
|
|
|
$access{'edonly'} && &error($text{'dbase_ecannot'});
|
|
|
|
$access{'buser'} || &error($text{'dbase_ecannot'});
|
2007-09-29 22:16:17 +00:00
|
|
|
&ui_print_header(undef, $in{'all'} ? $text{'backup_title2'}
|
|
|
|
: $text{'backup_title'}, "",
|
2007-04-12 20:24:50 +00:00
|
|
|
"backup_form");
|
|
|
|
|
2014-11-19 22:06:52 -08:00
|
|
|
($cmd) = split(/\s+/, $config{'mysqldump'});
|
|
|
|
if (!-x $cmd) {
|
|
|
|
print &text('backup_edump', "<tt>$cmd</tt>",
|
2007-09-29 22:16:17 +00:00
|
|
|
"../config.cgi?$module_name"),"<p>\n";
|
2007-04-12 20:24:50 +00:00
|
|
|
&ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'});
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cron = !$module_info{'usermin'} && $access{'buser'} eq 'root' &&
|
|
|
|
!$access{'user'} && &foreign_installed("cron");
|
|
|
|
if ($in{'all'}) {
|
|
|
|
print "$text{'backup_desc3'}\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print &text('backup_desc', "<tt>$in{'db'}</tt>"),"\n";
|
|
|
|
}
|
|
|
|
if ($cron) {
|
|
|
|
print "$text{'backup_desc2'}\n";
|
|
|
|
}
|
|
|
|
print "<p>\n";
|
|
|
|
%c = $module_info{'usermin'} ? %userconfig : %config;
|
|
|
|
|
2016-08-20 18:46:34 -07:00
|
|
|
$download = $in{'all'} ? 'database' : $in{'db'};
|
|
|
|
print &ui_form_start("backup_db.cgi/$download.sql", "post");
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_hidden("db", $in{'db'});
|
|
|
|
print &ui_hidden("all", $in{'all'});
|
2009-02-26 19:26:19 +00:00
|
|
|
print &ui_hidden_table_start($text{'backup_header1'}, "width=100%", 2, "main",
|
|
|
|
1, [ "width=30%" ]);
|
2007-04-12 20:24:50 +00:00
|
|
|
|
2007-09-29 22:16:17 +00:00
|
|
|
# Destination file or directory
|
2018-12-24 12:48:03 -08:00
|
|
|
if ($in{'all'}) {
|
|
|
|
print &ui_table_row($text{'backup_file2'},
|
|
|
|
&ui_textbox("file", $c{'backup_'.$in{'db'}}, 60)." ".
|
|
|
|
&file_chooser_button("file"));
|
2019-04-12 16:27:57 -07:00
|
|
|
print &ui_table_row($text{'backup_prefix'},
|
2019-11-27 13:12:11 -08:00
|
|
|
&ui_opt_textbox("prefix", $c{'backup_prefix_'}, 10,
|
2019-04-12 16:27:57 -07:00
|
|
|
$text{'backup_noprefix'}));
|
2018-12-24 12:48:03 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
print &ui_table_row($text{'backup_file'},
|
|
|
|
&ui_radio_table("dest", 0,
|
2016-08-20 18:46:34 -07:00
|
|
|
[ [ 1, $text{'backup_download'} ],
|
|
|
|
[ 0, $text{'backup_path'},
|
|
|
|
&ui_textbox("file", $c{'backup_'.$in{'db'}}, 60)." ".
|
|
|
|
&file_chooser_button("file") ] ]));
|
2018-12-24 12:48:03 -08:00
|
|
|
}
|
2007-09-29 22:16:17 +00:00
|
|
|
|
|
|
|
# Create destination dir
|
2007-04-12 20:24:50 +00:00
|
|
|
if ($in{'all'}) {
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_mkdir'},
|
|
|
|
&ui_yesno_radio("mkdir", int($c{'backup_mkdir_'.$in{'db'}})));
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$in{'all'}) {
|
|
|
|
# Show input to select tables
|
|
|
|
$t = $c{'backup_tables_'.$in{'db'}};
|
|
|
|
@tables = &list_tables($in{'db'});
|
2014-05-12 09:20:45 -07:00
|
|
|
if (@tables) {
|
|
|
|
print &ui_table_row($text{'backup_tables'},
|
|
|
|
&ui_radio("tables_def", $t ? 0 : 1,
|
|
|
|
[ [ 1, $text{'backup_alltables'} ],
|
|
|
|
[ 0, $text{'backup_seltables'} ] ])."<br>".
|
|
|
|
&ui_select("tables", [ split(/\s+/, $t) ],
|
|
|
|
[ sort @tables ], 5, 1));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print &ui_hidden("tables_def", 1);
|
|
|
|
}
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_hidden_table_end("main");
|
2009-02-26 19:26:19 +00:00
|
|
|
print &ui_hidden_table_start($text{'backup_header2'}, "width=100%", 2, "opts",
|
|
|
|
0, [ "width=30%" ]);
|
2007-09-29 22:16:17 +00:00
|
|
|
|
2007-04-12 20:24:50 +00:00
|
|
|
# Show input for where clause
|
|
|
|
$w = $c{'backup_where_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_where'},
|
|
|
|
&ui_opt_textbox("where", $w, 30, $text{'backup_none'}));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
# Show option to include drop statements in SQL
|
|
|
|
$d = $c{'backup_drop_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_drop'},
|
|
|
|
&ui_yesno_radio("drop", $d ? 1 : 0));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
# Show input for character set
|
2023-10-11 21:02:17 -07:00
|
|
|
$dbc = $in{'db'} ? &get_character_set($in{'db'}) : "";
|
|
|
|
$s = $c{'backup_charset_'.$in{'db'}} || $c{'charset'} || $dbc;
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_charset'},
|
|
|
|
&ui_radio("charset_def", $s ? 0 : 1,
|
2007-04-12 20:24:50 +00:00
|
|
|
[ [ 1, $text{'default'} ],
|
|
|
|
[ 0, &ui_select("charset", $s,
|
2007-09-29 22:16:17 +00:00
|
|
|
[ &list_character_sets($in{'db'}) ]) ] ]));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
2019-02-18 16:44:21 -08:00
|
|
|
if (&compare_version_numbers($mysql_version, "5.0") >= 0) {
|
2017-11-02 21:58:43 +08:00
|
|
|
# Show compatibility format option
|
2007-04-12 20:24:50 +00:00
|
|
|
$cf = $c{'backup_compatible_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_compatible'},
|
|
|
|
&ui_radio("compatible_def", $cf ? 0 : 1,
|
2007-04-12 20:24:50 +00:00
|
|
|
[ [ 1, $text{'default'} ],
|
|
|
|
[ 0, &text('backup_compwith',
|
|
|
|
&ui_select("compatible", $cf,
|
2007-09-29 22:16:17 +00:00
|
|
|
[ &list_compatible_formats() ])) ] ]));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
%co = map { $_, 1 } split(/\s+/, $c{'backup_options_'.$in{'db'}});
|
2007-09-29 22:16:17 +00:00
|
|
|
$opts = "";
|
2007-04-12 20:24:50 +00:00
|
|
|
foreach $o (&list_compatible_options()) {
|
2007-09-29 22:16:17 +00:00
|
|
|
$opts .= &ui_checkbox("options", $o->[0], $o->[1] || $o->[0],
|
|
|
|
$co{$o->[0]})."<br>\n";
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_options'}, $opts);
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
print &ui_hidden("compatible_def", 1),"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# Show compression option
|
|
|
|
$cp = int($c{'backup_compress_'.$in{'db'}});
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_compress'},
|
|
|
|
&ui_radio("compress", $cp,
|
2007-04-12 20:24:50 +00:00
|
|
|
[ [ 0, $text{'backup_cnone'} ],
|
|
|
|
[ 1, $text{'backup_gzip'} ],
|
2007-09-29 22:16:17 +00:00
|
|
|
[ 2, $text{'backup_bzip2'} ] ]));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
2010-02-01 15:44:43 -08:00
|
|
|
# Show single-transaction option
|
|
|
|
$s = $c{'backup_single_'.$in{'db'}};
|
|
|
|
print &ui_table_row($text{'backup_single'},
|
|
|
|
&ui_yesno_radio("single", $s ? 1 : 0));
|
|
|
|
|
2012-01-13 14:00:10 -08:00
|
|
|
# Show quick dump mode
|
|
|
|
$q = $c{'backup_quick_'.$in{'db'}};
|
|
|
|
print &ui_table_row($text{'backup_quick'},
|
|
|
|
&ui_yesno_radio("quick", $q ? 1 : 0));
|
|
|
|
|
2021-08-12 09:29:02 +01:00
|
|
|
# Allow user to specify custom backup parameters
|
|
|
|
$b = $c{'backup_parameters_'.$in{'db'}};
|
|
|
|
print &ui_table_row($text{'backup_parameters'},
|
|
|
|
&ui_textbox("parameters", $b, 60));
|
|
|
|
|
2007-04-12 20:24:50 +00:00
|
|
|
if ($cron) {
|
|
|
|
# Show before/after commands
|
|
|
|
$b = $c{'backup_before_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_before'},
|
|
|
|
&ui_textbox("before", $b, 60));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
$a = $c{'backup_after_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_after'},
|
|
|
|
&ui_textbox("after", $a, 60));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
if ($in{'all'}) {
|
|
|
|
# Command mode option
|
|
|
|
$cmode = $c{'backup_cmode_'.$in{'db'}};
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_cmode'},
|
|
|
|
&ui_radio("cmode", int($cmode),
|
|
|
|
[ [ 0, $text{'backup_cmode0'} ],
|
|
|
|
[ 1, $text{'backup_cmode1'} ] ]));
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 22:35:14 +00:00
|
|
|
print &ui_hidden_table_end("opts");
|
2009-02-26 19:26:19 +00:00
|
|
|
print &ui_hidden_table_start($text{'backup_header3'}, "width=100%", 2,
|
|
|
|
"sched", 1, [ "width=30%" ]);
|
2007-09-29 22:16:17 +00:00
|
|
|
|
2011-11-29 15:49:33 -08:00
|
|
|
# Who to notify?
|
|
|
|
$email = $c{'backup_email_'.$in{'db'}};
|
|
|
|
print &ui_table_row($text{'backup_email'},
|
|
|
|
&ui_textbox("email", $email, 60));
|
|
|
|
|
|
|
|
# Notification conditions
|
|
|
|
$notify = $c{'backup_notify_'.$in{'db'}};
|
|
|
|
print &ui_table_row($text{'backup_notify'},
|
|
|
|
&ui_radio("notify", int($notify),
|
|
|
|
[ [ 0, $text{'backup_notify0'} ],
|
|
|
|
[ 1, $text{'backup_notify1'} ],
|
|
|
|
[ 2, $text{'backup_notify2'} ] ]));
|
|
|
|
|
2007-04-12 20:24:50 +00:00
|
|
|
# Show cron time
|
|
|
|
&foreign_require("cron", "cron-lib.pl");
|
|
|
|
@jobs = &cron::list_cron_jobs();
|
|
|
|
$cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
|
|
|
|
($job) = grep { $_->{'command'} eq $cmd } @jobs;
|
|
|
|
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_table_row($text{'backup_sched'},
|
|
|
|
&ui_radio("sched", $job ? 1 : 0,
|
|
|
|
[ [ 0, $text{'no'} ], [ 1, $text{'backup_sched1'} ] ]));
|
2007-04-12 20:24:50 +00:00
|
|
|
|
|
|
|
$job ||= { 'mins' => 0,
|
|
|
|
'hours' => 0,
|
|
|
|
'days' => '*',
|
|
|
|
'months' => '*',
|
|
|
|
'weekdays' => '*' };
|
2014-02-02 11:04:03 -08:00
|
|
|
print &cron::get_times_input($job);
|
2007-09-29 22:16:17 +00:00
|
|
|
|
|
|
|
print &ui_hidden_table_end("sched");
|
|
|
|
}
|
|
|
|
else {
|
2007-09-29 22:35:14 +00:00
|
|
|
print &ui_hidden_table_end("opts");
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cron) {
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_form_end([ [ "backup", $text{'backup_ok'} ],
|
|
|
|
[ "save", $text{'backup_ok2'} ] ]);
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-09-29 22:16:17 +00:00
|
|
|
print &ui_form_end([ [ "backup", $text{'backup_ok'} ] ]);
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($in{'all'}) {
|
|
|
|
&ui_print_footer("", $text{'index_return'});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
&ui_print_footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
|
2012-07-28 17:27:22 -07:00
|
|
|
&get_databases_return_link($in{'db'}), $text{'index_return'});
|
2007-04-12 20:24:50 +00:00
|
|
|
}
|
|
|
|
|