Created
June 26, 2024 18:46
-
-
Save joshuafredrickson/47df10352a831d85d06c5598feae952e to your computer and use it in GitHub Desktop.
Back up all MariaDB/MySQL databases and optionally exclude certain dbs
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 | |
# Set up variables | |
DBUSER="" | |
DBPASSWORD="" | |
DESTINATION="/volumes/external/mariadb" | |
EXCLUDE_DB="information_schema|performance_schema|mysql|sys" # Add any databases you want to exclude | |
# Get the list of databases | |
DBS=$(mysql -u $DBUSER -p$DBPASSWORD -e "SHOW DATABASES;" | grep -Ev "Database|$EXCLUDE_DB") | |
# Dump each database | |
for DB in $DBS; do | |
mysqldump -u $DBUSER -p$DBPASSWORD --databases $DB | gzip > $DESTINATION/$DB.sql.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment