#!/bin/sh # user_db="root" pass_db="passwd" host_db="localhost" name_db="mysqlname" port="3306" ls /bak/mydata/ &> /dev/null if [ $? -ne 2 ];then mkdir -p /bak/mydata &> /dev/null fi /usr/bin/mysqldump --opt -u$user_db -p$passwd_db -h$localhost -P$port $name_db > /bak/mydata/$name_db_`date +%F`.sql # find /bak/mydata -type f -mtime +10 -exec rm -f {} \; &> /dev/null
自动备份MYSQL数据库,自动删除10天前的备份