首页 > 代码库 > mysql自动备份脚本

mysql自动备份脚本

#!/bin/bash

bak_dir=/tmp/`date +%Y%m%d`

mysqldb=test

mysqlusr=root

mysqlpw=123456

mysqlcmd=/usr/bin/mysqldump


if [ $UID -ne 0 ];then

        echo "you must be use root";

        exit

fi


if [ ! -d $bak_dir ];then

        mkdir -p $bak_dir

        echo "$bak_dir is create ok";

else

        echo "this $bak_dir is already exists";

fi


$mysqlcmd -u$mysqlusr -p$mysqlpw $mysqldb > $bak_dir/$mysqldb.sql


if [ $? -eq 0 ];then

echo "the database $mysqldb is backup ok"

else

echo "the database $mysqldb is backup error"

fi


自动备份

crontab e

01 00 * * * /bin/bash /tmp/mysql_back.sh


mysql自动备份脚本