mysql定时备份

#!/bin/bash
DATE=`date +%Y%m%d%H%M`                #every minute
DATABASE=test              #database name
DB_USERNAME=root                       #database username
DB_PASSWORD=123456         #database password
BACKUP_PATH=/backup/mysqldata        #backup path

#backup command

/usr/local/mysql/bin/mysqldump -u$DB_USERNAME -p$DB_PASSWORD -h 127.0.0.1 -R --opt $DATABASE | gzip > ${BACKUP_PATH}\/${DATABASE}_${DATE}.sql.gz

#just backup the latest 5 days

find ${BACKUP_PATH} -mtime +5 -name "${DATABASE}_*.sql.gz" -exec rm -f {} \;

定时任务设置 3小时备份一次

00 3 * * * /backup/shell/database_backup_shell.sh

你可能感兴趣的:(mysql定时备份)