Skip to content

Instantly share code, notes, and snippets.

@lnfnunes
Created December 21, 2017 02:24
Show Gist options
  • Save lnfnunes/301da8bf16794672ba17261feea0c9d4 to your computer and use it in GitHub Desktop.
Save lnfnunes/301da8bf16794672ba17261feea0c9d4 to your computer and use it in GitHub Desktop.
Script to dump database excluding some tables
#!/bin/bash -e
HOST=XXXXXX
USER=XXXXXX
PASSWORD=XXXXXX
DATABASE=databasename
DB_FILE=backupDB_$(date +"%Y%m%d_%H%M").sql
EXCLUDED_TABLES=(
table1
table2
table3
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
done
echo "Dump structure"
mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} --single-transaction --no-data ${DATABASE} > ${DB_FILE}
echo "Dump content"
mysqldump --host=${HOST} --user=${USER} --password=${PASSWORD} ${DATABASE} --no-create-info ${IGNORED_TABLES_STRING} >> ${DB_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment