Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Forked from richardfeliciano/BackUpMysql
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juniorb2ss/b2f789142e313050b582 to your computer and use it in GitHub Desktop.
Save juniorb2ss/b2f789142e313050b582 to your computer and use it in GitHub Desktop.
#!/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