全量备份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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容