New: Add patch to allow export of database with no mysqldump access.
Still bugged.
This commit is contained in:
parent
10959d0dcc
commit
7ed4400c03
@ -43,13 +43,25 @@ llxHeader('','','EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad');
|
|||||||
?>
|
?>
|
||||||
<script type="text/javascript" language="javascript">
|
<script type="text/javascript" language="javascript">
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
jQuery("#mysql_options").hide();
|
|
||||||
jQuery("#postgresql_options").hide();
|
function hideoptions () {
|
||||||
|
jQuery("#mysql_options").hide();
|
||||||
|
jQuery("#mysql_options_nobin").hide();
|
||||||
|
jQuery("#postgresql_options").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
hideoptions();
|
||||||
|
|
||||||
jQuery("#radio_dump_mysql").click(function() {
|
jQuery("#radio_dump_mysql").click(function() {
|
||||||
|
hideoptions();
|
||||||
jQuery("#mysql_options").show();
|
jQuery("#mysql_options").show();
|
||||||
});
|
});
|
||||||
|
jQuery("#radio_dump_mysql_nobin").click(function() {
|
||||||
|
hideoptions();
|
||||||
|
jQuery("#mysql_options_nobin").show();
|
||||||
|
});
|
||||||
jQuery("#radio_dump_postgresql").click(function() {
|
jQuery("#radio_dump_postgresql").click(function() {
|
||||||
|
hideoptions();
|
||||||
jQuery("#postgresql_options").show();
|
jQuery("#postgresql_options").show();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -79,7 +91,7 @@ if ($_GET["msg"])
|
|||||||
name="token" value="<?php echo $_SESSION['newtoken']; ?>" /> <input
|
name="token" value="<?php echo $_SESSION['newtoken']; ?>" /> <input
|
||||||
type="hidden" name="export_type" value="server" />
|
type="hidden" name="export_type" value="server" />
|
||||||
|
|
||||||
<fieldset id="fieldsetexport"><!-- LDR -->
|
<fieldset id="fieldsetexport">
|
||||||
<?php print '<legend>'.$langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b></legend>'; ?>
|
<?php print '<legend>'.$langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b></legend>'; ?>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
@ -94,7 +106,12 @@ if ($_GET["msg"])
|
|||||||
<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />
|
<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />
|
||||||
<label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>
|
<label for="radio_dump_mysql">MySQL Dump (mysqldump)</label>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if (! empty($conf->global->MAIN_FEATURES_LEVEL)) { ?>
|
||||||
|
<div class="formelementrow"><input type="radio" name="what" value="mysqlnobin" id="radio_dump_mysql_nobin" />
|
||||||
|
<label for="radio_dump_mysql">MySQL Dump (php) <?php print img_warning('Backup can\'t be guaranted with this method. Prefer previous one'); ?></label>
|
||||||
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ($db->label == 'PostgreSQL')
|
else if ($db->label == 'PostgreSQL')
|
||||||
{
|
{
|
||||||
@ -327,7 +344,6 @@ print "\n";
|
|||||||
$result=$formfile->show_documents('systemtools','backup',$conf->admin->dir_output.'/backup',$_SERVER['PHP_SELF'],0,1,'',1,0,0,54,0,'',$langs->trans("PreviousDumpFiles"));
|
$result=$formfile->show_documents('systemtools','backup',$conf->admin->dir_output.'/backup',$_SERVER['PHP_SELF'],0,1,'',1,0,0,54,0,'',$langs->trans("PreviousDumpFiles"));
|
||||||
//if ($result) print '<br><br>';
|
//if ($result) print '<br><br>';
|
||||||
|
|
||||||
$db->close();
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
?>
|
|
||||||
|
$db->close();
|
||||||
|
|||||||
@ -31,19 +31,18 @@ $file=isset($_POST['filename_template']) ? $_POST['filename_template'] : '';
|
|||||||
|
|
||||||
$langs->load("admin");
|
$langs->load("admin");
|
||||||
|
|
||||||
if (! $user->admin)
|
if (! $user->admin) accessforbidden();
|
||||||
accessforbidden();
|
|
||||||
|
|
||||||
|
|
||||||
if ($file && ! $what)
|
if ($file && ! $what)
|
||||||
{
|
{
|
||||||
//print DOL_URL_ROOT.'/dolibarr_export.php';
|
//print DOL_URL_ROOT.'/dolibarr_export.php';
|
||||||
header("Location: ".DOL_URL_ROOT.'/admin/tools/dolibarr_export.php?msg='.urlencode($langs->trans("ErrorFieldRequired",$langs->transnoentities("ExportMethod"))));
|
header("Location: ".DOL_URL_ROOT.'/admin/tools/dolibarr_export.php?msg='.urlencode($langs->trans("ErrorFieldRequired",$langs->transnoentities("ExportMethod"))));
|
||||||
/*
|
/*
|
||||||
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ExportMethod")).'</div>';
|
print '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ExportMethod")).'</div>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
*/
|
*/
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,199 +83,223 @@ $time_start = time();
|
|||||||
// MYSQL
|
// MYSQL
|
||||||
if ($what == 'mysql')
|
if ($what == 'mysql')
|
||||||
{
|
{
|
||||||
$cmddump=$_POST["mysqldump"];
|
$cmddump=$_POST["mysqldump"];
|
||||||
if ($cmddump)
|
if ($cmddump)
|
||||||
{
|
{
|
||||||
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
dolibarr_set_const($db, 'SYSTEMTOOLS_MYSQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
$outputdir = $conf->admin->dir_output.'/backup';
|
$outputdir = $conf->admin->dir_output.'/backup';
|
||||||
$outputfile = $outputdir.'/'.$file;
|
$outputfile = $outputdir.'/'.$file;
|
||||||
// for compression format, we add extension
|
// for compression format, we add extension
|
||||||
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
|
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
|
||||||
if ($compression == 'gz') $outputfile.='.gz';
|
if ($compression == 'gz') $outputfile.='.gz';
|
||||||
if ($compression == 'bz') $outputfile.='.bz2';
|
if ($compression == 'bz') $outputfile.='.bz2';
|
||||||
$outputerror = $outputfile.'.err';
|
$outputerror = $outputfile.'.err';
|
||||||
dol_mkdir($conf->admin->dir_output.'/backup');
|
dol_mkdir($conf->admin->dir_output.'/backup');
|
||||||
|
|
||||||
// Parameteres execution
|
// Parameteres execution
|
||||||
$command=$cmddump;
|
$command=$cmddump;
|
||||||
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command
|
if (preg_match("/\s/",$command)) $command=escapeshellarg($command); // Use quotes on command
|
||||||
|
|
||||||
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
|
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
|
||||||
$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
|
$param=$dolibarr_main_db_name." -h ".$dolibarr_main_db_host;
|
||||||
$param.=" -u ".$dolibarr_main_db_user;
|
$param.=" -u ".$dolibarr_main_db_user;
|
||||||
if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
|
if (! empty($dolibarr_main_db_port)) $param.=" -P ".$dolibarr_main_db_port;
|
||||||
if (! $_POST["use_transaction"]) $param.=" -l --single-transaction";
|
if (! $_POST["use_transaction"]) $param.=" -l --single-transaction";
|
||||||
if ($_POST["disable_fk"]) $param.=" -K";
|
if ($_POST["disable_fk"]) $param.=" -K";
|
||||||
if ($_POST["sql_compat"] && $_POST["sql_compat"] != 'NONE') $param.=" --compatible=".$_POST["sql_compat"];
|
if ($_POST["sql_compat"] && $_POST["sql_compat"] != 'NONE') $param.=" --compatible=".$_POST["sql_compat"];
|
||||||
if ($_POST["drop_database"]) $param.=" --add-drop-database";
|
if ($_POST["drop_database"]) $param.=" --add-drop-database";
|
||||||
if ($_POST["sql_structure"])
|
if ($_POST["sql_structure"])
|
||||||
{
|
{
|
||||||
if ($_POST["drop"]) $param.=" --add-drop-table";
|
if ($_POST["drop"]) $param.=" --add-drop-table";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$param.=" -t";
|
$param.=" -t";
|
||||||
}
|
}
|
||||||
if ($_POST["sql_data"])
|
if ($_POST["sql_data"])
|
||||||
{
|
{
|
||||||
$param.=" --tables";
|
$param.=" --tables";
|
||||||
if ($_POST["showcolumns"]) $param.=" -c";
|
if ($_POST["showcolumns"]) $param.=" -c";
|
||||||
if ($_POST["extended_ins"]) $param.=" -e";
|
if ($_POST["extended_ins"]) $param.=" -e";
|
||||||
if ($_POST["delayed"]) $param.=" --delayed-insert";
|
if ($_POST["delayed"]) $param.=" --delayed-insert";
|
||||||
if ($_POST["sql_ignore"]) $param.=" --insert-ignore";
|
if ($_POST["sql_ignore"]) $param.=" --insert-ignore";
|
||||||
if ($_POST["hexforbinary"]) $param.=" --hex-blob";
|
if ($_POST["hexforbinary"]) $param.=" --hex-blob";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$param.=" -d";
|
$param.=" -d";
|
||||||
}
|
}
|
||||||
$paramcrypted=$param;
|
$paramcrypted=$param;
|
||||||
$paramclear=$param;
|
$paramclear=$param;
|
||||||
if (! empty($dolibarr_main_db_pass))
|
if (! empty($dolibarr_main_db_pass))
|
||||||
{
|
{
|
||||||
$paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
$paramcrypted.=" -p".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
||||||
$paramclear.=" -p".$dolibarr_main_db_pass;
|
$paramclear.=" -p".$dolibarr_main_db_pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<b>'.$langs->trans("RunCommandSummary").':</b><br>'."\n";
|
print '<b>'.$langs->trans("RunCommandSummary").':</b><br>'."\n";
|
||||||
print '<textarea rows="'.ROWS_2.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
|
print '<textarea rows="'.ROWS_2.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
|
|
||||||
// Now run command and show result
|
// Now run command and show result
|
||||||
print '<b>'.$langs->trans("BackupResult").':</b> ';
|
print '<b>'.$langs->trans("BackupResult").':</b> ';
|
||||||
|
|
||||||
$errormsg='';
|
$errormsg='';
|
||||||
|
|
||||||
$result=dol_mkdir($outputdir);
|
$result=dol_mkdir($outputdir);
|
||||||
|
|
||||||
// Debut appel methode execution
|
// Debut appel methode execution
|
||||||
$fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
|
$fullcommandcrypted=$command." ".$paramcrypted." 2>&1";
|
||||||
$fullcommandclear=$command." ".$paramclear." 2>&1";
|
$fullcommandclear=$command." ".$paramclear." 2>&1";
|
||||||
if ($compression == 'none') $handle = fopen($outputfile, 'w');
|
if ($compression == 'none') $handle = fopen($outputfile, 'w');
|
||||||
if ($compression == 'gz') $handle = gzopen($outputfile, 'w');
|
if ($compression == 'gz') $handle = gzopen($outputfile, 'w');
|
||||||
if ($compression == 'bz') $handle = bzopen($outputfile, 'w');
|
if ($compression == 'bz') $handle = bzopen($outputfile, 'w');
|
||||||
|
|
||||||
if ($handle)
|
if ($handle)
|
||||||
{
|
{
|
||||||
$ok=0;
|
$ok=0;
|
||||||
dol_syslog("Run command ".$fullcommandcrypted);
|
dol_syslog("Run command ".$fullcommandcrypted);
|
||||||
$handlein = popen($fullcommandclear, 'r');
|
$handlein = popen($fullcommandclear, 'r');
|
||||||
while (!feof($handlein))
|
while (!feof($handlein))
|
||||||
{
|
{
|
||||||
$read = fgets($handlein);
|
$read = fgets($handlein);
|
||||||
fwrite($handle,$read);
|
fwrite($handle,$read);
|
||||||
if (preg_match('/-- Dump completed/i',$read)) $ok=1;
|
if (preg_match('/-- Dump completed/i',$read)) $ok=1;
|
||||||
}
|
}
|
||||||
pclose($handlein);
|
pclose($handlein);
|
||||||
|
|
||||||
if ($compression == 'none') fclose($handle);
|
if ($compression == 'none') fclose($handle);
|
||||||
if ($compression == 'gz') gzclose($handle);
|
if ($compression == 'gz') gzclose($handle);
|
||||||
if ($compression == 'bz') bzclose($handle);
|
if ($compression == 'bz') bzclose($handle);
|
||||||
|
|
||||||
if (! empty($conf->global->MAIN_UMASK))
|
if (! empty($conf->global->MAIN_UMASK))
|
||||||
@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
|
@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
|
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
|
||||||
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
|
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
|
||||||
}
|
}
|
||||||
// Get errorstring
|
// Get errorstring
|
||||||
if ($compression == 'none') $handle = fopen($outputfile, 'r');
|
if ($compression == 'none') $handle = fopen($outputfile, 'r');
|
||||||
if ($compression == 'gz') $handle = gzopen($outputfile, 'r');
|
if ($compression == 'gz') $handle = gzopen($outputfile, 'r');
|
||||||
if ($compression == 'bz') $handle = bzopen($outputfile, 'r');
|
if ($compression == 'bz') $handle = bzopen($outputfile, 'r');
|
||||||
if ($handle)
|
if ($handle)
|
||||||
{
|
{
|
||||||
// Get 2048 first chars of error message.
|
// Get 2048 first chars of error message.
|
||||||
$errormsg = fgets($handle,2048);
|
$errormsg = fgets($handle,2048);
|
||||||
// Close file
|
// Close file
|
||||||
if ($compression == 'none') fclose($handle);
|
if ($compression == 'none') fclose($handle);
|
||||||
if ($compression == 'gz') gzclose($handle);
|
if ($compression == 'gz') gzclose($handle);
|
||||||
if ($compression == 'bz') bzclose($handle);
|
if ($compression == 'bz') bzclose($handle);
|
||||||
if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur
|
if ($ok && preg_match('/^-- MySql/i',$errormsg)) $errormsg=''; // Pas erreur
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Renommer fichier sortie en fichier erreur
|
// Renommer fichier sortie en fichier erreur
|
||||||
//print "$outputfile -> $outputerror";
|
//print "$outputfile -> $outputerror";
|
||||||
@dol_delete_file($outputerror,1);
|
@dol_delete_file($outputerror,1);
|
||||||
@rename($outputfile,$outputerror);
|
@rename($outputfile,$outputerror);
|
||||||
// Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
|
// Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
|
||||||
if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
|
if (! $errormsg) $errormsg=$langs->trans("ErrorFailedToRunExternalCommand");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fin execution commande
|
// Fin execution commande
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($what == 'mysqlnobin')
|
||||||
|
{
|
||||||
|
$outputdir = $conf->admin->dir_output.'/backup';
|
||||||
|
$outputfile = $outputdir.'/'.$file;
|
||||||
|
$outputfiletemp = $outputfile.'-TMP.sql';
|
||||||
|
// for compression format, we add extension
|
||||||
|
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
|
||||||
|
if ($compression == 'gz') $outputfile.='.gz';
|
||||||
|
if ($compression == 'bz') $outputfile.='.bz2';
|
||||||
|
$outputerror = $outputfile.'.err';
|
||||||
|
dol_mkdir($conf->admin->dir_output.'/backup');
|
||||||
|
|
||||||
|
if ($compression == 'gz' or $compression == 'bz')
|
||||||
|
{
|
||||||
|
backup_tables($outputfiletemp);
|
||||||
|
dol_compress_file($outputfiletemp, $outputfile, $compression);
|
||||||
|
unlink($outputfiletemp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
backup_tables($outputfile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POSTGRESQL
|
// POSTGRESQL
|
||||||
if ($what == 'postgresql')
|
if ($what == 'postgresql')
|
||||||
{
|
{
|
||||||
$cmddump=$_POST["postgresqldump"];
|
$cmddump=$_POST["postgresqldump"];
|
||||||
if ($cmddump)
|
if ($cmddump)
|
||||||
{
|
{
|
||||||
dolibarr_set_const($db, 'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
dolibarr_set_const($db, 'SYSTEMTOOLS_POSTGRESQLDUMP', $cmddump,'chaine',0,'',$conf->entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
$outputdir = $conf->admin->dir_output.'/backup';
|
$outputdir = $conf->admin->dir_output.'/backup';
|
||||||
$outputfile = $outputdir.'/'.$file;
|
$outputfile = $outputdir.'/'.$file;
|
||||||
// for compression format, we add extension
|
// for compression format, we add extension
|
||||||
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
|
$compression=isset($_POST['compression']) ? $_POST['compression'] : 'none';
|
||||||
if ($compression == 'gz') $outputfile.='.gz';
|
if ($compression == 'gz') $outputfile.='.gz';
|
||||||
if ($compression == 'bz') $outputfile.='.bz2';
|
if ($compression == 'bz') $outputfile.='.bz2';
|
||||||
$outputerror = $outputfile.'.err';
|
$outputerror = $outputfile.'.err';
|
||||||
dol_mkdir($conf->admin->dir_output.'/backup');
|
dol_mkdir($conf->admin->dir_output.'/backup');
|
||||||
|
|
||||||
// Parameteres execution
|
// Parameteres execution
|
||||||
$command=$cmddump;
|
$command=$cmddump;
|
||||||
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
|
if (preg_match("/\s/",$command)) $command=$command=escapeshellarg($command); // Use quotes on command
|
||||||
|
|
||||||
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
|
//$param=escapeshellarg($dolibarr_main_db_name)." -h ".escapeshellarg($dolibarr_main_db_host)." -u ".escapeshellarg($dolibarr_main_db_user)." -p".escapeshellarg($dolibarr_main_db_pass);
|
||||||
$param=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
|
$param=" --no-tablespaces --inserts -h ".$dolibarr_main_db_host;
|
||||||
$param.=" -U ".$dolibarr_main_db_user;
|
$param.=" -U ".$dolibarr_main_db_user;
|
||||||
if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
|
if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port;
|
||||||
if ($_POST["sql_compat"] && $_POST["sql_compat"] == 'ANSI') $param.=" --disable-dollar-quoting";
|
if ($_POST["sql_compat"] && $_POST["sql_compat"] == 'ANSI') $param.=" --disable-dollar-quoting";
|
||||||
if ($_POST["drop_database"]) $param.=" -c -C";
|
if ($_POST["drop_database"]) $param.=" -c -C";
|
||||||
if ($_POST["sql_structure"])
|
if ($_POST["sql_structure"])
|
||||||
{
|
{
|
||||||
if ($_POST["drop"]) $param.=" --add-drop-table";
|
if ($_POST["drop"]) $param.=" --add-drop-table";
|
||||||
if (empty($_POST["sql_data"])) $param.=" -s";
|
if (empty($_POST["sql_data"])) $param.=" -s";
|
||||||
}
|
}
|
||||||
if ($_POST["sql_data"])
|
if ($_POST["sql_data"])
|
||||||
{
|
{
|
||||||
if (empty($_POST["sql_structure"])) $param.=" -a";
|
if (empty($_POST["sql_structure"])) $param.=" -a";
|
||||||
if ($_POST["showcolumns"]) $param.=" -c";
|
if ($_POST["showcolumns"]) $param.=" -c";
|
||||||
}
|
}
|
||||||
$param.=' -f "'.$outputfile.'"';
|
$param.=' -f "'.$outputfile.'"';
|
||||||
//if ($compression == 'none')
|
//if ($compression == 'none')
|
||||||
if ($compression == 'gz') $param.=' -Z 9';
|
if ($compression == 'gz') $param.=' -Z 9';
|
||||||
//if ($compression == 'bz')
|
//if ($compression == 'bz')
|
||||||
$paramcrypted=$param;
|
$paramcrypted=$param;
|
||||||
$paramclear=$param;
|
$paramclear=$param;
|
||||||
/*if (! empty($dolibarr_main_db_pass))
|
/*if (! empty($dolibarr_main_db_pass))
|
||||||
{
|
{
|
||||||
$paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
$paramcrypted.=" -W".preg_replace('/./i','*',$dolibarr_main_db_pass);
|
||||||
$paramclear.=" -W".$dolibarr_main_db_pass;
|
$paramclear.=" -W".$dolibarr_main_db_pass;
|
||||||
}*/
|
}*/
|
||||||
$paramcrypted.=" -w ".$dolibarr_main_db_name;
|
$paramcrypted.=" -w ".$dolibarr_main_db_name;
|
||||||
$paramclear.=" -w ".$dolibarr_main_db_name;
|
$paramclear.=" -w ".$dolibarr_main_db_name;
|
||||||
|
|
||||||
print $langs->trans("RunCommandSummaryToLaunch").':<br>'."\n";
|
print $langs->trans("RunCommandSummaryToLaunch").':<br>'."\n";
|
||||||
print '<textarea rows="'.ROWS_3.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
|
print '<textarea rows="'.ROWS_3.'" cols="120">'.$command." ".$paramcrypted.'</textarea><br>'."\n";
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
|
|
||||||
// Now show to ask to run command
|
// Now show to ask to run command
|
||||||
print $langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user);
|
print $langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser",$dolibarr_main_db_user,$dolibarr_main_db_user);
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
$what='';
|
$what='';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -285,29 +308,29 @@ if ($what == 'postgresql')
|
|||||||
// Si on a demande une generation
|
// Si on a demande une generation
|
||||||
if ($what)
|
if ($what)
|
||||||
{
|
{
|
||||||
if ($errormsg)
|
if ($errormsg)
|
||||||
{
|
{
|
||||||
print '<div class="error">'.$langs->trans("Error")." : ".$errormsg.'</div>';
|
print '<div class="error">'.$langs->trans("Error")." : ".$errormsg.'</div>';
|
||||||
// print '<a href="'.DOL_URL_ROOT.$relativepatherr.'">'.$langs->trans("DownloadErrorFile").'</a><br>';
|
// print '<a href="'.DOL_URL_ROOT.$relativepatherr.'">'.$langs->trans("DownloadErrorFile").'</a><br>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print '<div class="ok">';
|
print '<div class="ok">';
|
||||||
print $langs->trans("BackupFileSuccessfullyCreated").'.<br>';
|
print $langs->trans("BackupFileSuccessfullyCreated").'.<br>';
|
||||||
print $langs->trans("YouCanDownloadBackupFile");
|
print $langs->trans("YouCanDownloadBackupFile");
|
||||||
print '</div>';
|
print '</div>';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result=$formfile->show_documents('systemtools','backup',$conf->admin->dir_output.'/backup',$_SERVER['PHP_SELF'],0,1,'',1,0,0,54,0,'',$langs->trans("PreviousDumpFiles"));
|
$result=$formfile->show_documents('systemtools','backup',$conf->admin->dir_output.'/backup',$_SERVER['PHP_SELF'],0,1,'',1,0,0,54,0,'',$langs->trans("PreviousDumpFiles"));
|
||||||
|
|
||||||
if ($result == 0)
|
if ($result == 0)
|
||||||
{
|
{
|
||||||
print $langs->trans("NoBackupFileAvailable").'<br>';
|
print $langs->trans("NoBackupFileAvailable").'<br>';
|
||||||
print $langs->trans("ToBuildBackupFileClickHere",DOL_URL_ROOT.'/admin/tools/dolibarr_export.php').'<br>';
|
print $langs->trans("ToBuildBackupFileClickHere",DOL_URL_ROOT.'/admin/tools/dolibarr_export.php').'<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
@ -315,4 +338,118 @@ print '<br>';
|
|||||||
$time_end = time();
|
$time_end = time();
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|
||||||
|
$db->close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// MYSQL NO BINARIES (only php)
|
||||||
|
/** Backup the db OR just a table without mysqldump binary (does not require any exec permission)
|
||||||
|
* Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php)
|
||||||
|
* Updated and enhanced by Stephen Larroque (lrq3000) and by the many commentators from the blog
|
||||||
|
*
|
||||||
|
* @param string $outputfile Output file name
|
||||||
|
* @param string $tables Table name or '*' for all
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*
|
||||||
|
* FIXME Must add directives to have restore working even with constraints not loaded into correct order, etc...
|
||||||
|
*/
|
||||||
|
function backup_tables($outputfile, $tables='*')
|
||||||
|
{
|
||||||
|
global $db, $langs;
|
||||||
|
global $errormsg;
|
||||||
|
|
||||||
|
// Set to UTF-8
|
||||||
|
$db->query('SET NAMES utf8');
|
||||||
|
$db->query('SET CHARACTER SET utf8');
|
||||||
|
|
||||||
|
//get all of the tables
|
||||||
|
if ($tables == '*')
|
||||||
|
{
|
||||||
|
$tables = array();
|
||||||
|
$result = $db->query('SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\'');
|
||||||
|
while($row = $db->fetch_row($result))
|
||||||
|
{
|
||||||
|
$tables[] = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tables = is_array($tables) ? $tables : explode(',',$tables);
|
||||||
|
}
|
||||||
|
|
||||||
|
//cycle through
|
||||||
|
$handle = fopen($outputfile, 'w+');
|
||||||
|
if (fwrite($handle, '') === FALSE)
|
||||||
|
{
|
||||||
|
$langs->load("errors");
|
||||||
|
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
|
||||||
|
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
foreach($tables as $table)
|
||||||
|
{
|
||||||
|
$sql='SELECT * FROM '.$table;
|
||||||
|
$result = $db->query($sql);
|
||||||
|
$num_fields = $db->num_rows($result);
|
||||||
|
|
||||||
|
fwrite($handle,'DROP TABLE IF EXISTS '.$table);
|
||||||
|
$resqldrop=$db->query('SHOW CREATE TABLE '.$table);
|
||||||
|
$row2 = $db->fetch_row($resqldrop);
|
||||||
|
fwrite($handle,"\n\n".$row2[1].";\n\n");
|
||||||
|
|
||||||
|
while($row = $db->fetch_row($result))
|
||||||
|
{
|
||||||
|
fwrite($handle,'INSERT INTO '.$table.' VALUES(');
|
||||||
|
$columns = count($row);
|
||||||
|
for($j=0; $j<$columns; $j++)
|
||||||
|
{
|
||||||
|
$row[$j] = addslashes($row[$j]);
|
||||||
|
$row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
|
||||||
|
if (isset($row[$j])) { fwrite($handle,'"'.$row[$j].'"'); } else { fwrite($handle,'""'); }
|
||||||
|
if (isset($row[$j]))
|
||||||
|
{
|
||||||
|
if ($row[$j] == null)
|
||||||
|
{
|
||||||
|
fwrite($handle,'"null"');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fwrite($handle,'"'.$row[$j].'"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fwrite($handle,'""');
|
||||||
|
}
|
||||||
|
if ($j<($num_fields-1)) { fwrite($handle,','); }
|
||||||
|
}
|
||||||
|
fwrite($handle,");\n");
|
||||||
|
}
|
||||||
|
fwrite($handle,"\n\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Backup Procedure structure*/
|
||||||
|
/*
|
||||||
|
$result = $db->query('SHOW PROCEDURE STATUS');
|
||||||
|
if ($db->num_rows($result) > 0)
|
||||||
|
{
|
||||||
|
while ($row = $db->fetch_row($result)) { $procedures[] = $row[1]; }
|
||||||
|
foreach($procedures as $proc)
|
||||||
|
{
|
||||||
|
fwrite($handle,"DELIMITER $$\n\n");
|
||||||
|
fwrite($handle,"DROP PROCEDURE IF EXISTS '$name'.'$proc'$$\n");
|
||||||
|
$resqlcreateproc=$db->query("SHOW CREATE PROCEDURE '$proc'");
|
||||||
|
$row2 = $db->fetch_row($resqlcreateproc);
|
||||||
|
fwrite($handle,"\n".$row2[2]."$$\n\n");
|
||||||
|
fwrite($handle,"DELIMITER ;\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/* Backup Procedure structure*/
|
||||||
|
|
||||||
|
fclose($handle);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -873,9 +873,11 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert file to image
|
* Convert an image file into antoher format.
|
||||||
* @param file Input file name
|
* This need Imagick php extension.
|
||||||
* @param ext Extension of target file
|
*
|
||||||
|
* @param string $file Input file name
|
||||||
|
* @param string $ext Extension of target file
|
||||||
*/
|
*/
|
||||||
function dol_convert_file($file,$ext='png')
|
function dol_convert_file($file,$ext='png')
|
||||||
{
|
{
|
||||||
@ -906,4 +908,34 @@ function dol_convert_file($file,$ext='png')
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compress a file
|
||||||
|
*
|
||||||
|
* @param string $inputfile Source file name
|
||||||
|
* @param string $outputfile Target file name
|
||||||
|
* @param string $mode 'gz' or 'bz'
|
||||||
|
*/
|
||||||
|
function dol_compress_file($inputfile, $outputfile, $mode="gz")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$data = implode("", file($inputfile));
|
||||||
|
if ($mode == 'gz') $compressdata = gzencode($data, 9);
|
||||||
|
elseif ($mode == 'bz') $compressdata = bzcompress($data, 9);
|
||||||
|
|
||||||
|
$fp = fopen($outputfile, "w");
|
||||||
|
fwrite($fp, $compressdata);
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
global $langs, $errormsg;
|
||||||
|
$langs->load("errors");
|
||||||
|
dol_syslog("Failed to open file ".$outputfile,LOG_ERR);
|
||||||
|
$errormsg=$langs->trans("ErrorFailedToWriteInDir");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user