单个数据库备份脚本
# vi mysqlback.sh #!/bin/sh Date=`date +%Y-%m-%d` olddate=`date +%Y-%m-%d -d "-7 days"` bd_user='root' db_passwd='123456' db_name='test' mkdir /usr/local/apache/back/$Date mkdir /logs/$Date rm -rf /logs/$olddate rm -rf /usr/local/apache/back/$olddate echo "$db_name back begin at `date +%H:%M:%S`" >> /logs/$Date/back.log mysqldump -u $db_user -p$db_passwd --add-drop-table test | gzip > /usr/local/apache/back/$Date/test_$Date.sql.gz echo "$db_name back end at `date +%H:%M:%S`" >> /logs/$Date/back.log:wq
脚本注释:1、备份数据库test,并压缩成.gz文件,并删除7天前的备份 -p 和$db_passwd中间没有空格
2、记录数据库开始备份的时间和结束备份的时间(几点几分几秒)