Skip to content

Instantly share code, notes, and snippets.

@7ochem
Forked from Rud5G/magento-db-dump.sh
Last active December 12, 2015 10:49
Show Gist options
  • Save 7ochem/4761744 to your computer and use it in GitHub Desktop.
Save 7ochem/4761744 to your computer and use it in GitHub Desktop.
(MySQLDUMP_DATABASE=$(sed -n 's/^.*<dbname><!\[CDATA\[\(.*\)\]\]><\/dbname>.*/\1/p' app/etc/local.xml | head -n1) \
&& \
mysqldump -h$(sed -n 's/^.*<host><!\[CDATA\[\(.*\)\]\]><\/host>.*/\1/p' app/etc/local.xml | head -n1) \
-u$(sed -n 's/^.*<username><!\[CDATA\[\(.*\)\]\]><\/username>.*/\1/p' app/etc/local.xml | head -n1) \
-p$(sed -n 's/^.*<password><!\[CDATA\[\(.*\)\]\]><\/password>.*/\1/p' app/etc/local.xml | head -n1) \
$MySQLDUMP_DATABASE \
--ignore-table=${MySQLDUMP_DATABASE}.core_cache \
--ignore-table=${MySQLDUMP_DATABASE}.core_cache_tag \
--ignore-table=${MySQLDUMP_DATABASE}.log_url \
--ignore-table=${MySQLDUMP_DATABASE}.log_url_info \
--ignore-table=${MySQLDUMP_DATABASE}.log_visitor \
--ignore-table=${MySQLDUMP_DATABASE}.log_visitor_info \
--ignore-table=${MySQLDUMP_DATABASE}.log_customer \
--ignore-table=${MySQLDUMP_DATABASE}.log_quote \
--ignore-table=${MySQLDUMP_DATABASE}.report_event \
--ignore-table=${MySQLDUMP_DATABASE}.report_viewed_product_index \
--ignore-table=${MySQLDUMP_DATABASE}.index_event \
--ignore-table=${MySQLDUMP_DATABASE}.index_process_event \
--ignore-table=${MySQLDUMP_DATABASE}.dataflow_batch_export \
--ignore-table=${MySQLDUMP_DATABASE}.dataflow_batch_import \
&& \
mysqldump -h$(sed -n 's/^.*<host><!\[CDATA\[\(.*\)\]\]><\/host>.*/\1/p' app/etc/local.xml | head -n1) \
-u$(sed -n 's/^.*<username><!\[CDATA\[\(.*\)\]\]><\/username>.*/\1/p' app/etc/local.xml | head -n1) \
-p$(sed -n 's/^.*<password><!\[CDATA\[\(.*\)\]\]><\/password>.*/\1/p' app/etc/local.xml | head -n1) \
$MySQLDUMP_DATABASE \
--no-data \
core_cache core_cache_tag \
log_url log_url_info log_visitor log_visitor_info log_customer log_quote \
report_event report_viewed_product_index \
index_event index_process_event \
dataflow_batch_export dataflow_batch_import \
) | gzip -c > ${PWD##*/}_$(date +%Y-%m-%d_%H%M%S).sql.gz
@7ochem
Copy link
Author

7ochem commented Sep 4, 2014

Of course you can also use the great n98-magerun.phar:
n98-magerun.phar db:dump -cgzip --strip="@development" (includes stripping customer and sales data)

Most ideal for dev to dev dump:
n98-magerun.phar db:dump -cgzip --strip="@stripped catalogsearch_* core_cache* index*event"

For enterprise, add enterprise_logging_event* (excluding enterprise_logging_event and enterprise_logging_event_changes tables)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment