标签: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!
本文出自 “清香悠远” 博客,请务必保留此出处http://5604671.blog.51cto.com/5594671/1614970
标签:mysql备份脚本
原文地址:http://5604671.blog.51cto.com/5594671/1614970