In Linux, MySQL backs up some data that meet the conditions in the database, and then deletes the data script after backup

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 "start executing backup command! "
#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 "backup finished, start to execute delete command! "
echo "delete from xxxxxx.xxxxx WHERE create_time <= '${DATE1}'" | mysql -h127.0.0.1 -uxxxxx -pxxxxx
Echo "deletion completed, program execution completed! "

Recommended Today

Oracle scheduled tasks

Timing task query To query Oracle scheduled tasks, you can use: –Scheduled tasks for all users SELECT * FROM dba_jobs; –Timing task of the user select * from user_jobs; In the query results, the what field generally stores the name of the stored procedure (or the specific stored procedure content). Broken = n indicates that […]