Skip to content

Instantly share code, notes, and snippets.

@gieart87
Created January 26, 2016 14:19
Show Gist options
  • Save gieart87/1acf1d266d8a912cb256 to your computer and use it in GitHub Desktop.
Save gieart87/1acf1d266d8a912cb256 to your computer and use it in GitHub Desktop.
Backup MySQL databases into separated files and exclude some databases defined
#!/bin/bash
USER="root"
PASSWORD="root"
OUTPUT="/home/backup-dir"
rm "$OUTPUT/*gz" > /dev/null 2>&1
databases=`mysql --user=$USER --password=$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump --force --opt --user=$USER --password=$PASSWORD --databases $db > $OUTPUT/`date +%Y%m%d`.$db.sql
gzip $OUTPUT/`date +%Y%m%d`.$db.sql
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment