Skip to content

Instantly share code, notes, and snippets.

@simonda86
Created August 22, 2013 10:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save simonda86/6305487 to your computer and use it in GitHub Desktop.
Save simonda86/6305487 to your computer and use it in GitHub Desktop.
MySQL Backup script for all databases
#!/bin/bash
user=""
password=""
host=""
backup_path="/path/to/your/home/_backup/mysql"
date=$(date +"%d-%b-%Y")
# Get list of databases
databases=$(mysql --user=$user --password=$password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)")
# Create folder using date
mkdir $backup_path/$date
# Create dumps for each database
for db in $databases
do
mysqldump --user=$user --password=$password --host=$host $db > $backup_path/$date/$db.sql
done
@bloodyburger
Copy link

use --routines

@parag007
Copy link

what if input of password should be hidden. How to do that?

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