Skip to content

Instantly share code, notes, and snippets.

@deevis
Last active October 30, 2022 18:36
Show Gist options
  • Save deevis/8cb7c76964212ab1d0d6a2b904d33b3b to your computer and use it in GitHub Desktop.
Save deevis/8cb7c76964212ab1d0d6a2b904d33b3b to your computer and use it in GitHub Desktop.
Backup all MySQL (MariaDB) databases
#!/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