Last active
October 30, 2022 18:36
-
-
Save deevis/8cb7c76964212ab1d0d6a2b904d33b3b to your computer and use it in GitHub Desktop.
Backup all MySQL (MariaDB) databases
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 | |
_now=$(date +"%F_%H_%M%P") | |
pushd /mnt2/backups/mysql/ | |
for db_name in `mysql -h 127.0.0.1 -u root -e "show databases;" | grep "\|" | grep -v "_schema" | grep -v "mysql" | tail -n +2`; do | |
echo "Backing up ${db_name}" | |
filename="${db_name}_${_now}.sql" | |
mysqldump -h 127.0.0.1 -u root $db_name > ${filename} | |
done | |
tar cvfz mysql_pi_${_now}.tar.gz $(ls *${_now}*.sql) && rm *${_now}*.sql | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment