#!/bin/bash #This mysql backup script for dsm db by daily #environment: ubuntu 10.4 #2011-6-12 #def the name of db dbname=dsm #def the username and password dbuser=dsm dbpasswd=dsm #def the path of the backup file backuppath=/home/ts4/mysqldumps/ #def the log path logfile=/home/ts4/mysqldumps/log/backupdb.log #def the name of the dumpfile by current time dumpfile=$(date +%y%m%d%H%M) #def the function to back db back_db() { #log current time and db name to logfile echo $(date +%y%m%d%H%M)" Beginning database "${dbname}" backup--------------------">>${logfile} #backup db and log any error mysqldump -u${dbuser} -p${dbpasswd} ${dbname}|gzip>${backuppath}${dbname}${dumpfile}.sql.gz 2>>${logfile} #log the filename echo "backup file names:"${backuppath}${dbname}${dumpfile}".sql.gz">>${logfile} echo -e "--------------------/n">>${logfile} } #del file before 60 days #rm_oldfile() #{ # #fine and del the files which is before 60days # find ./ -type f -mtime +60 -exec rm {} /; #} #goto backup dir cd ${backuppath} #run backup function back_db #run rm file function #rm_oldfile 上面代码注释掉了删除过去备份的功能,因为还没测试过。