Skip to content

Instantly share code, notes, and snippets.

@joshuafredrickson
Created June 26, 2024 18:46
Show Gist options
  • Save joshuafredrickson/47df10352a831d85d06c5598feae952e to your computer and use it in GitHub Desktop.
Save joshuafredrickson/47df10352a831d85d06c5598feae952e to your computer and use it in GitHub Desktop.
Back up all MariaDB/MySQL databases and optionally exclude certain dbs
#!/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