diff options
| author | Horus3 | 2015-03-25 18:02:11 +0100 |
|---|---|---|
| committer | Horus3 | 2015-03-25 18:02:11 +0100 |
| commit | 5018d9f3aadfcbbac3c41c142fc2a29caac38b12 (patch) | |
| tree | 334ce5bd0fc5f20a427b62a8e8102d5fbcd0c8d0 | |
| parent | 323716c9fdd59021c0c3a1fdf900108ace857e41 (diff) | |
| download | dotfiles-5018d9f3aadfcbbac3c41c142fc2a29caac38b12.tar.gz | |
Add script to backup mysql databases.
| -rwxr-xr-x | bin/backup_mysql.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/bin/backup_mysql.sh b/bin/backup_mysql.sh new file mode 100755 index 0000000..eea03bd --- /dev/null +++ b/bin/backup_mysql.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Backup all databases in a MySQL or MariaDB server. + +password="$1" + +if [ -z $password ]; then + echo "Usage: $0 MYSQL_ROOT_PASSWORD" 1>&2 + exit 1 +fi + +for i in $(mysql -u root -p${password} -e "show databases;" | grep -E '\w' | tail -n +2); do + if [[ $i != "information_schema" ]]; then + echo "Doing backup for database $i..." + mysqldump -u root -p${password} $i > $i.sql + fi +done |
