前端之家收集整理的这篇文章主要介绍了
SHELL编程(二) 按天备份mysql数据库脚本,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/bash
BACKUPDIR=/opt/bee/shtest/data/` date +%Y-%m-%d `
MysqLDB=nowcoder
MysqLUSR=root
if
[ $UID -ne 0 ];then
echo "This script must use the root user"
sleep 2
exit 0
fi
if
[ ! -d $BACKUPDIR ];then
mkdir -p $BACKUPDIR
else
echo "$BACKUPDIR exists ..."
fi
echo "Please input passwd:"
read -s passwd
MysqLPW=$passwd
echo -e $MysqLPW
/usr/bin/MysqLdump -u$MysqLUSR -p$passwd -d $MysqLDB >$BACKUPDIR/nowcoder.sql
cd $BACKUPDIR; tar -czf ${MysqLDB}_db.tar.gz *.sql
find . -type f -name *.sql |xargs rm -rf
[ $? -eq 0 ] && echo "This `date +%Y-%m-%d` MysqL backup success"
cd $BACKUPDIR ; find . -type d -mtime +30 | xargs rm -rf