-
-
Save jbbn/a308445b719265a2b249 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DS', DIRECTORY_SEPARATOR); | |
function _getExtractSchemaStatement($sqlFileName, $db) | |
{ | |
$dumpSchema = 'mysqldump' . ' '; | |
$dumpSchema .= '--no-data' . ' '; | |
$dumpSchema .= '-u ' . $db['user'] . ' '; | |
$db['pass'] = (string) $db['pass']; | |
if (!empty($db['pass'])) { | |
$dumpSchema .= '-p' . $db['pass'] . ' '; | |
} | |
$dumpSchema .= '-h ' . $db['host'] . ' '; | |
$dumpSchema .= $db['name'] .' > ' . $sqlFileName; | |
return $dumpSchema; | |
} | |
function _getExtractDataStatement($sqlFileName, $db) | |
{ | |
$tables = array( | |
'adminnotification_inbox', | |
'aw_core_logger', | |
'dataflow_batch_export', | |
'dataflow_batch_import', | |
'log_customer', | |
'log_quote', | |
'log_summary', | |
'log_summary_type', | |
'log_url', | |
'log_url_info', | |
'log_visitor', | |
'log_visitor_info', | |
'log_visitor_online', | |
'index_event', | |
'report_event', | |
'report_viewed_product_index', | |
'report_compared_product_index', | |
'catalog_compare_item', | |
'catalogindex_aggregation', | |
'catalogindex_aggregation_tag', | |
'catalogindex_aggregation_to_tag' | |
); | |
$ignoreTables = ' '; | |
foreach($tables as $table) { | |
$ignoreTables .= '--ignore-table=' . $db['name'] . '.' . $db['pref'] . $table . ' '; | |
} | |
$dumpData = 'mysqldump' . ' '; | |
$dumpData .= $ignoreTables; | |
$dumpData .= '-u ' . $db['user'] . ' '; | |
$db['pass'] = (string) $db['pass']; | |
if (!empty($db['pass'])) { | |
$dumpSchema .= '-p' . $db['pass'] . ' '; | |
} | |
$dumpData .= '-h ' . $db['host'] . ' '; | |
$dumpData .= $db['name'] .' >> ' . $sqlFileName; | |
return $dumpData; | |
} | |
function export_tiny() | |
{ | |
$configPath = '.' . DS . 'app' . DS . 'etc' . DS . 'local.xml'; | |
$xml = simplexml_load_file($configPath, NULL, LIBXML_NOCDATA); | |
$db['host'] = $xml->global->resources->default_setup->connection->host; | |
$db['name'] = $xml->global->resources->default_setup->connection->dbname; | |
$db['user'] = $xml->global->resources->default_setup->connection->username; | |
$db['pass'] = $xml->global->resources->default_setup->connection->password; | |
$db['pref'] = $xml->global->resources->db->table_prefix; | |
$sqlFileName = 'var' . DS . $db['name'] . '-' . date('j-m-y-h-i-s') . '.sql'; | |
//Extract the DB schema | |
echo 'Extracting the DB schema...' . PHP_EOL; | |
$dumpSchema = _getExtractSchemaStatement($sqlFileName, $db); | |
exec($dumpSchema); | |
//Extract the DB data | |
echo 'Extracting the DB data...' . PHP_EOL; | |
$dumpData = _getExtractDataStatement($sqlFileName, $db); | |
exec($dumpData); | |
echo 'Finished!'; | |
} | |
export_tiny(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference:
http://inchoo.net/ecommerce/magento/magento-tip-get-a-small-sized-version-of-a-large-production-database/
https://gist.github.com/ceckoslab/4495889