A simple small script for MySQL backup script

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash

#记录备份的时间
echo "-----" $ (date + "%y-%m-%d%h:%m:%s") "-----" >>/data/backup_mysql/record.log

#定义变量

Myuser=root
mypassword=29749716# @Heiniao
Socket=/data/mysql/mysql.sock
mycmd= "Mysql-u $MYUSER-p$mypassword-s $SOCKET"
mydump= "Mysqldump-u $MYUSER-p$mypassword-s $SOCKET"
Backupdir=/data/backup_mysql

#正式备份

For DB in ' $MYCMD-e ' show databases; "| Sed ' 1,2d ' | Egrep-v "Mysql|performance_schema"
Do
$MYDUMP $db > ${backupdir}/${db}_$ (Date +%f). sql
Done
CD ${backupdir}
Tar czvf ${backupdir}/$ (date +%f). tar.gz./*_$ (date +%f). sql
RM-RF ${backupdir}/*.sql
Find ${backupdir}-mtime +30-name "*.sql.tar.gz"-exec rm-rf {} \;


This article is from the "Campbell blog" blog, please be sure to keep this source http://jinbao.blog.51cto.com/6287622/1758419

A simple small script for MySQL backup script

Related Article

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.