全量備份mysql數據腳本

#!/bin/bash
# Databases that you wish to be backed up by this script. You can have any number of databases specified; encapsilate each database name in single quotes and separate each database name by a space.
#
# Example:
databases=( 'db1' 'db2' )

# The host name of the MySQL database server; usually 'localhost'
db_host="localhost"

# The port number of the MySQL database server; usually '3306'
db_port="3306"

# The MySQL user to use when performing the database backup.
db_user="test"

# The password for the above MySQL user.
db_pass="password"

# Date/time included in the file names of the database backup files.
datetime=$(date +'%Y%m%d%H%M%S')

# Directory to which backup files will be written. Should end with slash ("/").
backups_dir=/data/mysql-dump/$datetime

if [ ! -d "$backups_dir" ]; then
    mkdir -p  "$backups_dir"
fi

for db_name in ${databases[@]}; do
        # Create database backup and compress using gzip.
        mysqldump -u $db_user -h $db_host -P $db_port --password=$db_pass $db_name > $backups_dir/$db_name.sql
done

?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容