27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
33 $langs->load(
"admin");
35 $action =
GETPOST(
'action',
'aZ09');
36 $what =
GETPOST(
'what',
'alpha');
37 $export_type =
GETPOST(
'export_type',
'alpha');
41 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
42 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
43 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
45 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
48 $offset = $limit * $page;
62 $utils =
new Utils($db);
69 if ($file && !$what) {
71 header(
"Location: ".DOL_URL_ROOT.
'/admin/tools/dolibarr_export.php?msg='.urlencode($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"ExportMethod"))).(GETPOST(
'page_y',
'int') ?
'&page_y='.GETPOST(
'page_y',
'int') :
''));
75 if ($action ==
'delete') {
86 $_SESSION[
"commandbackuplastdone"] =
'';
87 $_SESSION[
"commandbackuptorun"] =
'';
88 $_SESSION[
"commandbackupresult"] =
'';
92 if (!empty($ExecTimeLimit)) {
93 $err = error_reporting();
96 @set_time_limit($ExecTimeLimit);
97 error_reporting($err);
100 if (!empty($MemoryLimit)) {
101 @ini_set(
'memory_limit', $MemoryLimit);
106 $dump_buffer_len = 0;
109 $time_start = time();
112 $outputdir = $conf->admin->dir_output.
'/backup';
120 if ($what ==
'mysql') {
121 $cmddump =
GETPOST(
"mysqldump",
'none');
124 if (!empty($dolibarr_main_restrict_os_commands)) {
125 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
126 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
127 dol_syslog(
"Command are restricted to ".$dolibarr_main_restrict_os_commands.
". We check that one of this command is inside ".$cmddump);
128 $basenamecmddump = basename(str_replace(
'\\',
'/', $cmddump));
129 if (!in_array($basenamecmddump, $arrayofallowedcommand)) {
130 $errormsg = $langs->trans(
'CommandIsNotInsideAllowedCommands');
134 if (!$errormsg && $cmddump) {
135 dolibarr_set_const($db,
'SYSTEMTOOLS_MYSQLDUMP', $cmddump,
'chaine', 0,
'', $conf->entity);
139 $utils->dumpDatabase(
GETPOST(
'compression',
'alpha'), $what, 0, $file, 0, 0, $lowmemorydump);
140 $errormsg = $utils->error;
141 $_SESSION[
"commandbackuplastdone"] = $utils->result[
'commandbackuplastdone'];
142 $_SESSION[
"commandbackuptorun"] = $utils->result[
'commandbackuptorun'];
147 if ($what ==
'mysqlnobin') {
148 $utils->dumpDatabase(
GETPOST(
'compression',
'alpha'), $what, 0, $file, 0, 0, $lowmemorydump);
150 $errormsg = $utils->error;
151 $_SESSION[
"commandbackuplastdone"] = $utils->result[
'commandbackuplastdone'];
152 $_SESSION[
"commandbackuptorun"] = $utils->result[
'commandbackuptorun'];
156 if ($what ==
'postgresql') {
157 $cmddump =
GETPOST(
"postgresqldump",
'none');
173 if (!$errormsg && $cmddump) {
174 dolibarr_set_const($db,
'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,
'chaine', 0,
'', $conf->entity);
178 $utils->dumpDatabase(
GETPOST(
'compression',
'alpha'), $what, 0, $file, 0, 0, $lowmemorydump);
179 $errormsg = $utils->error;
180 $_SESSION[
"commandbackuplastdone"] = $utils->result[
'commandbackuplastdone'];
181 $_SESSION[
"commandbackuptorun"] = $utils->result[
'commandbackuptorun'];
192 $resultstring .=
'<div class="error">'.$langs->trans(
"Error").
" : ".$errormsg.
'</div>';
194 $_SESSION[
"commandbackupresult"] = $resultstring;
197 setEventMessages($langs->trans(
"BackupFileSuccessfullyCreated").
'.<br>'.$langs->trans(
"YouCanDownloadBackupFile"),
null,
'mesgs');
199 $resultstring =
'<div class="ok">';
200 $resultstring .= $langs->trans(
"BackupFileSuccessfullyCreated").
'.<br>';
201 $resultstring .= $langs->trans(
"YouCanDownloadBackupFile");
202 $resultstring .=
'</div>';
204 $_SESSION[
"commandbackupresult"] = $resultstring;
223 header(
"Location: dolibarr_export.php".(
GETPOST(
'page_y',
'int') ?
'?page_y='.
GETPOST(
'page_y',
'int') :
''));