Personal Mysql Backup

Date: 2022-08-20
#!/bin/bash
user=""
password=""
host=nx-mysql-2
dir=$(dirname $0)"/$(date --iso-8601)_$host"
mysqldump=$(which mysqldump)
mysql=$(which mysql)
# --disable-ssl
databases=`$mysql --host $host --port 3306 --ssl --user=$user --password=$password --batch --skip-column-names -e "SHOW DATABASES;" | grep -v 'mysql$\|information_schema\|performance_schema'`


set -x #echo on
mkdir -p $dir

for database in $databases; do
    $mysqldump \
        --host $host \
        --ssl \
        --user=$user --password=$password \
        --force \
        --quote-names --dump-date \
        --opt --single-transaction \
        --events --routines --triggers \
        --databases $database \
        --result-file="$dir/$database.sql"
done

# zip all files
7z a -tzip "$dir.zip" $dir
#rm -rf $dir
65690cookie-checkPersonal Mysql Backup