Skip to content

Instantly share code, notes, and snippets.

@frengky
Created February 10, 2016 10:30
Show Gist options
  • Save frengky/1890403dbb15942eaf42 to your computer and use it in GitHub Desktop.
Save frengky/1890403dbb15942eaf42 to your computer and use it in GitHub Desktop.
#!/bin/sh
BACKUPDIR="/usr/backup/databases"
TODAY=$(date '+%Y-%m-%d')
DATABASES=$(echo "show databases;" | mysql)
mkdir -p "${BACKUPDIR}/${TODAY}"
for DB in $DATABASES; do
if [ "$DB" != "Database" ] && \
[ "$DB" != "mysql" ] && \
[ "$DB" != "information_schema" ] && \
[ "$DB" != "performance_schema" ] && \
[ "$DB" != "test" ]; then
## echo "db: $DB"
mysqldump --databases "$DB" | xz > "${BACKUPDIR}/${TODAY}/${TODAY}_${DB}.sql.xz"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment