Created
March 23, 2017 01:22
-
-
Save bvlion/cd5557977e0e5290faf92c815437f58b to your computer and use it in GitHub Desktop.
Springバッチの管理DBの指定日以前のデータを削除するシェル(パスワードの管理方法に関しては.my.cnf等を検討)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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