#!/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 "删除完毕,程序执行完毕!"

玄机
35 声望12 粉丝

希望来这里认识更多志同道合的朋友,大家一起交流学习!