mysql自动备份

第一个mysql自动备份脚本。


#!/bin/bash

#auto backup mysql database for test

#by hag



backCMD=/usr/bin/mysqldump

dbuser=root

dbpasswd=admin123

databasename=test

backup_dir=/opt/backup/mysql


if [ ! -d $backup_dir ]; then

    mkdir -p $backup_dir

fi


if [ $UID -ne 0 ]; then

  echo "must be root can  run the script!"

fi


$backCMD -u$dbuser -p$dbpasswd $databasename > $backup_dir/nimeide.sql


if [ $? -eq 0 ]; then

 echo " this backup mysql successfully!"

  else

  echo " this backup mysql failed!"

fi

~     

写好脚本后,赋予执行权限

[root@localhost script]# chmod 755 backmysql.sh

sh +x 调式脚本  sh +n 检测脚本是否有错误!

[root@localhost script]# sh +x backmysql.sh 

 this backup mysql successfully!


你可能感兴趣的:(mysql,备份,脚本)