http://blog.csdn.net/clj198606061111/article/details/45420311
一、执行环境
操作系统:linux redhat
数据库:mysql 5.6
二、备份规划
1.数据备份位置
/opt/www/back/database/pac/data
2.备份日志位置
/opt/www/back/database/pac/logs
3.shell脚本位置
/opt/soft/scripts/mysqldaiybak.sh
4.每天凌晨3:10执行全量备份
三、my.conf配置备份用户
mysql5.6不允许直接在mysqldump 命令里面输入用户名、密码执行导出,但是允许在my.conf里面直接配置好mysqldump的用户密码,在执行mysqldump命令的时候无需显示输入用户密码了。
在/opt/soft/mysql/my.conf末尾添加如下配置项。
- [mysqldump]
- user=mysql_backup_user_name
- password=mysql_packup_password
四、编辑shell脚本
1.创建shell脚本
mkdir /opt/soft/scripts/mysqldaiybak.sh
2.赋予shell脚本可执行权限
chmod 755 /opt/soft/scripts/mysqldaiybak.sh
3.完整的shell脚本
- #!/bin/bash
- #This is mysql mysqldaiybak scripts
- #2015-05-01
- database=kuanrf_pac
- databak_dir=/opt/www/back/database/pac/data
- logs_dir=/opt/www/back/database/pac/logs
- dumpbin=/opt/soft/mysql/bin/mysqldump
- DATE=$(date +%Y%m%d)
- logFile=$logs_dir/kuanrf_pac$DATE.log
- echo " " > $logFile
- echo "-----------------------------------" >> $logFile
- echo "kuanrf_pac backup start" >> $logFile
- echo $(date +"%y-%m-%d %H:%M:%S") >> $logFile
- echo "-----------------------------------" >> $logFile
- $dumpbin $database >$databak_dir/kuanrf_pac_bak$DATE.sql
- echo "-----------------------------------" >> $logFile
- echo "kuanrf_pac backup end" >> $logFile
- echo $(date +"%y-%m-%d %H:%M:%S") >> $logFile
- echo "-----------------------------------" >> $logFile
1.执行如下命令,打开定时任务配置文件
- crontab -e
2.vi编辑器操作,插入如下配置项,保存
- 10 3 * * 1-6 /opt/soft/scripts/mysqldaiybak.sh
3.查看定时任务是否配置成功
- crontab -l
- /sbin/service crond restart
5.查看定时任务是否已经运行
- ps -ax | grep cron