Skip to content

Instantly share code, notes, and snippets.

@rogersguedes
Created January 26, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogersguedes/8401e37c5a03ba370981f10a208db94c to your computer and use it in GitHub Desktop.
Save rogersguedes/8401e37c5a03ba370981f10a208db94c to your computer and use it in GitHub Desktop.
This scripts generate a mysqldump commands to backup a MySQL database into two separate files. One for tables creation only and other for for data insertion;
#!/bin/bash
discendingTime(){
date '+%Y.%m.%d.%H.%M.%S'
}
TIME_NOW=$(discendingTime)
HOST=$1
PORT=$2
USER=$3
DATABASE=$4
DB_FILE=$5-${DATABASE}-${TIME_NOW}
EXCLUDED_TABLES=(
)
IGNORED_TABLES_STRING=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
IGNORED_TABLES_STRING+=" --ignore-table=${DATABASE}.${TABLE}"
done
echo "# Dump structure"
echo "mysqldump --host=${HOST} --port=${PORT} --user=${USER} -p --single-transaction --no-data ${DATABASE} > ${DB_FILE}-DDL.sql"
echo "# Dump content"
echo "mysqldump --complete-insert --host=${HOST} --port=${PORT} --user=${USER} -p ${DATABASE} --no-create-info ${IGNORED_TABLES_STRING} > ${DB_FILE}-DATA.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment