mysql自动备份脚本

/##mysql自动备份脚本
/##写了一个mysql数据库的shell自动备份数据的脚本,在每日的12点和24点进行备份
/##
/##
/###!/bin/bash
/########################################################################
/### DATE: 2019-10-25 #
/### AUTHOR: zhangy_j #
/### FUNC: 判断指定数据库名,如未指定则退出该程序 #
/### 根据当前test测试数据库进行备份指定数据库 #
/### 该脚本可单独运行,也可在每日11点和23点自动调用 #
/### #
/###-------------|------------------------------------------------------#
/########################################################################
/###调取数据库密码文件
/##. /sbin/yujun/pswd >/dev/null 2>&1
/###设置备份文件存放位置
/##export BAK=/tmp/yujun >/dev/null 2>&1
/###mysqldump --opt --single-transaction -uroot -p$pass --master-data=2 -h49.4.11.31 3333 > /sbin/yujun/3333.sql
/###str=$"/n"
/###sstr=$(echo -e)
/###调取数据库备份文件
/##DATAFILE=${BAK}/datafile.db
/##DATA_DIR=${BAK}
/##BAK_DIR=${BAK}/bak
/##BAK_DT=date +%Y%m%d
/##BAK_LOG=${BAK_DIR}/databak${BAK_DT}_log
/##FILE_DT=dbdate +%H
/##############################Backup database host
/##DB_HOST="49.4.11.31"
/##############################Database backup user
/##DB_USER='root'
/##
/###Create backup directory
/##if [ ! -d ${BAK_DIR}/${BAK_DT} ]; then
/## mkdir -p ${BAK_DIR}/${BAK_DT} >/dev/null
/##fi
/##
/##if [ ! -f ${DATAFILE} ]
/##then
/##echo "$DATAFILE file does not exist! "
/##echo "请将要备份的数据库名放在$DATAFILE文件中!"
/##
/## exit
/##fi
/##
/##print_log(){
/## MYDATE=date +"%Y-%m-%d %H:%M:%S"
/##case ${2} in
/## 1)
/## printf "%-40s%s\n" "$1" "$3$4$5$6$7$8${9}"
/## printf "%-40s%s\n" "$1" "$3$4$5$6$7$8${9}" >> ${BAK_LOG}
/## ;;
/## *)
/## echo "input error" >> ${BAK_LOG}
/## ;;
/##esac
/##}
/##
/##cd ${BAK_DIR} || exit
/##
/###read -p "Please enter the database you want to back up : " DB
/##
/##
/##for i in cat $DATA_DIR/datafile.db
/##do
/## print_log "The database to be backed up is named: $i" "1"
/##
/##DB_FILE=${FILEDT}$i.sql
/##
/##echo "-----【date "+%Y/%m/%d %H:%M:%S"】Start backup ${i} data base-----" >>${BAK_LOG}
/##mysqldump --opt --single-transaction --master-data=2 -u$DB_USER -p$pass -h$DB_HOST ${i} > ${BAK_DIR}/${BAK_DT}/${DB_FILE}
/##echo "-----【date "+%Y/%m/%d %H:%M:%S"】Backup complete ${i} data base,Backup file ${DB_FILE}-----" >>${BAK_LOG}
/##done

上一篇:临时记录


下一篇:攻防世界Web_backup