Last active
February 22, 2021 04:01
-
-
Save hoangdh/818cdc65afd64faab47df3ea9f9f1e25 to your computer and use it in GitHub Desktop.
Dump all database on MySQL/MariaDB systems.
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/bash | |
BACKUP_DIR="/opt/backup" | |
mkdir -p ${BACKUP_DIR} | |
## Get all databases on system | |
USER="root" | |
PASSWORD="" | |
DBS=`mysql -u ${USER} -p${PASSWORD} -sNe "SHOW DATABASES;" | grep -Ev "information_schema|performance_schema|mysql|test"` | |
for DB in ${DBS} | |
do | |
TIMESTAMP=$(date +%Y%m%d) | |
DBNAME="${DB}-$TIMESTAMP" | |
mysqldump -u $USER -p$PASSWORD --events --routines --triggers --databases ${DB} | gz > "${BACKUP_DIR}/${DBNAME}.sql.gz" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment