Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Springバッチの管理DBの指定日以前のデータを削除するシェル(パスワードの管理方法に関しては.my.cnf等を検討)
#!/bin/bash
# SQL情報
PREFIX=
USER=
PASSWORD=
SCHEMA=
# 最終保存日
DATE=`date '+%Y-%m-%d'`
mysql -u${USER} -D${SCHEMA} -p${PASSWORD} <<EOF
begin;
DELETE FROM ${PREFIX}_STEP_EXECUTION_CONTEXT WHERE STEP_EXECUTION_ID
IN (SELECT STEP_EXECUTION_ID FROM ${PREFIX}_STEP_EXECUTION WHERE JOB_EXECUTION_ID
IN (SELECT JOB_EXECUTION_ID FROM ${PREFIX}_JOB_EXECUTION where CREATE_TIME < '${DATE}'));
DELETE FROM ${PREFIX}_STEP_EXECUTION WHERE JOB_EXECUTION_ID
IN (SELECT JOB_EXECUTION_ID FROM ${PREFIX}_JOB_EXECUTION where CREATE_TIME < '${DATE}');
DELETE FROM ${PREFIX}_JOB_EXECUTION_CONTEXT WHERE JOB_EXECUTION_ID
IN (SELECT JOB_EXECUTION_ID FROM ${PREFIX}_JOB_EXECUTION where CREATE_TIME < '${DATE}');
DELETE FROM ${PREFIX}_JOB_EXECUTION_PARAMS WHERE JOB_EXECUTION_ID
IN (SELECT JOB_EXECUTION_ID FROM ${PREFIX}_JOB_EXECUTION where CREATE_TIME < '${DATE}');
DELETE FROM ${PREFIX}_JOB_EXECUTION where CREATE_TIME < '${DATE}';
DELETE FROM ${PREFIX}_JOB_INSTANCE WHERE JOB_INSTANCE_ID
NOT IN (SELECT JOB_INSTANCE_ID FROM ${PREFIX}_JOB_EXECUTION);
commit;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment