Skip to content

Instantly share code, notes, and snippets.

@bvlion
Created March 23, 2017 01:22
Show Gist options
  • Save bvlion/cd5557977e0e5290faf92c815437f58b to your computer and use it in GitHub Desktop.
Save bvlion/cd5557977e0e5290faf92c815437f58b to your computer and use it in GitHub Desktop.
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