sh脚本备份数据库
#!/bin/bash
BACKUP=/u01/backup/MySQL/
DATETIME=$(date '+%Y-%m-%d')
DB_HOST=127.0.0.1
DB_USER=root
DB_PWD=root
DATABASE1=test
DATABASE2=test_api
mkdir -p "${BACKUP}/$DATETIME"
TIME=$(date '+%H%M%S')
mysqldump -u${DB_USER} -p${DB_PWD} -h${DB_HOST} -q -R --databases $DATABASE1 | gzip > ${BACKUP}/$DATETIME/${TIME}_${DATABASE1}.sql.gz
mysqldump -u${DB_USER} -p${DB_PWD} -h${DB_HOST} -q -R --databases $DATABASE2 | gzip > ${BACKUP}/$DATETIME/${TIME}_${DATABASE2}.sql.gz
crontab定时任务语法可以参考这个网站
https://toolhut.cn/tools/crontab
评论 (0)