Proactively back up MySQL scripts every day

Source: Internet
Author: User

Run the script at timed intervals:
1. Operation

crontab-e XX * * * * /bin/bash yourpath/mysqlbak.sh2. Open your own initiative to run the fileVi/etc/crontabAdditions such as the following are included in the etc. Let them run the task on their own initiative.XX * * * * root/mysqlbak.shAbove two 00 00 * * * To run the script for the early hours of the day

Time-sharing Weekly command

M: Minutes (0-59). Every minute with * or */1
H: Hours (0-23).

(0 means 0 points)
D: Day (1-31).


M: Month (1-12).
D: Day of the Week (0~6,0 is Sunday).

run */5 every five minutes * * * *runs per hour 0 * * * *Daily Run 0 0 * * *Weekly Run 0 0 * 0Monthly Run 0 0 1 * *Run 0 0 1 1 per year *Restart Cron/etc/rc.d/init.d/crond RestartOrService Crond RestartPlease see Crond wiki for details.
http://zh.wikipedia.org/wiki/Cronmysqlback.sh #!/bin/bash #功能说明: This feature is used to back up the database #编写日期: 2010/12/06 Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin Export PATH #数据库username dbuser= ' root ' #数据库password dbpasswd= ' 123456′ #数据库名, you can define multiple databases. The middle is separated by a space, such as: Test test1 test2 dbname= ' test1 test2′ #备份时间 backtime= ' Date +%y%m%d%h%m%s ' #日志备份路径 logpath= '/second/backup ' #数据备份路径 datapath= '/second/backup ' #日志记录头部 echo ' "Backup Time is ${backtime}, back Up database table ${dbname} start" >> ${logpath}/mysqllog.log #正式备份数据库For table in $dbname; source= ' Mysqldump-u ${dbuser}-p${dbpasswd} ${table}> ${logpath}/${backtime}.sql ' 2>> ${logpath}/ Mysqllog.log; #备份成功下面操作 if ["$?" = = 0];then CD $datapath #为节约硬盘空间, compress the database tar jcf ${table}${backtime}.tar.bz2 ${backtime}.sql >/dev/null #删除原始文件, just stay compressed after the file rm-f ${datapath}/${backtime}.sql echo "database table ${dbname} backup succeeded!!" >> ${logpath}/mysqllog.log Else #备份失败则进行下面操作 echo "database table ${dbname} backup failed!" >> ${logpath}/mysqllog.log fi Done

Here is an introduction
10 tutorials for MySQL database backup

Http://www.linuxde.net/2012/03/9379.html

Proactively back up MySQL scripts every day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.