Skip to content

Instantly share code, notes, and snippets.

@ScribeOfGoD
Forked from simonda86/gist:6305487
Created October 10, 2016 18:57
Show Gist options
  • Save ScribeOfGoD/e0fa6b19e45c3573a5d5229dc76f0b0d to your computer and use it in GitHub Desktop.
Save ScribeOfGoD/e0fa6b19e45c3573a5d5229dc76f0b0d 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment