linux定时备份并清理表中数据

linux定时备份70天以前的数据

#!/bin/sh
DB_USER="root" 
DB_PASS="123456"
DB_NAME="igames"
DB_TABLE="table"

DATE=`date +%Y_%m_%d`
BIN_DIR="/IGames/server/mysql/bin"
BCK_DIR="/home/whl" 

DELETESQL_EAT='DELETE FROM  TB_BACK_EAT where createTime <SUBDATE(DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00'),INTERVAL 70 DAY)'
DELETESQL_BET='DELETE FROM  TB_BACK_BET where createTime <SUBDATE(DATE_FORMAT(NOW(),'%Y-%m-%d 00:00:00'),INTERVAL 70 DAY)'
if !(test -d $BCK_DIR)  
then  
  mkdir $BCK_DIR  
fi 
${BIN_DIR}/mysqldump --opt -u${DB_USER} -p${DB_PASS} ${DB_NAME} "TB_BACK_EAT" "TB_BACK_BET" > ${BCK_DIR}/${DATE}${DB_TABLE}.sql

${BIN_DIR}/mysql -u${DB_USER} -p${DB_PASS} ${DB_NAME} << EOF 
$DELETESQL_EAT
EOF

${BIN_DIR}/mysql -u${DB_USER} -p${DB_PASS} ${DB_NAME} << EOF 
$DELETESQL_BET
EOF


你可能感兴趣的:(linux定时备份并清理表中数据)