Last active
June 20, 2021 17:14
-
-
Save scr34m/4662366 to your computer and use it in GitHub Desktop.
MySQL backup script per day directory
This file contains 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 | |
export PATH=${PATH}:/usr/local/bin:/usr/bin | |
mysqldir="/data/backup/mysql" | |
date=`date +%Y-%m-%d` | |
dbdir="/var/lib/mysql" | |
if [ ! -d "${mysqldir}/${date}" ]; then | |
mkdir -p ${mysqldir}/${date} | |
fi | |
dbs=`ls ${dbdir}` | |
for db in ${dbs} | |
do | |
if [ -d ${dbdir}/${db} ] && [ "${db}" != "performance_schema" ]; then | |
mysqldump -Q -h localhost -u root -pPASSWORD ${db} > ${mysqldir}/${date}/${db}.sql | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment