码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本(三)

时间:2015-07-03 00:23:47      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:mysql自动备份脚本

  1. 自动备份数据库脚本


#!/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 be use 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


本文出自 “毛毛鸭” 博客,请务必保留此出处http://woshitieren.blog.51cto.com/2466034/1670336

shell脚本(三)

标签:mysql自动备份脚本

原文地址:http://woshitieren.blog.51cto.com/2466034/1670336

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!