mysql备份脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql备份脚本相关的知识,希望对你有一定的参考价值。
touch mysql_backup.sh
chmod +x mysql_backup.sh
vim mysql_backup.sh
#!/bin/bash
id="root"
pwd="123456"
dbs="test rockoa"
backuppath="/root/mysqlbackup" 备份路径自行设置
day=15
[ ! -d $backpath ] &&mkdir -p $backuppath
cd $backuppath
backupname=mysql_$(date +%Y-%m-%d)
for db in $dbs;
do
mysqldump -u$id -p$pwd -S /var/lib/mysql/mysql.sock $db >$backupname_$db.sql
if [ "$?" == "0" ]
then
echo $(date +%Y-%m-%d)" $db mysqldump sucess">>mysql.log
else
echo $(date +%Y-%m-%d)" $db mysql dump failed">>mysql.log
exit 0
fi
done
tar -czf $backupname.tar.gz *.sql
if [ "$?" == "0" ]
then
echo $(date +%Y-%m-%d)" tar sucess">>mysql.log
else
echo $(date +%Y-%m-%d)" tar failed">>mysql.log
exit 0
fi
rm -f *.sql
delname=mysql_$(date -d "$day day ago" +%Y-%m-%d).tar.gz
rm -f $delname
sh mysql_backup.sh
ll /root/mysqlbackup/
total 56
-rw-r--r-- 1 root root 52346 Sep 24 16:44 mysql_2016-09-24.tar.gz
-rw-r--r-- 1 root root 184 Sep 24 16:44 mysql.log
cd /root/mysqlbackup/
tar zxvf mysql_2016-09-24.tar.gz
rockoa.sql
test.sql
vim /etc/crontab
5 9-6 * * 1-7 root /root/mysql_backup.sh
/etc/rc.d/init.d/crond restart
本文出自 “mailfile” 博客,谢绝转载!
以上是关于mysql备份脚本的主要内容,如果未能解决你的问题,请参考以下文章