分类: Mysql/postgreSQL
2006-08-16 11:30:34
1,首先建立目录,比如:
Mkdir –p
/root/meil
2,拷贝mysql_backup到该目录
3,添加计划任务(
比如在14:12
开始备份)
crontab
-e
12 14 * * * /root/meil/mysql_backup > /var/log/dbbackup.log 2>&1
4,重新启动crond。
/etc/rc.d/init.d/crond restart
5,解压使用如下命令:
zcat 20060816-03:30:00.tar.gz |tar xvf -
其他机器需要配置可以如下操作:
mkdir -p /root/meil ; scp -r 10.56.90.13:/root/meil/my* /root/meil && echo "30 23 * * * /root/meil/mysql_backup > /var/log/dbbackup.log 2>&1" >> /var/spool/cron/root && crontab -l
脚本如下:如果数据库没有密码,需要去掉 -prss123
#/usr/bin/dbbackup
#!
/bin/bash
mkdir -p
/root/meil/backup/
backdir=/root/meil/backup/
touch
/var/log/dbbackup.log
datetime=`date
+"%Y%m%d-%T"`
filesum=`ls ${backdir}
| wc -l`
if [ "${filesum}" -ge 10
];then
cd
${backdir}
rm -rf `ls | head
-1`
fi
echo "tar and gzip the
backed file now ..."
cd
/usr/local/mysql/bin
/usr/local/mysql/bin/mysqldump
mddb -prss123> ${backdir}$datetime.sql
cd
${backdir}
tar -c *.sql | gzip
>./${datetime}.tar.gz
rm -rf
*.sql
echo "all success ! you
can find the backed file in ${backdir} suffixed by
.tar.gz"
exit
0