-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path1000_source_processing.sh
252 lines (249 loc) · 10.6 KB
/
1000_source_processing.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
#
####################################################################################################
# S T A G I N G O V E R L A Y - Source Database Tasks #
# 1000_source_processing.sh
####################################################################################################
#
# Import properties file
#
. clone_environment.properties
#################################################
# Default Configuration #
#################################################
trgbasepath="${basepath}targets/"
logfilepath="${basepath}logs/"
functionbasepath="${basepath}function_lib/"
custfunctionbasepath="${basepath}custom_lib/"
custsqlbasepath="${custfunctionbasepath}sql/"
sqlbasepath="${functionbasepath}sql/"
rmanbasepath="${functionbasepath}rman/"
abendfile="$trgbasepath""$trgdbname"/"$trgdbname"_1000_abend_step
logfilename="$trgdbname"_DB_Overlay_$(date +%a)"_$(date +%F).log"
####################################################################################################
# add functions library #
####################################################################################################
. ${functionbasepath}/usage.sh
. ${functionbasepath}/syncpoint.sh
. ${functionbasepath}/send_notification.sh
. ${functionbasepath}/check_database_status1.sh
. ${functionbasepath}/check_database_status2.sh
. ${functionbasepath}/start_rman_prod_backup.sh
. ${functionbasepath}/delete_sourcedb_backups.sh
#
########################################
# VALIDATIONS #
########################################
#
if [ $# -lt 2 ]
then
echo " ====> Abort!!!. Invalid database arguments for overlay"
usage $0 :1000_overlay_staging "[DATABASE NAME]"
########################################################################
# send notification and exit #
########################################################################
send_notification "$trgappname"_Overlay_abend "Invalid database name for replication" ${TOADDR} ${RTNADDR} ${CCADDR}
exit 3
fi
echo "SCRIPT IS IN UNDER CONSTRUCTION !!!"
exit 99
#
# Check user
#
os_user_check ${dbosuser}
rcode=$?
if [ "$rcode" -gt 0 ]
then
error_notification_exit $rcode "Wrong os user, user should be ${dbosuser}!!" $trgdbname 0 $LINENO
fi
#
# Validate Directory
#
os_verify_or_make_directory ${logfilepath}
os_verify_or_make_directory ${trgbasepath}
os_verify_or_make_directory ${trgbasepath}${trgdbname}
os_verify_or_make_file ${abendfile} 0
#######################################################################################
restart=false
while read val1 val2
do
stepnum=$val1
linenum=$val2
if [[ "$stepnum" != "0" ]]
then
restart=true
echo ""
echo " RESTART LOCATION: "$stepnum" ,around line: "$linenum""
echo " SCRIPT LOCATION: /u01/app/oracle/scripts/refresh/1000_overlay_staging1.sh"
echo "TASK LOG LOCATION: /u01/app/oracle/scripts/refresh/logs/"
echo " RUN LOG LOCATION: /u01/app/oracle/scripts/refresh/logs/"
echo ""
else
echo ""
echo " NORMAL LOCATION: "$stepnum" ,line: "$linenum""
echo " SCRIPT LOCATION: /u01/app/oracle/scripts/refresh/1000_overlay_staging1.sh"
echo "TASK LOG LOCATION: /u01/app/oracle/scripts/refresh/logs/"
echo " RUN LOG LOCATION: /u01/app/oracle/scripts/refresh/logs/"
echo ""
stepnum=`expr $stepnum + 50`
fi
done < "$abendfile"
#
now=$(date "+%m/%d/%y %H:%M:%S")
echo $now >>$logfilepath$logfilename
#
now=$(date "+%m/%d/%y %H:%M:%S")" ====> ######## $srcdbname to $trgdbname overlay has been started - PART1 ########"
echo $now >>$logfilepath$logfilename
#
for step in $(seq "$stepnum" 50 250)
do
case $step in
"50")
echo "START TASK: $step send_notification"
#####################################################################################
# send notification that DB overlay started #
#####################################################################################
# send_notification "$srcdbname"_backup_started "$srcdbname backup started" 2
#
########################################
# write an audit record in the log #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Send start $srcdbname database backup Notification"
echo $now >>$logfilepath$logfilename
#
echo "END TASK: $step send_notification"
;;
"100")
echo "START TASK: $step check_database_status1"
########################################
# check source database status #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Check $srcdbname status on node1"
echo $now >>$logfilepath$logfilename
#
check_database_status1 $srcdbname
rcode=$?
if [ "$rcode" -gt 0 ]
then
rcode=$?
echo "Check database status failed"
now=$(date "+%m/%d/%y %H:%M:%S")" ====>Check $srcdbname status FAILD!!! RC=$rcode"
echo $now >>$logfilepath$logfilename
syncpoint $trgdbname $step "$LINENO"
########################################################################
# send notification #
########################################################################
# send_notification "$trgdbname"_Overlay_abend "Check $srcdbname database status failed" 3
echo "error.......Exit."
echo ""
exit $rcode
fi
#
echo "END TASK: $step check_database_status1"
;;
"150")
echo "START TASK: $step delete_sourcedb_backups"
########################################
# delete old source database backups #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Delete $srcdbname old backups"
echo $now >>$logfilepath$logfilename
#
delete_sourcedb_backups $srcdbname
#
rcode=$?
if [ "$rcode" -gt 0 ]
then
rcode=$?
echo "delete backups failed"
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Delete $srcdbname old backups FAILD!!! RC=$rcode"
echo $now >>$logfilepath$logfilename
syncpoint $trgdbname $step "$LINENO"
########################################################################
# send notification #
########################################################################
# send_notification "$trgdbname"_Overlay_abend "Delete $srcdbname RMAN old backup failed" 3
echo "error.......Exit."
echo ""
exit $rcode
fi
echo "END TASK: $step delete_sourcedb_backups"
;;
"200")
echo "START TASK: $step start_rman_prod_backups"
########################################
# delete old bckup completed #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Delete $srcdbname old backups completed"
echo $now >>$logfilepath$logfilename
#
########################################
# Start Source database backups #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Start $srcdbname new backups"
echo $now >>$logfilepath$logfilename
#
start_rman_prod_backup $srcdbname
rcode=$?
if [ $? -ne 0 ] # if RMAN connection fails
then
########################################
# update log file #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> "$srcdbname" backup FAILED. Abort!! RC=$rcode"
echo $now >>$logfilepath$logfilename
syncpoint $trgdbname $step "$LINENO"
########################################################################
# send notification #
########################################################################
# send_notification "$trgdbname"_Overlay_abend "Source database $srcdbname RMAN backup failed" 3
echo "error in : start_rman_prod_backups"
echo ""
exit 99
fi
echo "END TASK: $step start_rman_prod_backups"
;;
"250")
echo "START TASK: $step check_database_status2"
########################################
# Source database backups completed #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> $srcdbname new backups completed"
echo $now >>$logfilepath$logfilename
#
########################################
# check source database after backups #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> Check $srcdbname status after new backups"
echo $now >>$logfilepath$logfilename
#
check_database_status2 $srcdbname
rcode=$?
if [ $? -ne 0 ]
then
########################################
# update log file #
########################################
now=$(date "+%m/%d/%y %H:%M:%S")" ====> $srcdbname Status FAILED. Abort!! RC=$rcode"
echo $now >>$logfilepath$logfilename
syncpoint $trgdbname $step "$LINENO"
########################################################################
# send notification #
########################################################################
# send_notification "$trgdbname"_Overlay_abend "Source database $srcdbname status failed" 3
echo "error in : check_database_status2"
echo ""
exit 99
fi
echo "END TASK: $step check_database_status2"
;;
"300")
echo "START TASK: $step end-of $srcdbname database backup"
syncpoint $srcdbname "0 " "$LINENO"
echo "END TASK: $step end-of $srcdbname database backup"
;;
*)
echo "step not found - step: $step around Line ===> " "$LINENO"
;;
esac
done