Add optional options for mysqlnobin export method.
Signed-off-by: Stephen L. <lrq3000@gmail.com>
This commit is contained in:
parent
44bed57faf
commit
427da6ed5e
@ -76,7 +76,7 @@ jQuery(document).ready(function() {
|
|||||||
|
|
||||||
function hideoptions () {
|
function hideoptions () {
|
||||||
jQuery("#mysql_options").hide();
|
jQuery("#mysql_options").hide();
|
||||||
jQuery("#mysql_options_nobin").hide();
|
jQuery("#mysql_nobin_options").hide();
|
||||||
jQuery("#postgresql_options").hide();
|
jQuery("#postgresql_options").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ jQuery(document).ready(function() {
|
|||||||
});
|
});
|
||||||
jQuery("#radio_dump_mysql_nobin").click(function() {
|
jQuery("#radio_dump_mysql_nobin").click(function() {
|
||||||
hideoptions();
|
hideoptions();
|
||||||
jQuery("#mysql_options_nobin").show();
|
jQuery("#mysql_nobin_options").show();
|
||||||
});
|
});
|
||||||
jQuery("#radio_dump_postgresql").click(function() {
|
jQuery("#radio_dump_postgresql").click(function() {
|
||||||
hideoptions();
|
hideoptions();
|
||||||
@ -255,6 +255,50 @@ print $langs->trans("BackupDescY").'<br><br>';
|
|||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
<!-- Fieldset mysql_nobin -->
|
||||||
|
<fieldset id="mysql_nobin_options"><legend><?php echo $langs->trans("MySqlExportParameters"); ?></legend>
|
||||||
|
<fieldset>
|
||||||
|
<legend><?php echo $langs->trans("ExportOptions"); ?></legend>
|
||||||
|
<div class="formelementrow"><input type="checkbox"
|
||||||
|
name="nobin_use_transaction" value="yes" id="checkbox_use_transaction" /> <label
|
||||||
|
for="checkbox_use_transaction"> <?php echo $langs->trans("UseTransactionnalMode"); ?></label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="formelementrow"><input type="checkbox" name="nobin_disable_fk"
|
||||||
|
value="yes" id="checkbox_disable_fk" checked="checked" /> <label
|
||||||
|
for="checkbox_disable_fk"> <?php echo $langs->trans("CommandsToDisableForeignKeysForImport"); ?><?php print img_warning('Mandatory if you want to be able to restore your sql dump later'); ?></label>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<fieldset><legend>Structure</legend> <input
|
||||||
|
type="checkbox" name="nobin_drop" value="1" id="checkbox_dump_drop" /> <label
|
||||||
|
for="checkbox_dump_drop"><?php echo $langs->trans("AddDropTable"); ?></label><br>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<fieldset>
|
||||||
|
<legend><?php echo $langs->trans("Datas"); ?></legend>
|
||||||
|
|
||||||
|
<input type="checkbox" name="nobin_nolocks" value="no"
|
||||||
|
id="checkbox_dump_disable-add-locks" /> <label
|
||||||
|
for="checkbox_dump_disable-add-locks"> <?php echo $langs->trans("NoLockBeforeInsert"); ?></label><br>
|
||||||
|
|
||||||
|
<input type="checkbox" name="nobin_delayed" value="yes"
|
||||||
|
id="checkbox_dump_delayed" /> <label for="checkbox_dump_delayed"> <?php echo $langs->trans("DelayedInsert"); ?></label><br>
|
||||||
|
|
||||||
|
<input type="checkbox" name="nobin_sql_ignore" value="yes"
|
||||||
|
id="checkbox_dump_ignore" /> <label for="checkbox_dump_ignore"> <?php echo $langs->trans("IgnoreDuplicateRecords"); ?></label><br>
|
||||||
|
|
||||||
|
<input type="checkbox" name="nobin_charset_utf8" value="yes"
|
||||||
|
id="checkbox_charset_utf8" checked="checked" disabled="disabled" /> <label
|
||||||
|
for="checkbox_charset_utf8"> <?php echo $langs->trans("UTF8"); ?></label><br>
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -422,23 +422,31 @@ function backup_tables($outputfile, $tables='*')
|
|||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
-- Server version ".$db->db->server_info."
|
-- Server version ".$db->db->server_info."
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
|
||||||
SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";
|
|
||||||
|
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
/*!40101 SET NAMES utf8 */;
|
/*!40101 SET NAMES utf8 */;
|
||||||
|
|
||||||
";
|
";
|
||||||
|
|
||||||
|
if (GETPOST("nobin_disable_fk")) $sqlhead .= "SET FOREIGN_KEY_CHECKS=0;\n";
|
||||||
|
$sqlhead .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n";
|
||||||
|
if (GETPOST("nobin_use_transaction")) $sqlhead .= "SET AUTOCOMMIT=0;\nSTART TRANSACTION;\n";
|
||||||
|
|
||||||
fwrite($handle, $sqlhead);
|
fwrite($handle, $sqlhead);
|
||||||
|
|
||||||
|
$ignore = '';
|
||||||
|
if (GETPOST("nobin_sql_ignore")) $ignore = 'IGNORE ';
|
||||||
|
$delayed = '';
|
||||||
|
if (GETPOST("nobin_delayed")) $delayed = 'DELAYED ';
|
||||||
|
|
||||||
// Process each table and print their definition + their datas
|
// Process each table and print their definition + their datas
|
||||||
foreach($tables as $table)
|
foreach($tables as $table)
|
||||||
{
|
{
|
||||||
// Saving the table structure
|
// Saving the table structure
|
||||||
fwrite($handle, "--\n-- Table structure for table `".$table."`\n--\n\n");
|
fwrite($handle, "\n--\n-- Table structure for table `".$table."`\n--\n");
|
||||||
|
|
||||||
//fwrite($handle,"DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
|
if (GETPOST("nobin_drop")) fwrite($handle,"DROP TABLE IF EXISTS `".$table."`;\n"); // Dropping table if exists prior to re create it
|
||||||
//fwrite($handle,"/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
|
//fwrite($handle,"/*!40101 SET @saved_cs_client = @@character_set_client */;\n");
|
||||||
//fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n");
|
//fwrite($handle,"/*!40101 SET character_set_client = utf8 */;\n");
|
||||||
$resqldrop=$db->query('SHOW CREATE TABLE '.$table);
|
$resqldrop=$db->query('SHOW CREATE TABLE '.$table);
|
||||||
@ -448,18 +456,17 @@ SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";
|
|||||||
|
|
||||||
|
|
||||||
// Dumping the data (locking the table and disabling the keys check while doing the process)
|
// Dumping the data (locking the table and disabling the keys check while doing the process)
|
||||||
fwrite($handle, "--\n-- Dumping data for table `".$table."`\n--\n\n");
|
fwrite($handle, "\n--\n-- Dumping data for table `".$table."`\n--\n");
|
||||||
//fwrite($handle, "LOCK TABLES `".$table."` WRITE;\n"); // Lock the table before inserting data (when the data will be imported back)
|
if (!GETPOST("nobin_nolocks")) fwrite($handle, "LOCK TABLES `".$table."` WRITE;\n"); // Lock the table before inserting data (when the data will be imported back)
|
||||||
fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n");
|
if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` DISABLE KEYS;\n");
|
||||||
|
|
||||||
$sql='SELECT * FROM '.$table;
|
$sql='SELECT * FROM '.$table;
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
$num_fields = $db->num_rows($result);
|
$num_fields = $db->num_rows($result);
|
||||||
while($row = $db->fetch_row($result)) {
|
while($row = $db->fetch_row($result)) {
|
||||||
// For each row of data we print a line of INSERT
|
// For each row of data we print a line of INSERT
|
||||||
fwrite($handle,'INSERT INTO `'.$table.'` VALUES (');
|
fwrite($handle,'INSERT '.$delayed.$ignore.'INTO `'.$table.'` VALUES (');
|
||||||
$columns = count($row);
|
$columns = count($row);
|
||||||
$rowsarr = array();
|
|
||||||
for($j=0; $j<$columns; $j++) {
|
for($j=0; $j<$columns; $j++) {
|
||||||
// Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
|
// Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
|
||||||
if ($row[$j] == null and !is_string($row[$j])) {
|
if ($row[$j] == null and !is_string($row[$j])) {
|
||||||
@ -479,8 +486,8 @@ SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";
|
|||||||
}
|
}
|
||||||
fwrite($handle,implode(',', $row).");\n");
|
fwrite($handle,implode(',', $row).");\n");
|
||||||
}
|
}
|
||||||
fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking
|
if (GETPOST("nobin_disable_fk")) fwrite($handle, "ALTER TABLE `".$table."` ENABLE KEYS;\n"); // Enabling back the keys/index checking
|
||||||
//fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table
|
if (!GETPOST("nobin_nolocks")) fwrite($handle, "UNLOCK TABLES;\n"); // Unlocking the table
|
||||||
fwrite($handle,"\n\n\n");
|
fwrite($handle,"\n\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,11 +511,10 @@ SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";
|
|||||||
/* Backup Procedure structure*/
|
/* Backup Procedure structure*/
|
||||||
|
|
||||||
// Write the footer (restore the previous database settings)
|
// Write the footer (restore the previous database settings)
|
||||||
$sqlfooter='';
|
$sqlfooter="\n\n";
|
||||||
$sqlfooter.="
|
if (GETPOST("nobin_use_transaction")) $sqlfooter .= "COMMIT;\n";
|
||||||
SET FOREIGN_KEY_CHECKS=1;
|
if (GETPOST("nobin_disable_fk")) $sqlfooter .= "SET FOREIGN_KEY_CHECKS=1;\n";
|
||||||
|
$sqlfooter.="\n\n-- Dump completed on ".date('Y-m-d G-i-s');
|
||||||
-- Dump completed on ".date('Y-m-d G-i-s');
|
|
||||||
fwrite($handle, $sqlfooter);
|
fwrite($handle, $sqlfooter);
|
||||||
|
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user