分类: DB2/Informix
2011-12-16 16:31:27
#!/bin/bash
#脚本功能:备份mysql数据库;全备与单备#bakmysql_path=”/mysqlbak”today=`date +%F`mysqlcomm=`which mysql`Lecho=`which echo`Lmysqldump=`which mysqldump`mysqlpwd=”PASSWORD”Lfind=`which find`
#整体备份
$Lmysqldump –skip-opt –all-databases -p$mysqlpwd > $bakmysql_path/$today-all-databases.sql
#单个备份
#dbnames:查询数据库名称
dbnames=`$mysqlcomm -uroot -e “show databases” -p$mysqlpwd`
#dblist:过滤一下非数据库字符
dblist=`$Lecho $dbnames|sed ‘s/Database//’`
for database in $dblist
do
$Lmysqldump –skip-opt -uroot -p$mysqlpwd $database > /$bakmysql_path/$today-$database.sql
done
#删除7天以前的备份文件,防止过多的备份文件塞满硬盘$Lfind $bakmysql_path -type f -mtime +7 -exec rm -f {} \;