Shell Script (iii)

Source: Internet
Author: User
Tags mysql backup

    1. Automatically back up database scripts


#!/bin/bash
#auto Bakcup MySQL
#by 2015-7-2

Bak_dir= "/data/backup/' Date +%y%m%d '"
Mysql_db=discuz
Mysql_user=root
mysql_pw=123456
Mysql_cmd=/usr/bin/mysqldump

If [$UID-ne 0]; Then

echo "must to is use the root for run shell ..."


Exit
Fi

if [!-d "$BAK _dar"]; Then

Mkdir-p $BAK _dir

Echo-e "\033[32mthe $BAK _dir is create successfully\033[0m"

Else
echo "This $BAK _dir is exists ..."

Fi
#mysql Backup commend
$MYSQL _cmd-u$mysql_user-p$mysql_pw $MYSQL _db> $BAK _dir/$MYSQL _db.sql

If [$?-eq 0]; Then


Echo-e "\033[32mthe MySQL $MYSQL _db is backup successfully\033[0m"
Else
Echo-e "\033[32mthe MySQL $MYSQL _db is backup failed,please check\033[0m"

Fi


This article is from the "Fluffy Duck" blog, please be sure to keep this source http://woshitieren.blog.51cto.com/2466034/1670336

Shell Script (iii)

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.