Skip to content

Instantly share code, notes, and snippets.

@alistaircol
Created December 8, 2020 18:28
Show Gist options
  • Save alistaircol/7dac533f056cec38cd19b2571a52e4a0 to your computer and use it in GitHub Desktop.
Save alistaircol/7dac533f056cec38cd19b2571a52e4a0 to your computer and use it in GitHub Desktop.
Simple bash script to dump schema structure, select tables and data
#!/usr/bin/env bash
# --column-statistics=0: https://serverfault.com/a/912677/530593
DUMP_COMMAND="mysqldump \
--column-statistics=0 \
--host=db.ac93.uk \
--user=user \
--password=password"
function dump_crm_structure
{
# when dumping crm structure, ignore this table
IGNORE_CRM_TABLES=(
"ignore_1"
)
CRM_STRUCTURE="$DUMP_COMMAND \
ac_crm \
--no-data \
--skip-triggers"
for table in ${IGNORE_CRM_TABLES[*]}; do
CRM_STRUCTURE+="\
--ignore-table=ac93_crm.$table"
done
$CRM_STRUCTURE >> crm.sql
}
function dump_crm_data
{
# when dumping data, only use these tables
DATA_CRM_TABLES=(
"allow_1"
)
CRM_DATA="$DUMP_COMMAND \
ac_crm \
--no-create-info \
--skip-triggers \
${DATA_CRM_TABLES[*]}"
$CRM_DATA >> crm.sql
}
# dump only these internal tables and data
DATA_INTERNAL_TABLES=(
"allow_1"
)
function dump_internal_structure
{
INTERNAL_STRUCTURE="$DUMP_COMMAND \
--no-data \
ac93_internal \
${DATA_INTERNAL_TABLES[*]}"
$INTERNAL_STRUCTURE >> crm.sql
}
function dump_internal_data
{
INTERNAL_DATA="$DUMP_COMMAND \
--no-create-info \
--skip-triggers \
ac93_internal \
${DATA_INTERNAL_TABLES[*]}"
$INTERNAL_DATA >> crm.sql
}
rm crm.sql
dump_crm_structure
dump_crm_data
dump_internal_structure
dump_internal_data
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment