NEW The backup tools has an "lowmemory" for mysqldump on large database
This commit is contained in:
parent
a970f78c4e
commit
60d9db248f
@ -214,10 +214,6 @@ if (in_array($type, array('mysql', 'mysqli'))) {
|
|||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<fieldset><legend>'.$langs->trans("ExportOptions").'</legend>';
|
print '<fieldset><legend>'.$langs->trans("ExportOptions").'</legend>';
|
||||||
print '<div class="formelementrow">';
|
|
||||||
print '<input type="checkbox" name="use_transaction" value="yes" id="checkbox_use_transaction" />';
|
|
||||||
print '<label for="checkbox_use_transaction">'.$langs->trans("UseTransactionnalMode").'</label>';
|
|
||||||
print '</div>';
|
|
||||||
|
|
||||||
if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
|
if (!empty($conf->global->MYSQL_OLD_OPTION_DISABLE_FK)) {
|
||||||
print '<div class="formelementrow">';
|
print '<div class="formelementrow">';
|
||||||
@ -239,14 +235,35 @@ if (in_array($type, array('mysql', 'mysqli'))) {
|
|||||||
print '<option value="ORACLE">ORACLE</option>';
|
print '<option value="ORACLE">ORACLE</option>';
|
||||||
print '<option value="POSTGRESQL">POSTGRESQL</option>';
|
print '<option value="POSTGRESQL">POSTGRESQL</option>';
|
||||||
print '</select>';
|
print '</select>';
|
||||||
print '<br>';
|
print '<br><br>';
|
||||||
|
|
||||||
print '<input type="checkbox" name="use_mysql_quick_param" value="yes" id="checkbox_use_quick" />';
|
print '<div class="formelementrow">';
|
||||||
|
print '<input type="checkbox" name="use_transaction" value="yes" id="checkbox_use_transaction" checked="checked" />';
|
||||||
|
print '<label for="checkbox_use_transaction">'.$langs->trans("UseTransactionnalMode").'</label>';
|
||||||
|
print '</div>';
|
||||||
|
|
||||||
|
print '<input type="checkbox" name="use_mysql_quick_param" value="yes" id="checkbox_use_quick" checked="checked" />';
|
||||||
print '<label for="checkbox_use_quick">';
|
print '<label for="checkbox_use_quick">';
|
||||||
print $form->textwithpicto($langs->trans('ExportUseMySQLQuickParameter'), $langs->trans('ExportUseMySQLQuickParameterHelp'));
|
print $form->textwithpicto($langs->trans('ExportUseMySQLQuickParameter'), $langs->trans('ExportUseMySQLQuickParameterHelp'));
|
||||||
print '</label>';
|
print '</label>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
|
$execmethod = 0;
|
||||||
|
if (!empty($conf->global->MAIN_EXEC_USE_POPEN)) {
|
||||||
|
$execmethod = $conf->global->MAIN_EXEC_USE_POPEN;
|
||||||
|
}
|
||||||
|
if (empty($execmethod)) {
|
||||||
|
$execmethod = 1;
|
||||||
|
}
|
||||||
|
if ($execmethod == 1) {
|
||||||
|
// If we use the "exec" method for shell, we ask if we need to use the alternative low memory exec mode.
|
||||||
|
print '<input type="checkbox" name="lowmemorydump" value="yes" id="lowmemorydump"'.(GETPOSTISSET('lowmemorydump') ? GETPOST('lowmemorydump', 'alpha') : getDolGlobalString('MAIN_LOW_MEMORY_DUMP') ? ' checked="checked"' : '').'" />';
|
||||||
|
print '<label for="lowmemorydump">';
|
||||||
|
print $form->textwithpicto($langs->trans('ExportUseLowMemoryMode'), $langs->trans('ExportUseLowMemoryModeHelp'));
|
||||||
|
print '</label>';
|
||||||
|
print '<br>';
|
||||||
|
}
|
||||||
|
|
||||||
print '<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
|
print '<!-- <input type="checkbox" name="drop_database" value="yes" id="checkbox_drop_database" />';
|
||||||
print '<label for="checkbox_drop_database">'.$langs->trans("AddDropDatabase").'</label>';
|
print '<label for="checkbox_drop_database">'.$langs->trans("AddDropDatabase").'</label>';
|
||||||
print '-->';
|
print '-->';
|
||||||
|
|||||||
@ -189,7 +189,7 @@ class Utils
|
|||||||
* @param int $usedefault 1=Use default backup profile (Set this to 1 when used as cron)
|
* @param int $usedefault 1=Use default backup profile (Set this to 1 when used as cron)
|
||||||
* @param string $file 'auto' or filename to build
|
* @param string $file 'auto' or filename to build
|
||||||
* @param int $keeplastnfiles Keep only last n files (not used yet)
|
* @param int $keeplastnfiles Keep only last n files (not used yet)
|
||||||
* @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method
|
* @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec' - need size of dump in memory, but low memory method is used if GETPOST('lowmemorydump') is set, 2=Use the 'popen' method (low memory method)
|
||||||
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
|
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
|
||||||
*/
|
*/
|
||||||
public function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0)
|
public function dumpDatabase($compression = 'none', $type = 'auto', $usedefault = 1, $file = 'auto', $keeplastnfiles = 0, $execmethod = 0)
|
||||||
@ -278,8 +278,8 @@ class Utils
|
|||||||
if (!empty($dolibarr_main_db_port)) {
|
if (!empty($dolibarr_main_db_port)) {
|
||||||
$param .= " -P ".$dolibarr_main_db_port;
|
$param .= " -P ".$dolibarr_main_db_port;
|
||||||
}
|
}
|
||||||
if (!GETPOST("use_transaction", "alpha")) {
|
if (GETPOST("use_transaction", "alpha")) {
|
||||||
$param .= " -l --single-transaction";
|
$param .= " --single-transaction";
|
||||||
}
|
}
|
||||||
if (GETPOST("disable_fk", "alpha") || $usedefault) {
|
if (GETPOST("disable_fk", "alpha") || $usedefault) {
|
||||||
$param .= " -K";
|
$param .= " -K";
|
||||||
@ -342,17 +342,42 @@ class Utils
|
|||||||
|
|
||||||
$handle = '';
|
$handle = '';
|
||||||
|
|
||||||
|
$lowmemorydump = GETPOSTISSET("lowmemorydump", "alpha") ? GETPOST("lowmemorydump") : getDolGlobalString('MAIN_LOW_MEMORY_DUMP');
|
||||||
|
|
||||||
// Start call method to execute dump
|
// Start call method to execute dump
|
||||||
$fullcommandcrypted = $command." ".$paramcrypted." 2>&1";
|
$fullcommandcrypted = $command." ".$paramcrypted." 2>&1";
|
||||||
$fullcommandclear = $command." ".$paramclear." 2>&1";
|
$fullcommandclear = $command." ".$paramclear." 2>&1";
|
||||||
if ($compression == 'none') {
|
if (!$lowmemorydump) {
|
||||||
$handle = fopen($outputfile, 'w');
|
if ($compression == 'none') {
|
||||||
} elseif ($compression == 'gz') {
|
$handle = fopen($outputfile, 'w');
|
||||||
$handle = gzopen($outputfile, 'w');
|
} elseif ($compression == 'gz') {
|
||||||
} elseif ($compression == 'bz') {
|
$handle = gzopen($outputfile, 'w');
|
||||||
$handle = bzopen($outputfile, 'w');
|
} elseif ($compression == 'bz') {
|
||||||
} elseif ($compression == 'zstd') {
|
$handle = bzopen($outputfile, 'w');
|
||||||
$handle = fopen($outputfile, 'w');
|
} elseif ($compression == 'zstd') {
|
||||||
|
$handle = fopen($outputfile, 'w');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($compression == 'none') {
|
||||||
|
$fullcommandclear .= " > ".$outputfile;
|
||||||
|
$fullcommandcrypted .= " > ".$outputfile;
|
||||||
|
$handle = 1;
|
||||||
|
} elseif ($compression == 'gz') {
|
||||||
|
$fullcommandclear .= " | gzip > ".$outputfile;
|
||||||
|
$fullcommandcrypted .= " | gzip > ".$outputfile;
|
||||||
|
$paramcrypted.=" | gzip";
|
||||||
|
$handle = 1;
|
||||||
|
} elseif ($compression == 'bz') {
|
||||||
|
$fullcommandclear .= " | bzip2 > ".$outputfile;
|
||||||
|
$fullcommandcrypted .= " | bzip2 > ".$outputfile;
|
||||||
|
$paramcrypted.=" | bzip2";
|
||||||
|
$handle = 1;
|
||||||
|
} elseif ($compression == 'zstd') {
|
||||||
|
$fullcommandclear .= " | zstd > ".$outputfile;
|
||||||
|
$fullcommandcrypted .= " | zstd > ".$outputfile;
|
||||||
|
$paramcrypted.=" | zstd";
|
||||||
|
$handle = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ok = 0;
|
$ok = 0;
|
||||||
@ -374,7 +399,8 @@ class Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO Replace with executeCLI function
|
// TODO Replace with executeCLI function but
|
||||||
|
// we must first introduce a low memory mode
|
||||||
if ($execmethod == 1) {
|
if ($execmethod == 1) {
|
||||||
$output_arr = array();
|
$output_arr = array();
|
||||||
$retval = null;
|
$retval = null;
|
||||||
@ -394,16 +420,23 @@ class Utils
|
|||||||
if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) {
|
if ($i == 1 && preg_match('/Warning.*Using a password/i', $read)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fwrite($handle, $read.($execmethod == 2 ? '' : "\n"));
|
if (!$lowmemorydump) {
|
||||||
if (preg_match('/'.preg_quote('-- Dump completed', '/').'/i', $read)) {
|
fwrite($handle, $read.($execmethod == 2 ? '' : "\n"));
|
||||||
$ok = 1;
|
if (preg_match('/'.preg_quote('-- Dump completed', '/').'/i', $read)) {
|
||||||
} elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES', '/').'/i', $read)) {
|
$ok = 1;
|
||||||
$ok = 1;
|
} elseif (preg_match('/'.preg_quote('SET SQL_NOTES=@OLD_SQL_NOTES', '/').'/i', $read)) {
|
||||||
|
$ok = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we have a result here in lowmemorydump mode, something is strange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif ($lowmemorydump) {
|
||||||
|
$ok = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($execmethod == 2) { // With this method, there is no way to get the return code, only output
|
if ($execmethod == 2) { // With this method, there is no way to get the return code, only output
|
||||||
$handlein = popen($fullcommandclear, 'r');
|
$handlein = popen($fullcommandclear, 'r');
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|||||||
@ -2225,3 +2225,5 @@ PreviousHash=Previous hash
|
|||||||
LateWarningAfter="Late" warning after
|
LateWarningAfter="Late" warning after
|
||||||
TemplateforBusinessCards=Template for a business card in different size
|
TemplateforBusinessCards=Template for a business card in different size
|
||||||
InventorySetup= Inventory Setup
|
InventorySetup= Inventory Setup
|
||||||
|
ExportUseLowMemoryMode=Use a low memory mode
|
||||||
|
ExportUseLowMemoryModeHelp=Use the low memory mode to execute the exec of the dump (compression is done through a pipe instead of into the PHP memory). This method does not allow to check that file is completed and error message can't be reported if it fails.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user