- 论坛徽章:
- 0
|
本帖最后由 justin033 于 2010-06-23 11:35 编辑
这种方法应该很多的,如下我的脚本:
- #!/bin/sh
- #
- # By Justin
- #
- # Archive the carrierDB email_package table in every week.
- #
- #
- #Setting
- RT_name="root"
- RT_pwd=""
- RT_sock="/data02/mysql/mysql.sock"
- ORI_table="email_package"
- ARC_table="email_package$(date +%Y%m%d)"
- # execute SQL
- /usr/local/mysql/bin/mysql -u${RT_name} -p${RT_pwd} -S${RT_sock} << EOF
- use carrierDB_0;
- create table if not exists carrierDB_0.${ARC_table} like carrierDB_0.${ORI_table};
- insert into carrierDB_0.${ARC_table} select * from carrierDB_0.${ORI_table} where task_status_id = 3 and create_time < date_sub(now(), interval 7 day);
- delete from carrierDB_0.${ORI_table} where task_status_id = 3 and create_time < date_sub(now(), interval 7 day);
- quit
- EOF
复制代码 然后在crontab定时就行了。。。用mysql event也行的 |
|