Skip to content

Instantly share code, notes, and snippets.

@rinukkusu
Created January 31, 2019 14:05
Show Gist options
  • Save rinukkusu/3c948beea624c05f59db0bf8cd623138 to your computer and use it in GitHub Desktop.
Save rinukkusu/3c948beea624c05f59db0bf8cd623138 to your computer and use it in GitHub Desktop.
#!/bin/bash
USER="root"
PASSWORD=""
OUTPUT="/tmp/dbbackup/"
DATE=`date +%Y-%m-%d_%H-%M`
FOLDER="$OUTPUT"
rm -rf "$FOLDER"
mkdir "$OUTPUT"
mkdir "$FOLDER"
#rm "$FOLDER/*gz" > /dev/null 2>&1
databases=`mysql -u $USER -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump -u $USER --databases $db > $FOLDER/$db.sql
echo "Compressing database: $db"
gzip $FOLDER/$db.sql
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment