Created
November 16, 2020 19:00
-
-
Save DavidEredics/a65b6ed60de73c9a94c421a6f6bce6ff to your computer and use it in GitHub Desktop.
Shell script to backup mysql database and/or specific table
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
#!/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