Automatic daily backup of mysql script _ MySQL

Source: Internet
Author: User
Every day, the mysql script is automatically backed up and scheduled to execute the script:
1. execute

Crontab-e 00 00 ***/bin/bash yourpath/mysqlbak. sh2. open the automatic execution file vi/etc/crontab and add the following content to etc to enable it to automatically execute the task. 00 00 *** root/mysqlbak. sh and above 00 *** are automatically executed every morning

Hour, day, month, and Week commands

M: minute (0-59 ). Each minute is represented by * or */1.
H: Hour (0-23 ). (0 indicates 0)
D: Day (1-31 ).
M: month (1-12 ).
D: days in a week (0 ~ 6, 0 is Sunday ).

Execute every five minutes */5 * execute 0 * every hour * execute 0 0 every day * execute 0 0 every week * 0 execute 0 0 every month * every year execute 0 0 1 1 * restart cron/etc/rc. d/init. for details about d/crond restartorservice crond restart, see the crond wiki.
Http://zh.wikipedia.org/wiki/Cron: mysqlback. sh #! /Bin/bash # Function description: This function is used to back up a database. # Prepared on: 2010/12/06 PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin Export PATH # Database username Dbuser = 'root' # Database password Dbpasswd = '000000 ′ # Database name. you can define multiple databases separated by spaces, for example, test test1 test2. Dbname = 'test1 test2 ′ # Backup time Backtime = 'date + % Y % m % d % H % M % s' # Log backup path Logpath = '/second/backup' # Data backup path Datapath = '/second/backup' # Log record header Echo '"backup time is $ {backtime}, backup database table $ {dbname} starts" >$ {logpath}/mysqllog. log # Formally back up the database For table in $ dbname; do Source = 'mysqldump-u $ {dbuser}-p $ {dbpasswd }$ {table }>$ {logpath}/$ {backtime }. SQL '2 >>$ {logpath}/mysqllog. log; # Successful backup: If ["$? "= 0]; then Cd $ datapath # Compressing the database to save hard disk space Tar jcf zookeeper table1_zookeeper backtime=.tar.bz2 $ {backtime}. SQL>/dev/null # Delete the original file, leaving only the compressed file Rm-f $ {datapath}/$ {backtime}. SQL Echo "database table $ {dbname} has been backed up successfully !!" >>$ {Logpath}/mysqllog. log Else # If the backup fails, perform the following operations: Echo "database table $ {dbname} backup failed !!" >>$ {Logpath}/mysqllog. log Fi Done

Here is an introduction
10 tutorials on MySQL database backup

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

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.