Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Forked from timkuijsten/mysql_backup
Last active February 9, 2017 17:02
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 ryanburnette/9456453 to your computer and use it in GitHub Desktop.
Save ryanburnette/9456453 to your computer and use it in GitHub Desktop.
#! /bin/bash
TIMESTAMP=$(date +"%F")
BACKUP_DIR="./$TIMESTAMP"
MYSQL_USER="backup"
MYSQL_PASSWORD=""
mkdir $BACKUP_DIR
databases=`mysql --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
for db in $databases; do
mysqldump --force --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db --ignore-table=mysql.event | gzip > "$BACKUP_DIR/$db.gz"
done
@timkuijsten
Copy link

Using the password as an argument to the mysql* commands is insecure. Anyone who executes ps auxww while this script is running can see the password. I've updated my script to make this more clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment