Skip to content

Instantly share code, notes, and snippets.

@DavidEredics
Created November 16, 2020 19:00
Show Gist options
  • Save DavidEredics/a65b6ed60de73c9a94c421a6f6bce6ff to your computer and use it in GitHub Desktop.
Save DavidEredics/a65b6ed60de73c9a94c421a6f6bce6ff to your computer and use it in GitHub Desktop.
Shell script to backup mysql database and/or specific table
#!/bin/sh
date=$(date +"%Y-%m-%d")
now=$(date --iso-8601=seconds)
dbname=''
table1=''
options="--defaults-extra-file=/path/mysql-credentials.cnf --no-tablespaces"
LOGFILE=/path/dbBackupErrors.txt
OUTPUT_DB=/path/database_${dbname}_${date}.sql
OUTPUT_TABLE1=/path/table_${table1}_${date}.sql
echo "[${now}]" >> $LOGFILE
#backup database
/usr/bin/mysqldump $options $dbname 2>> $LOGFILE 1> $OUTPUT_DB
#backup table
/usr/bin/mysqldump $options $dbname $table1 2>> $LOGFILE 1> $OUTPUT_TABLE1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment