forked from aliaskov/bashscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBBackup.sh
More file actions
12 lines (12 loc) · 724 Bytes
/
DBBackup.sh
File metadata and controls
12 lines (12 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
USER="root"
PASSWORD="PASS"
HOST="HOST"
mysql -u $USER -p$PASSWORD -h $HOST --silent -e 'SELECT table_schema "DB Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in Mb" FROM information_schema.tables GROUP BY table_schema;'
databases=`mysql -u $USER -p$PASSWORD -h $HOST --silent -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
echo "Dumping database: $db"
mysqldump -d -u $USER -p$PASSWORD -h $HOST --single-transaction --order-by-primary --compress --databases $db > `date +%Y%m%d`.$db.sql
fi
done