Last active
February 3, 2020 19:57
-
-
Save richardfeliciano/33c91b5e6139fac3f733 to your computer and use it in GitHub Desktop.
Backup ALL MySql
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/bash | |
#your db settings | |
USER="db_root" | |
PASS="db_pass" | |
PATH="/path/to/backup/folder" | |
HOST="mysql_host" | |
DATE=`date +%d%m%y%H%M` | |
#get databases list | |
databases=`mysql --host=$HOST --user=$USER --password=$PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
#loop trough results | |
for db in $databases; do | |
#exclude performance_schema and information_schema databases | |
if [ "$db" != "performance_schema" ] && [ "$db" != "information_schema" ] ; then | |
#dump database, and gzip | |
mysqldump -u $USER -p${PASS} $db | gzip > ${PATH}dbbackup_${db}_${DATE}.bak.gz | |
fi | |
done | |
#remove backups older than 7 days(+7) modify this value if you want. | |
find /path/to/backup/folder/db* -mtime +7 -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment