Created
September 12, 2018 17:14
-
-
Save geekbrit/6a7255a738ab070e300cbb77c30d8060 to your computer and use it in GitHub Desktop.
Backup all mysql databases, delete duplicate dump files
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 | |
databases=`mysql -h 127.0.0.1 -u root --batch --skip-column-names -e "SHOW DATABASES;" | grep -E -v "(information|performance)_schema"` | |
for db in $databases; do | |
echo "Dumping database: $db" | |
mysqldump -h 127.0.0.1 -u root --databases $db | head -n -1 > /root/Backups/`date +%d%H`.$db.sql | |
done | |
fdupes -rNdqio time /root/Backups |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This uses several ideas from https://stackoverflow.com/questions/9497869/export-and-import-all-mysql-databases-at-one-time
with the addition of deduping the saved dumpfiles (this required removing the last line of each dump file, which contains mysqldump's timestamp).
The password for root comes from a .my.cnf file (permissions set to 0600, ya have to be root to read it).