MySQL backup script

Source: Internet
Author: User
Tags mysql backup

MySQL is widely used in small and midsize businesses, and the following script can be used for full backups in a production environment.

Backup scenario: Full backup every 1:30 A.M., with 30 days of backup data (binary logs can be opened for incremental backup and recovery)

The steps are as follows:

1 Creating a backup user on the database server

Mysql> Grant Select,lock tables on bbs.* to ' backupmysql ' @ ' 192.168.154.160 ' identified by ' backupmysql ';

Mysql>flush privileges;


2 test the database backup from the backup host (the MySQL server requires an open 3306 port)

Mysqldump-ubackupmysql-pbackupmysql-h 192.168.154.162--databases BBS > Bbs.sql


3 Writing the backup script (on the backup host)

cd/data/script/

Vim mysqlbackup.sh

#!/bin/bash

#Name: Backupmysql

#Date: 2017-03-04

#Author: ZWJ

#Mail: [Email protected]

#Function: Mysqlbackup

#Version: 1.1

Myuser= "Backupmysql"

Mypass= "Backupmysql"

Mysqlhost= "192.168.154.162"

myconn= "-u$myuser-p$mypass-h $MYSQLHOST"

mydb= "BBS"

Mydst= "/data/backup/"

Mycmd= "/usr/bin/mysqldump"

mytime=$ (Date +%f)

Name= "$MYDB-$MYTIME"

CD $MYDST

$MYCMD $MYCONN--databases $MYDB > $NAME. sql

/bin/tar zcf $NAME. sql.tar.gz $NAME. SQL--remove &>/dev/null

Find $MYDST-mtime +30-name "*.tar.gz"-exec rm-rf {} \;


4 Set up Scheduled tasks

Crontab-e

*/30 1 * * */data/script/mysqlbackup.sh


This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1905534

MySQL backup script

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.