Skip to content

Instantly share code, notes, and snippets.

@sergeycherepanov
Last active October 2, 2021 07:30
Show Gist options
  • Save sergeycherepanov/c01e63ada93a392099f3c9cbcfb67221 to your computer and use it in GitHub Desktop.
Save sergeycherepanov/c01e63ada93a392099f3c9cbcfb67221 to your computer and use it in GitHub Desktop.
Mysql Dumpers
#!/bin/bash
#
# headless run: bash <(curl -s -L 'https://bit.ly/m1dumper')
# or
# with specidic dump path: DUMPPATH=/tmp/magento1.sql.gz /bin/bash <(curl -s -L 'https://bit.ly/m1dumper')
set -x
set -e
[[ -f app/etc/local.xml ]] || { echo "Can't locate the 'app/etc/local.xml'"; exit 1; }
M1DBHOST=$(php -r 'echo explode(":", simplexml_load_file("app/etc/local.xml")->global->resources->default_setup->connection->host)[0] ?? "127.0.0.1";')
M1DBPORT=$(php -r 'echo explode(":", simplexml_load_file("app/etc/local.xml")->global->resources->default_setup->connection->host)[1] ?? "3306";')
M1DBUSER=$(php -r 'echo simplexml_load_file("app/etc/local.xml")->global->resources->default_setup->connection->username;')
M1DPASSWORD=$(php -r 'echo simplexml_load_file("app/etc/local.xml")->global->resources->default_setup->connection->password;')
M1DBNAME=$(php -r 'echo simplexml_load_file("app/etc/local.xml")->global->resources->default_setup->connection->dbname;');
DUMPPATH=${DUMPPATH-${HOME}/${M1DBNAME}_$(date +'%Y%m%d%H%M%S').sql.gz}
bash <(curl -s -L https://bit.ly/mysqldumper) -h${M1DBHOST} -P${M1DBPORT} -u${M1DBUSER} -p${M1DPASSWORD} \
--skip-table-data-like "customer_entity%" \
--skip-table-data-like "customer_address%" \
--skip-table-data-like "sales_%" \
--skip-table-data-like "log_%" \
${M1DBNAME} | gzip > ${DUMPPATH} \
&& echo "Saved to: ${DUMPPATH}"
#!/bin/bash
#
# headless run: bash <(curl -s -L 'https://bit.ly/m2dumper')
# or
# with specidic dump path: DUMPPATH=/tmp/magento2.sql.gz /bin/bash <(curl -s -L 'https://bit.ly/m2dumper')
set -x
set -e
[[ -f app/etc/env.php ]] || { echo "Can't locate the 'app/etc/env.php'"; exit 1; }
M2DBHOST=$(php -r 'echo explode(":", (require("app/etc/env.php"))["db"]["connection"]["default"]["host"])[0] ?? "127.0.0.1";')
M2DBPORT=$(php -r 'echo explode(":", (require("app/etc/env.php"))["db"]["connection"]["default"]["host"])[1] ?? "3306";')
M2DBUSER=$(php -r 'echo (require("app/etc/env.php"))["db"]["connection"]["default"]["username"];')
M2DPASSWORD=$(php -r 'echo (require("app/etc/env.php"))["db"]["connection"]["default"]["password"];')
M2DBNAME=$(php -r 'echo (require("app/etc/env.php"))["db"]["connection"]["default"]["dbname"];');
DUMPPATH=${DUMPPATH-${HOME}/${M2DBNAME}_$(date +'%Y%m%d%H%M%S').sql.gz}
bash <(curl -s -L https://bit.ly/mysqldumper) -h${M2DBHOST} -P${M2DBPORT} -u${M2DBUSER} -p${M2DPASSWORD} \
--skip-table-data-like "customer_entity%" \
--skip-table-data-like "customer_address%" \
--skip-table-data-like "sales_%" \
--skip-table-data-like "quote%" \
${M2DBNAME} | gzip > ${DUMPPATH} \
&& echo "Saved to: ${DUMPPATH}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment