-
-
Save BrunoMoreno/e7f7cfd4a4961d012e88 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
OUTPUT="/path/to/backup/folder" | |
HOST="mysql_host" | |
DATE=`date +%d%m%y%H%M` | |
databases=`mysql --host=$HOST --user=$USER --password=$PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` | |
for db in $databases; do | |
if [ "$db" != "performance_schema" ] && [ "$db" != "information_schema" ] ; then | |
mysqldump -u $USER -p${PASS} $db | gzip > ${OUTPUT}dbbackup_${db}_${DATE}.bak.gz | |
fi | |
done | |
#remove backups 7 days older or more | |
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