#!/bin/bash
DATE=`date +%Y%m%d%H%M` #every minute
DATABASE=xxxxxx #database name
DB_USERNAME=xxxxxx #database username
DB_PASSWORD=xxxxxx #database password
BACKUP_PATH=/home/csq/backup #backup path
DATE1=`date -d "$(date +%Y%m%d) -2 weeks" +%Y-%m-%d\ %H:%M:%S`
echo "${DATE1}"
echo "开始执行备份命令!"
#mysqldump -u$DB_USERNAME -p$DB_PASSWORD $DATABASE t_task --where=" create_time >='2019-10-01 00:00:00' " > ${BACKUP_PATH}\/${DATABASE}_
mysqldump -u$DB_USERNAME -p$DB_PASSWORD $DATABASE t_task --where=" create_time <='${DATE1}'" > ${BACKUP_PATH}\/xxx_task_$(date +%Y%m%d%H%M).sql
echo "备份完毕,开始执行删除命令!"
echo "delete from xxxxxx.xxxxx WHERE create_time <= '${DATE1}'" | mysql -h127.0.0.1 -uxxxxx -pxxxxx
echo "删除完毕,程序执行完毕!"
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。