Skip to content

Instantly share code, notes, and snippets.

@Rud5G
Last active March 3, 2020 17:11
Show Gist options
  • Save Rud5G/4739140 to your computer and use it in GitHub Desktop.
Save Rud5G/4739140 to your computer and use it in GitHub Desktop.
1. set host+user+pass+db 2. dump without logs, etc.3. tail for completed (check dump)4. dump logs structure, etc.5. tail for completed (check dump)6. compress ps: possible to set the password to empty string? (which asks for the password on commandline). (= not tested).
export MySQLDUMP_HOSTNAME=
export MySQLDUMP_USERNAME=
export MySQLDUMP_DATABASE=
export MySQLDUMP_PASSWORD=
export MySQLTABLE_PREFIX=
mysqldump -p$MySQLDUMP_PASSWORD -h$MySQLDUMP_HOSTNAME -u$MySQLDUMP_USERNAME ${MySQLDUMP_DATABASE} \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}core_cache \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}core_cache_tag \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_url \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_url_info \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_visitor \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_visitor_info \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_customer \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}log_quote \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}report_event \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}report_viewed_product_index \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}index_event \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}index_process_event \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}dataflow_batch_export \
--ignore-table=${MySQLDUMP_DATABASE}.${MySQLTABLE_PREFIX}dataflow_batch_import \
> "mysqldb-${MySQLDUMP_DATABASE}.sql";
tail -n1 mysqldb-${MySQLDUMP_DATABASE}.sql ;
mysqldump -p$MySQLDUMP_PASSWORD -h$MySQLDUMP_HOSTNAME -u$MySQLDUMP_USERNAME ${MySQLDUMP_DATABASE} \
--no-data \
${MySQLTABLE_PREFIX}core_cache \
${MySQLTABLE_PREFIX}core_cache_tag \
${MySQLTABLE_PREFIX}log_url \
${MySQLTABLE_PREFIX}log_url_info \
${MySQLTABLE_PREFIX}log_visitor \
${MySQLTABLE_PREFIX}log_visitor_info \
${MySQLTABLE_PREFIX}log_customer \
${MySQLTABLE_PREFIX}log_quote \
${MySQLTABLE_PREFIX}report_event \
${MySQLTABLE_PREFIX}report_viewed_product_index \
${MySQLTABLE_PREFIX}index_event \
${MySQLTABLE_PREFIX}index_process_event \
${MySQLTABLE_PREFIX}dataflow_batch_export \
${MySQLTABLE_PREFIX}dataflow_batch_import \
>> "mysqldb-${MySQLDUMP_DATABASE}.sql";
tail -n1 mysqldb-${MySQLDUMP_DATABASE}.sql ;
gzip mysqldb-${MySQLDUMP_DATABASE}.sql ;
@7ochem
Copy link

7ochem commented Feb 12, 2013

Misschien credentials direct uitlezen:
mysqldump -hsed -n 's/^._<host><![CDATA[(._)]]><\/host>._/\1/p' app/etc/local.xml | head -n1
-used -n 's/^._<username><![CDATA[(._)]]><\/username>._/\1/p' app/etc/local.xml | head -n1
-psed -n 's/^._<password><![CDATA[(._)]]><\/password>._/\1/p' app/etc/local.xml | head -n1
sed -n 's/^._<dbname><![CDATA[(._)]]><\/dbname>._/\1/p' app/etc/local.xml | head -n1\

@Rud5G
Copy link
Author

Rud5G commented May 18, 2013

Possible, but then i would depend on having access to the source code next to the database.
But nice idea, maybe adding them to environmental variables.

Notice that, when you omit the password value for "export MySQLDUMP_PASSWORD=", mysqldump prompts for the password.
So its not stored in your history.

@leaoaugusto
Copy link

Hi, And how about removing the triggers definers from the file as well?

Currently I have to manually run this command:

sed -E 's/DEFINER=[^]+@[^]+/DEFINER=CURRENT_USER/g' my_db_dump.sql > my_db_dump.sql.portable.sql

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