MySQL backup script

Source: Internet
Author: User

#Mysql备份脚本

#脚本说明

---------

This script defines the databases that need to be backed up according to different scenarios, and periodically deletes more than 30 days of data from the backup directory. The script is very simple, can take away the direct use, welcome colleagues to make comments. Thank you ~

#!/bin/bash

#auto backup MySQL Scripts

#by WANGHL 2016-01-28

#define Path

M_user=root

m_pass=11111111

M_host=localhost

M_db=cloud

m_back_dir=/data/mysql/backup/

M_dir_time= ' Date +%y-%m-%d '


#Check User

If [$UID-ne-0];then

Echo-e "\033[32mplease use root."

Exit 0

Fi


#Check Backup Dir

if [!-D $M _back_dir];then

Mkdir-p $M _back_dir

echo "Dir create success."

Fi


#Backup CMD

/usr/bin/mysqldump-h$m_host-u$m_user-p$m_pass $M _db > $M _back_dir/cloud_$m_dir_time.sql


If [$?-eq 0];then

Echo-e "\033[32m$m_db backup success.........\033[0m"

Else

Echo-e "\033[32mplease Check it.\033[0m"

Fi


#Check DIR Time

Echo-e "\033[32m----------------------------\033[1m"

CD $M _back_dir; Find-mtime +30-exec rm-rf {} \;

echo $M _db DIR: $M _back_dir

Echo-e "\033[32m----------------------------\033[0m"


This article is from the "You Insist" blog, please be sure to keep this source http://whlai51.blog.51cto.com/2164371/1739525

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.