Fix: Option to make pg_dump/restore

This commit is contained in:
Laurent Destailleur 2014-09-17 17:38:07 +02:00
parent 900cdd5368
commit 12ae552486
4 changed files with 29 additions and 16 deletions

View File

@ -366,9 +366,11 @@ print $langs->trans("BackupDescY").'<br><br>';
id="filename_template" id="filename_template"
value="<?php value="<?php
$prefix='dump'; $prefix='dump';
if ($label == 'MySQL') $prefix='mysqldump'; $ext='.sql';
if ($label == 'PostgreSQL') $prefix='pg_dump'; if ($label == 'MySQL') { $prefix='mysqldump'; $ext='sql'; }
$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.sql'; //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='sql'; }
$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
echo $file; echo $file;
?>" /> <br> ?>" /> <br>
<br> <br>
@ -376,16 +378,19 @@ echo $file;
<?php <?php
// Define compressions array // Define compressions array
$compression=array( $compression=array();
'none' => array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None")),
'gz' => array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip")),
);
if ($label == 'MySQL') if ($label == 'MySQL')
{ {
// $compression['zip']= array('function' => 'dol_compress', 'id' => 'radio_compression_zip', 'label' => $langs->trans("FormatZip")); // Not open source format. Must implement dol_compress function $compression['none'] = array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None"));
$compression['gz'] = array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip"));
// $compression['zip']= array('function' => 'dol_compress', 'id' => 'radio_compression_zip', 'label' => $langs->trans("FormatZip")); // Not open source format. Must implement dol_compress function
$compression['bz'] = array('function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2")); $compression['bz'] = array('function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2"));
} }
else
{
$compression['none'] = array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("Default"));
$compression['gz'] = array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip"));
}
// Show compression choices // Show compression choices
print '<div class="formelementrow">'; print '<div class="formelementrow">';

View File

@ -94,7 +94,7 @@ print $langs->trans("RestoreDesc3",DOL_DATA_ROOT).'<br><br>';
?> ?>
<div class="formelementrow"> <div class="formelementrow">
<input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo ($radio_dump=='postgresql_options'?' checked':''); ?> /> <input type="radio" name="what" value="mysql" id="radio_dump_postgresql"<?php echo ($radio_dump=='postgresql_options'?' checked':''); ?> />
<label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore)</label> <label for="radio_dump_postgresql">PostgreSQL Restore (pg_restore or psql)</label>
</div> </div>
<?php <?php
} }
@ -170,6 +170,9 @@ else if ($label == 'PostgreSQL')
}*/ }*/
$paramcrypted.=" -W"; $paramcrypted.=" -W";
$paramclear.=" -W"; $paramclear.=" -W";
// With psql:
$paramcrypted.=" -f";
$paramclear.=" -f";
echo $langs->trans("ImportPostgreSqlDesc"); echo $langs->trans("ImportPostgreSqlDesc");
print '<br>'; print '<br>';

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -289,7 +289,9 @@ if ($what == 'postgresql')
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="-F c";
$param="-F p";
$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 (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.=" --disable-dollar-quoting"; if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.=" --disable-dollar-quoting";

View File

@ -1209,11 +1209,14 @@ class DoliDBPgsql extends DoliDB
*/ */
function getPathOfRestore() function getPathOfRestore()
{ {
$fullpathofdump='/pathtopgrestore/pg_restore'; //$tool='pg_restore';
$tool='psql';
if (file_exists('/usr/bin/pg_restore')) $fullpathofdump='/pathtopgrestore/'.$tool;
if (file_exists('/usr/bin/'.$tool))
{ {
$fullpathofdump='/usr/bin/pg_restore'; $fullpathofdump='/usr/bin/'.$tool;
} }
else else
{ {
@ -1223,7 +1226,7 @@ class DoliDBPgsql extends DoliDB
{ {
$liste=$this->fetch_array($resql); $liste=$this->fetch_array($resql);
$basedir=$liste['data_directory']; $basedir=$liste['data_directory'];
$fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_restore'; $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool;
} }
} }