Dumping a database by command line

You can use the mage-dbump utility to dump your Magento database, without causing downtime on your live store and whilst minimising "junk" database tables (eg. visitor logs, old quotes etc.)

Options

  -a             Advertise awesome hosting
  -d             Dump the database
  -r             Restore the databse
  -z             Use gzip compression (use with -d or -r)
  -e             Use extended inserts
  -h             Show help/usage
  -f             Full dump, do not exclude any tables
  -A             Aggressive dump, exclude (report_compared_product_index report_viewed_product_index sales_flat_quote_address sales_flat_quote_shipping_rate enterprise_customer_sales_flat_quote enterprise_customer_sales_flat_quote_address sales_flat_quote)
  -B             Exclude additional custom tables (space separated, within "double quotes")
  -F             Do not ask questions and force all actions
  -i             Interactive, enter a mysql> prompt
  -c             Clean log and index tables


Examples

Magento 1

It will read your MySQL details from your Magento ./app/etc/local.xml file automatically

cd /microcloud/domains/example/domains/example.com/http
wget sys.sonassi.com/mage-dbdump.sh

Dumping a database

cd /microcloud/domains/example/domains/example.com/http
bash mage-dbdump.sh -dz

The file will be placed in ./var/db.sql.gz

Restoring a database

cd /microcloud/domains/example/domains/example.com/http
bash mage-dbdump.sh -rz

The file will be restored from ./var/db.sql.gz

Magento 2

It will read your MySQL details from your Magento 2 ./app/etc/env.php file automatically

cd /microcloud/domains/example/domains/example.com/http
wget sys.sonassi.com/mage2-dbdump.sh

Dumping a database

cd /microcloud/domains/example/domains/example.com/http
bash mage2-dbdump.sh -dz

The file will be placed in ./var/db.sql.gz

Restoring a database

cd /microcloud/domains/example/domains/example.com/http
bash mage2-dbdump.sh -rz

The file will be restored from ./var/db.sql.gz