-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteLegacyData.sh
More file actions
42 lines (37 loc) · 1.49 KB
/
deleteLegacyData.sh
File metadata and controls
42 lines (37 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# 2020-06-04
# local test
HOST=localhost
USER=postgres
DB=postgres
export PGPASSWORD=
DATE_STR=`date -d '-3 month' "+%Y%m%d"`
NOW=`date`
YEAR=${DATE_STR:0:4}
MONTH=${DATE_STR:4:2}
DATE=${DATE_STR:6:2}
query="delete from where blabla_date < '${YEAR}-${MONTH}-${DATE} 00:00:00'"
psql -h $HOST -U $USER -d $DB -c "select 1" -o /dev/null
query_response=`echo $?`
if [ ${query_response} != "0" ]; then
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 1" >> csvBatch_error.log
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 1"
sleep 5s
psql -h $HOST -U $USER -d $DB -c "select 1" -o /dev/null
query_response=`echo $?`
if [ ${query_response} != "0" ]; then
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 2" >> csvBatch_error.log
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 2"
sleep 5s
psql -h $HOST -U $USER -d $DB -c "select 1" -o /dev/null
query_response=`echo $?`
if [ ${query_response} != "0" ]; then
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 3; EXIT" >> csvBatch_error.log
echo "[ERROR]$NOW cannot connect $USER@$HOST:5432/$DB; EXIT_CODE:$query_response; try: 3; EXIT"
query_test="F"
#exit $query_response
fi
fi
fi
psql -h $HOST -U $USER -d $DB -c "$query" -o /dev/null
echo "[DELETE]$NOW "$YEAR"-"$MONTH"-"$DATE" 이전의 레거시 데이터 삭제 blabla" >> csvBatch.log