shell脚本实现mysql数据备份与清理

SCRIPT

curdate=`date +%Y-%m-%d_%H-%M`
 backupdir=”/opt/backup/db”
 databasename=”DBName”
 username=”root”
 password=”–skip-password” # if password isn’t empty use “-pxxxxx”
 #the number of days to keep backups
 keepbackups=`date -d ’30 days ago’ +%Y-%m-%d`
 echo =====================
 echo Start backup MySQL DB
 mysqldump -u${username} ${password} ${databasename} > ${backupdir}/${databasename}_${curdate}.sql
 echo Done.
 echo Deleting old backups
 cd $backupdir
 find . -name “${databasename}_${keepbackups}*” | xargs rm -rf
 echo Done.
 echo =====================

相关推荐