#!/bin/bash
db_PATH='/shareSAN/mysqldata/ocs/mysql_back_wjf' #备份文件保存的路径
#db_DBNAME='sz_ocs' #备份的数据库名
db_DBNAME='newocs' #备份的数据库名
db_HOST='127.0.0.1' #mysql服务ip
db_PORT='3306' #端口
db_USER='root' #用户名
db_PASSWORD='zhoulih_321' #密码
db_DATE=$(date -d now +"%Y%m%d%H%M") #格式化的日期
echo "-------$(date -d now +"%Y-%m-%d %H:%M:%S") begin datedump------" >> ${db_PATH}/db_backup.log
echo 'doing....' >> ${db_PATH}/db_backup.log
/usr/local/mysql/bin/mysqldump -h$db_HOST -P$db_PORT -u$db_USER -p$db_PASSWORD --opt -q --flush-logs --master-data=2 -R --hex-blob --databases $db_DBNAME > ${db_PATH}/${db_DBNAME}${db_DATE}.sql
echo 'success!' >> ${db_PATH}/db_backup.log
echo "-------$(date -d now +"%Y-%m-%d %H:%M:%S") end datedump------" >> ${db_PATH}/db_backup.log
echo "=====================================================" >> ${db_PATH}/db_backup.log
echo '' >> ${db_PATH}/db_backup.log
转载于:https://www.cnblogs.com/wujf-myblog/p/10577229.html