MySQL Database backup script

Source: Internet
Author: User

Required to back up all the libraries, required to compress the package, the name of the package will take months and days.
source files, or source directories, are required to be deleted after the compressed package has been completed.
Tar with bzip2 compression. The scheduled task is 1:30 execution. After the success of the request to send mail to your QQ mailbox.
The message content. Do you want to include the compressed file name successfully? and size?


#!/bin/bash
#write by Lijun
#Date 2014-08-12
#==================
#备份数据库
Mkdir/backup 2>>/dev/null
Mkdir/mysql-bak 2>>/dev/null
mysqldump-uroot-p123456--all-databases >/backup/all.sql
#==================
#将数据库内容打成tar包, delete source directory and source file, send mail
Name= "MYSQL_BAK.TAR.BZ2"
rm-rf/mysql-bak/*
Tar cjvf/mysql-bak/$name-' date +%f-%t '/backup/* 2>>/dev/null && rm-rf/backup
Size= "' Du-sh/mysql-bak/*|awk ' {print '} '"
If [$?-eq 0]
Then
/ETC/INIT.D/HTTPD Restart 2>>/dev/null
echo "/mysql-bak/$name is OK and the size is $size" |mail-s "MySQL bak" QQ number. com && echo "Send mail OK"
Else
echo "Tar failed ..."
Fi

Crontab-e

* */1 * * * Bash script location

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.