Skip to content

Instantly share code, notes, and snippets.

@noweh
Created May 24, 2022 09:07
Show Gist options
  • Save noweh/b965f2ac439ec7a7d75ac40ab1dc2c89 to your computer and use it in GitHub Desktop.
Save noweh/b965f2ac439ec7a7d75ac40ab1dc2c89 to your computer and use it in GitHub Desktop.
mysqldump skip content from some tables (for GDRP)
#!/bin/bash
HOST_NAME=XXXX
USER=XXXX
PASSWORD=XXXX
DATABASE_NAME=XXXX
DB_FILE=export.sql
EXCLUDED_TABLES=(
table1
table2
table3
table4
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE_NAME}.${TABLE}"
done
echo "Dump structure"
mysqldump --host=${HOST_NAME} --user=${USER} --password=${PASSWORD} --single-transaction --no-data --routines ${DATABASE_NAME} > ${DB_FILE}
echo "Dump content"
mysqldump --host=${HOST_NAME} --user=${USER} --password=${PASSWORD} ${DATABASE_NAME} --no-create-info --skip-triggers ${IGNORED_TABLES_STRING} >> ${DB_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment