Skip to content

Instantly share code, notes, and snippets.

@hoangdh
Last active February 22, 2021 04:01
Show Gist options
  • Save hoangdh/818cdc65afd64faab47df3ea9f9f1e25 to your computer and use it in GitHub Desktop.
Save hoangdh/818cdc65afd64faab47df3ea9f9f1e25 to your computer and use it in GitHub Desktop.
Dump all database on MySQL/MariaDB systems.
#!/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