#!/bin/sh
DB_USER='root'
DB_PASS='root'
DB_NAME='dbname'
DB_BKPATH='/home/mysqldump-path'
DATE=`date +%Y%m%d%H%M`
HOUR_AGO=`date +%Y%m%d%H -d "-1 hour"`
cd ${DB_BKPATH}
/usr/binls/mysqldump --opt -u${DB_USER} -p${DB_PASS} ${DB_NAME} > ${DB_BKPATH}/${DB_NAME}_${DATE}.sql
#docker exec -it [CONTAINER ID] mysqldump -u${DB_USER} -p${DB_PASS} ${DB_NAME} > ${DB_BKPATH}/${DB_NAME}_${DATE}.sql
rm -rf ${DB_BKPATH}/${DB_NAME}_${HOUR_AGO}*
如果提示权限问题:-bash: ./mysql_backup.sh: 权限不够
chmod 777 ./mysql_backup.sh
或
chmod +x ./mysql_backup.sh