Last active
June 4, 2018 17:42
-
-
Save TheRatG/f3c6be7031b8ceec027da1fd85c40f1c to your computer and use it in GitHub Desktop.
mysqldump excluded tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PASSWORD=password | |
USER=user | |
DATABASE=database | |
DB_FILE=/tmp/${DATABASE}.sql.gz | |
EXCLUDED_TABLES=( | |
table_1 | |
table_2 | |
table_3 | |
) | |
IGNORED_TABLES_STRING='' | |
for TABLE in "${EXCLUDED_TABLES[@]}" | |
do : | |
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}" | |
done | |
mysqldump --no-data --skip-lock-tables --skip-add-locks --routines --user=${USER} --password=${PASSWORD} ${DATABASE} | gzip > ${DB_FILE}; | |
mysqldump --no-create-info --skip-lock-tables --skip-add-locks --extended-insert -u${USER} -p${PASSWORD} ${DATABASE} ${IGNORED_TABLES_STRING} | gzip >> ${DB_FILE}; | |
echo "${DB_FILE}"; | |
# import | |
# zcat ${DB_FILE} | mysql --user=${USER} --password=${PASSWORD} -D${DATABASE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment