From 12ae55248630575746a79c4c9a649a4f99306e90 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Wed, 17 Sep 2014 17:38:07 +0200 Subject: [PATCH] Fix: Option to make pg_dump/restore --- htdocs/admin/tools/dolibarr_export.php | 23 ++++++++++++++--------- htdocs/admin/tools/dolibarr_import.php | 5 ++++- htdocs/admin/tools/export.php | 6 ++++-- htdocs/core/db/pgsql.class.php | 11 +++++++---- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/htdocs/admin/tools/dolibarr_export.php b/htdocs/admin/tools/dolibarr_export.php index 74037147760..9d5317fdd88 100644 --- a/htdocs/admin/tools/dolibarr_export.php +++ b/htdocs/admin/tools/dolibarr_export.php @@ -366,9 +366,11 @@ print $langs->trans("BackupDescY").'<br><br>'; id="filename_template" value="<?php $prefix='dump'; -if ($label == 'MySQL') $prefix='mysqldump'; -if ($label == 'PostgreSQL') $prefix='pg_dump'; -$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.sql'; +$ext='.sql'; +if ($label == 'MySQL') { $prefix='mysqldump'; $ext='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; ?>" /> <br> <br> @@ -376,16 +378,19 @@ echo $file; <?php // Define compressions 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")), -); +$compression=array(); 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")); } - +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 print '<div class="formelementrow">'; diff --git a/htdocs/admin/tools/dolibarr_import.php b/htdocs/admin/tools/dolibarr_import.php index d66df365afa..0cd1ae19fa9 100644 --- a/htdocs/admin/tools/dolibarr_import.php +++ b/htdocs/admin/tools/dolibarr_import.php @@ -94,7 +94,7 @@ print $langs->trans("RestoreDesc3",DOL_DATA_ROOT).'<br><br>'; ?> <div class="formelementrow"> <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> <?php } @@ -170,6 +170,9 @@ else if ($label == 'PostgreSQL') }*/ $paramcrypted.=" -W"; $paramclear.=" -W"; + // With psql: + $paramcrypted.=" -f"; + $paramclear.=" -f"; echo $langs->trans("ImportPostgreSqlDesc"); print '<br>'; diff --git a/htdocs/admin/tools/export.php b/htdocs/admin/tools/export.php index 57fbb045a02..203776bc7f9 100644 --- a/htdocs/admin/tools/export.php +++ b/htdocs/admin/tools/export.php @@ -1,5 +1,5 @@ <?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> * * 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 //$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; if (! empty($dolibarr_main_db_port)) $param.=" -p ".$dolibarr_main_db_port; if (GETPOST("sql_compat") && GETPOST("sql_compat") == 'ANSI') $param.=" --disable-dollar-quoting"; diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 6593b2d896b..25263deee46 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -1209,11 +1209,14 @@ class DoliDBPgsql extends DoliDB */ 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 { @@ -1223,7 +1226,7 @@ class DoliDBPgsql extends DoliDB { $liste=$this->fetch_array($resql); $basedir=$liste['data_directory']; - $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/pg_restore'; + $fullpathofdump=preg_replace('/data$/','bin',$basedir).'/'.$tool; } } -- GitLab