Skip to content

Instantly share code, notes, and snippets.

@lukas-mertens
Last active January 5, 2019 18:59
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 lukas-mertens/c7649ba44b14454fa08053b4a427697c to your computer and use it in GitHub Desktop.
Save lukas-mertens/c7649ba44b14454fa08053b4a427697c to your computer and use it in GitHub Desktop.
#!/bin/bash
BACKUP_DIR="/opt/backup/mysql-backup"
MYSQL_USR="root"
MYSQL_PWD="your-password"
MYSQL_CMD=/usr/bin/mysql
MYSQL_DMP=/usr/bin/mysqldump
databases=`$MYSQL_CMD --user=$MYSQL_USR -p$MYSQL_PWD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
for db in $databases; do
echo "Dumping $db ..."
$MYSQL_DMP --force --opt --user=$MYSQL_USR -p$MYSQL_PWD --databases $db | gzip > "$BACKUP_DIR/$db.gz"
done
echo "-- DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment