Skip to main content
Template scripts for configuring OEM
Updated over 6 months ago

Druva provides template scripts that you can use to back up databases on the Oracle RMAN Database host. The scripts are listed as follows:

The scripts, oracle_oem_full_backup.txt and oracle_oem_archivelog_backup.txt are used on the OEM console while configuring the backup job from the OEM Job Engine.

oracle_oem_full_backup.txt

This script performs a full backup of the databases on the Oracle RMAN Database host. You may use your own RMAN block, provided that you do not change the ${RMANBACKUP_MOUNTPOINT_FULL} variable. The value of this variable indicates the path on the Oracle RMAN Database host, which is mounted on the Phoenix Backup Store. This path is critical as the backups are performed on the Phoenix Backup Store’s mount point.

001
#Update ORACLE_SID for the database. Example: ORACLE_SID=PROD


002
export ORACLE_SID=<>


003
#Update ORACLE_BASE for your database host server. E.g. ORACLE_BASE=/u01/app/oracle


004
export ORACLE_BASE=<>


005
#Update ORACLE_HOME for the database. Example: ORACLE_HOME=/opt/oracle/product/18c/dbhome_1


006
export ORACLE_HOME=<>


007
#Update PBS IP inside the quotes. Example: BACKUP_STORE_IP="172.xx.xx.xx"


008
export BACKUP_STORE_IP="<>"


009
#Update PBS Backup Mount name inside the quotes. Example: BACKUP_MOUNT="PRODMount"


010
export BACKUP_MOUNT="<>"


011
echo "Pre-Script execution is getting started"


012
if [[ -z "${ORACLE_HOME}" ]];


013
then


014
echo "Environment variable ORACLE_HOME not set... exiting"


015
exit 1


016
fi


017
if [[ -z "${ORACLE_SID}" ]];


018
then


019
echo "Environment variable ORACLE_SID not set... exiting"


020
exit 1


021
fi


022
SID=${ORACLE_SID}


023
echo "Validating backup request"


024
validate_resp=$(curl -X GET http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/1.2/backup 2> /dev/null)


025
if [ $? -ne 0 ];


026
then


027
echo "Request to validate phoenix backup failed... exiting"


028
echo "Response from Phoenix Backup Store: "$validate_resp


029
exit 1


030
fi


031
VALIDATE_ERROR_CODE=$(echo $validate_resp|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)


032
if [ $VALIDATE_ERROR_CODE -ne 0 ];


033
then


034
echo "Response from Phoenix Backup Store: "$validate_resp


035
echo "Request to validate Phoenix backup failed... exiting"


036
exit 1


037
fi


038
# Sample output format


039
# {"error_code":0,"error_msg":"","result":{"is_reached_max_snapshots":false,"mount_name":"m2"}}


040
export IS_REACHED_MAX_SNAPSHOTS=$(echo $validate_resp|awk -F "is_reached_max_snapshots" '{print $2}'|cut -d ',' -f1 |cut -d ':' -f2)


041
if [ $IS_REACHED_MAX_SNAPSHOTS == "false" ];


042
then


043
echo "Validation for phoenix backup succeeded"


044
else


045
echo "Response from Phoenix Backup Store: "$validate_resp


046
echo "Validation for phoenix backup failed... exiting"


047
exit 1


048
fi


049
echo "Notifying Phoenix to start backup - Phoenix Backup Store=$BACKUP_STORE_IP mount name=$BACKUP_MOUNT"


050
export res=$(curl -X POST http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/backup 2> /dev/null)


051
if [ $? -ne 0 ];


052
then


053
echo "Request to start phoenix backup failed... exiting"


054
echo "Response from Phoenix Backup Store: "$res


055
exit 1


056
fi


057
# Sample output format


058
# {"error_code":4295622665,"error_msg":"Backup mount does not exist on Export Service.","result":{"mount_name":"mount4","mount_path":""}}


059
ERROR_CODE=$(echo $res|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)


060
if [ $ERROR_CODE -ne 0 ];


061
then


062
echo "Response from Phoenix Backup Store: "$res


063
echo "Request to start Phoenix backup failed... exiting"


064
exit 1


065
fi


066
export REMOTE_MOUNTPOINT=$BACKUP_STORE_IP:$(echo $res|awk -F "mount_path" '{print $2}'|cut -d '"' -f3)


067
export RMANBACKUP_MOUNTPOINT=$(grep "^$REMOTE_MOUNTPOINT" /etc/fstab| sed 's/\s\+/ /g' |cut -d ' ' -f2)


068
if [ -z "$RMANBACKUP_MOUNTPOINT" ];


069
then


070
echo "Entry for Phoenix Backup Store mount not found in /etc/fstab... exiting"


071
exit 1


072
fi


073
export ACTUAL_MOUNTPOINT=$(mount|grep "^$REMOTE_MOUNTPOINT"|sed 's/\s\+/ /g' |cut -d " " -f3 2> /dev/null)


074
if [ -z "$ACTUAL_MOUNTPOINT" ];


075
then


076
mount $RMANBACKUP_MOUNTPOINT 2> /dev/null


077
if [ $? -ne 0 ];


078
then


079
echo "Unable to mount $RMANBACKUP_MOUNTPOINT... exiting"


080
exit 1


081
fi


082
else


083
export RMANBACKUP_MOUNTPOIN=$ACTUAL_MOUNTPOINT


084
fi


085
export PATH=$ORACLE_HOME/bin:$PATH


086
echo "Creating Dir $RMANBACKUP_MOUNTPOINT/$SID'/full'"


087
if [ ! -e $RMANBACKUP_MOUNTPOINT/$SID'/full' ]


088
then


089
mkdir -p $RMANBACKUP_MOUNTPOINT/$SID'/full'


090
if [ $? -eq 0 ];


091
then


092
echo "Created directory for full backup $RMANBACKUP_MOUNTPOINT/$SID/full"


093
else


094
echo "Oracle user does not have permission for $RMANBACKUP_MOUNTPOINT directory... exiting"


095
exit 1


096
fi


097
elif [ ! -d $RMANBACKUP_MOUNTPOINT/${SID}'/full' ];


098
then


099
echo "$RMANBACKUP_MOUNTPOINT is not a directory... exiting"


100
exit 1


101
fi


102
#Creating Archivelog Directory


103
if [ ! -e $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs' ]


104
then


105
mkdir -p $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs'


106
if [ $? -eq 0 ];


107
then


108
echo "Created directory for archivelogs backup $RMANBACKUP_MOUNTPOINT/$SID/archivelogs"


109
else


110
echo "Oracle user does not have permission for $RMANBACKUP_MOUNTPOINT directory... exiting"


111
exit 1


112
fi


113
elif [ ! -d $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs' ];


114
then


115
echo "$RMANBACKUP_MOUNTPOINT is not a directory... exiting"


116
exit 1


117
fi


118



119
export LOG_FILE_DIR=$RMANBACKUP_MOUNTPOINT/'_workspace/RMAN_Logs'


120
echo "Creating Log File Dir: =$RMANBACKUP_MOUNTPOINT'/_workspace/RMAN_Logs'"


121
if [ ! -e $LOG_FILE_DIR ]


122
then


123
mkdir -p $LOG_FILE_DIR


124
if [ $? -eq 0 ];


125
then


126
echo "Created log directory for oracle backup $LOG_FILE_DIR"


127
else


128
echo "Oracle user does not have permission for $LOG_FILE_DIR directory... exiting"


129
exit 1


130
fi


131
fi


132
RMANBACKUP_MOUNTPOINT_FULL=$RMANBACKUP_MOUNTPOINT/$SID


133
echo -n >$LOG_FILE_DIR'/rman_full_backup.log'


134
touch $RMANBACKUP_MOUNTPOINT/_workspace/


135
if [ $? -ne 0 ];


136
then


137
echo "$RMANBACKUP_MOUNTPOINT directory is not writable.. exiting"


138
exit 1


139
fi


140
#Checking if any .lock file is present and deleting the same if the PID is NOT running.


141
export is_lock_file_present=`find ${RMANBACKUP_MOUNTPOINT} -type f -name ".RMAN_FULL_lock_*"|wc -l `


142
if [[ ${is_lock_file_present} -ne 0 ]]


143
then


144
for _lock_file in `find ${RMANBACKUP_MOUNTPOINT} -type f -name ".RMAN_FULL_lock_*" | xargs `


145
do


146
export _pid=`echo ${_lock_file}|cut -d"_" -f4`


147
export is_pid_proc_running=`ps -ef|grep ${_pid}|grep -v grep | wc -l`


148
if [[ ${is_pid_proc_running} -ne 0 ]]


149
then


150
echo "[INFO] Full backup Lock File: ${_lock_file} is present and PID is active"


151
echo "[ERROR] One Full backup is already in progress with process ${_pid}. Exiting current backup"


152
exit 1


153
else


154
echo "[INFO] Full backup Lock File: ${_lock_file} is present and PID is NOT active"


155
echo "Deleting ${_lock_file}"


156
rm ${_lock_file}


157
if [ -e ${_lock_file} ]


158
then


159
echo "ERROR deleting file ${_lock_file}"


160
fi


161
fi


162
done


163
fi


164
# Creating a .lock file to represnt current active full/diff backup.


165
export file_stamp=`date | sed -e 's/ /_/g'`


166
export PID=`echo $$`


167
export LOCK_FILE=`echo ${RMANBACKUP_MOUNTPOINT}/.RMAN_FULL_lock_${PID}_${file_stamp}`


168
echo -n > ${LOCK_FILE}


169
if [ -e ${LOCK_FILE} ]


170
then


171
echo "[INFO] Lock file created: ${LOCK_FILE}"


172
else


173
echo "Error creating lock file: ${LOCK_FILE}"


174
echo "[ERROR] Backup will now stop"


175
exit 3


176
fi


177
#Calling Start RMAN Backup


178
export res_rmanbackup=$(curl -X POST http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/${SID}/full/rmanbackup 2> /dev/null)


179
if [ $? -ne 0 ];


180
then


181
echo "Request to start phoenix backup failed... exiting"


182
echo "Response from Phoenix Backup Store: "$res_rmanbackup


183
exit 1


184
fi


185
echo "Response RMAN Backup: ${res_rmanbackup}"


186
export SNAPSHOT_NAME=`echo $res_rmanbackup|awk -F "snap_name" '{print $2}'|cut -d '"' -f3`


187
if [ -z "$SNAPSHOT_NAME" ];


188
then


189
echo "Failed to get Snapshot name. Exiting. Please check Export Service Logs in PBS"


190
exit 1


191
fi


192
echo "Snapshot to be created ${SNAPSHOT_NAME}"


193
echo -n >$LOG_FILE_DIR'/rman_full_backup_'${SNAPSHOT_NAME}_${ORACLE_SID}'.log'


194
export RMAN_LOGFILE=$LOG_FILE_DIR'/rman_full_backup_'${SNAPSHOT_NAME}_${ORACLE_SID}'.log'


195
echo "RMAN Logfile: ${RMAN_LOGFILE}"


196



197
echo "Starting with RMAN backup. RMAN Log File: $RMAN_LOGFILE"


198
PARALLELISM=1


199
rman log=$RMAN_LOGFILE 2> /dev/null << EOF


200
connect target /


201
set echo on;


202
configure backup optimization on;


203
configure controlfile autobackup on;


204
configure device type disk parallelism $PARALLELISM BACKUP TYPE TO COPY;


205
configure datafile backup copies for device type disk to 1;


206
configure archivelog backup copies for device type disk to 1;


207
configure channel device type disk format '${RMANBACKUP_MOUNTPOINT_FULL}/full/datafile_%%U.bkp';


208
configure controlfile autobackup format for device type disk to '${RMANBACKUP_MOUNTPOINT_FULL}/full/full_controlfile_%%d_%%F.bkp';


209
run


210
{


211
sql 'alter system archive log current';


212
backup incremental level 1 for recover of copy with tag 'phoenix_oracle_backup' database;


213
recover copy of database with tag 'phoenix_oracle_backup';


214
sql 'alter system archive log current';


215
backup as backupset format '${RMANBACKUP_MOUNTPOINT_FULL}/archivelogs/%%d_%%h_%%e_%%s_%%t.arc' archivelog all not backed up;


216
#Force is to ignore I/O errors


217
delete noprompt obsolete device type disk;


218
delete force NOPROMPT expired copy;


219
delete force NOPROMPT expired backup;


220
crosscheck backup;


221
crosscheck copy;


222
}


223
configure backup optimization clear;


224
configure controlfile autobackup clear;


225
exit


226
EOF


227
export RMAN_EXIT_STATUS=$?


228
if [ $RMAN_EXIT_STATUS -ne 0 ];


229
then


230
echo ""


231
echo "rman failed with status $RMAN_EXIT_STATUS.. exiting"


232
rm ${LOCK_FILE}


233
if [ -e ${LOCK_FILE} ]


234
then


235
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"


236
else


237
dt=`date | sed -e 's/ /_/g'`


238
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "


239
fi


240
exit 1


241
fi


242



243
echo "Triggering backup operation"


244
echo "Notifying Phoenix to upload RMAN Logs"


245
echo "RMAN log location: $LOG_FILE_DIR/rman_full_backup_${SNAPSHOT_NAME}_${ORACLE_SID}.log"


246
echo "Notifying Phoenix to upload RMAN Logs"


247
rman_uploadlog_res=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@$LOG_FILE_DIR/rman_full_backup_${SNAPSHOT_NAME}_${ORACLE_SID}.log" -F mountpoint=$RMANBACKUP_MOUNTPOINT -F platform=linux http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/uploadlog 2> /dev/null)


248
if [ $? -ne 0 ];


249
then


250
echo "Request to send RMAN Logs failed..."


251
echo "Response from Phoenix Backup Store: "$rman_uploadlog_res


252
fi


253
rm ${LOCK_FILE}


254
if [ -e ${LOCK_FILE} ]


255
then


256
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"


257
else


258
dt=`date | sed -e 's/ /_/g'`


259
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "


260
fi


261
echo "Notifying Phoenix to end backup"


262
export final_res=$(curl -X PUT http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/backup 2> /dev/null)


263



264
if [ $? -ne 0 ];


265
then


266
echo "Request to end phoenix backup failed... exiting"


267
echo "Response from Phoenix Backup Store: "$final_res


268
rm ${LOCK_FILE}


269
if [ -e ${LOCK_FILE} ]


270
then


271
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"


272
else


273
dt=`date | sed -e 's/ /_/g'`


274
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "


275
fi


276
exit 5


277
fi


278
export ERROR_CODE=$(echo $final_res|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)


279
if [ $ERROR_CODE -ne 0 ];


280
then


281
echo "Response from Phoenix Backup Store: "$res


282
echo "Request to start Phoenix backup failed... exiting"


283
exit 7


284
fi


285
echo $final_res


286
echo "Exiting with successful status"

oracle_oem_archivelog_backup.txt

001
#Update ORACLE_SID for the database. Example: ORACLE_SID=PROD
002
export ORACLE_SID=<>
003
#Update ORACLE_BASE for your database host server. E.g. ORACLE_BASE=/u01/app/oracle
004
export ORACLE_BASE=<>
005
#Update ORACLE_HOME for the database. Example: ORACLE_HOME=/opt/oracle/product/18c/dbhome_1
006
export ORACLE_HOME=<>
007
#Update PBS IP inside the quotes. Example: BACKUP_STORE_IP="172.xx.xx.xx"
008
export BACKUP_STORE_IP="<>"
009
#Update PBS Backup Mount name inside the quotes. Example: BACKUP_MOUNT="PRODMount"
010
export BACKUP_MOUNT="<>"
011
echo "Pre-Script execution is getting started"
012
if [[ -z "${ORACLE_HOME}" ]];
013
then
014
echo "Environment variable ORACLE_HOME not set... exiting"
015
exit 1
016
fi
017
if [[ -z "${ORACLE_SID}" ]];
018
then
019
echo "Environment variable ORACLE_SID not set... exiting"
020
exit 1
021
fi
022
SID=${ORACLE_SID}
023
echo "Validating backup request"
024
validate_resp=$(curl -X GET http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/1.2/backup 2> /dev/null)
025
if [ $? -ne 0 ];
026
then
027
echo "Request to validate phoenix backup failed... exiting"
028
echo "Response from Phoenix Backup Store: "$validate_resp
029
exit 1
030
fi
031
VALIDATE_ERROR_CODE=$(echo $validate_resp|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)
032
if [ $VALIDATE_ERROR_CODE -ne 0 ];
033
then
034
echo "Response from Phoenix Backup Store: "$validate_resp
035
echo "Request to validate Phoenix backup failed... exiting"
036
exit 1
037
fi
038
# Sample output format
039
# {"error_code":0,"error_msg":"","result":{"is_reached_max_snapshots":false,"mount_name":"m2"}}
040
export IS_REACHED_MAX_SNAPSHOTS=$(echo $validate_resp|awk -F "is_reached_max_snapshots" '{print $2}'|cut -d ',' -f1 |cut -d ':' -f2)
041
if [ $IS_REACHED_MAX_SNAPSHOTS == "false" ];
042
then
043
echo "Validation for phoenix backup succeeded"
044
else
045
echo "Response from Phoenix Backup Store: "$validate_resp
046
echo "Validation for phoenix backup failed... exiting"
047
exit 1
048
fi
049
echo "Notifying Phoenix to start backup - Phoenix Backup Store=$BACKUP_STORE_IP mount name=$BACKUP_MOUNT"
050
export res=$(curl -X POST http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/backup 2> /dev/null)
051
if [ $? -ne 0 ];
052
then
053
echo "Request to start phoenix backup failed... exiting"
054
echo "Response from Phoenix Backup Store: "$res
055
exit 1
056
fi
057
# Sample output format
058
# {"error_code":4295622665,"error_msg":"Backup mount does not exist on Export Service.","result":{"mount_name":"mount4","mount_path":""}}
059
ERROR_CODE=$(echo $res|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)
060
if [ $ERROR_CODE -ne 0 ];
061
then
062
echo "Response from Phoenix Backup Store: "$res
063
echo "Request to start Phoenix backup failed... exiting"
064
exit 1
065
fi
066
export REMOTE_MOUNTPOINT=$BACKUP_STORE_IP:$(echo $res|awk -F "mount_path" '{print $2}'|cut -d '"' -f3)
067
export RMANBACKUP_MOUNTPOINT=$(grep "^$REMOTE_MOUNTPOINT" /etc/fstab| sed 's/\s\+/ /g' |cut -d ' ' -f2)
068
if [ -z "$RMANBACKUP_MOUNTPOINT" ];
069
then
070
echo "Entry for Phoenix Backup Store mount not found in /etc/fstab... exiting"
071
exit 1
072
fi
073
export ACTUAL_MOUNTPOINT=$(mount|grep "^$REMOTE_MOUNTPOINT"|sed 's/\s\+/ /g' |cut -d " " -f3 2> /dev/null)
074
if [ -z "$ACTUAL_MOUNTPOINT" ];
075
then
076
mount $RMANBACKUP_MOUNTPOINT 2> /dev/null
077
if [ $? -ne 0 ];
078
then
079
echo "Unable to mount $RMANBACKUP_MOUNTPOINT... exiting"
080
exit 1
081
fi
082
else
083
export RMANBACKUP_MOUNTPOIN=$ACTUAL_MOUNTPOINT
084
fi
085
export PATH=$ORACLE_HOME/bin:$PATH
086
echo "Creating Dir $RMANBACKUP_MOUNTPOINT/$SID'/full'"
087
if [ ! -e $RMANBACKUP_MOUNTPOINT/$SID'/full' ]
088
then
089
mkdir -p $RMANBACKUP_MOUNTPOINT/$SID'/full'
090
if [ $? -eq 0 ];
091
then
092
echo "Created directory for full backup $RMANBACKUP_MOUNTPOINT/$SID/full"
093
else
094
echo "Oracle user does not have permission for $RMANBACKUP_MOUNTPOINT directory... exiting"
095
exit 1
096
fi
097
elif [ ! -d $RMANBACKUP_MOUNTPOINT/${SID}'/full' ];
098
then
099
echo "$RMANBACKUP_MOUNTPOINT is not a directory... exiting"
100
exit 1
101
fi
102
#Creating Archivelog Directory
103
if [ ! -e $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs' ]
104
then
105
mkdir -p $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs'
106
if [ $? -eq 0 ];
107
then
108
echo "Created directory for archivelogs backup $RMANBACKUP_MOUNTPOINT/$SID/archivelogs"
109
else
110
echo "Oracle user does not have permission for $RMANBACKUP_MOUNTPOINT directory... exiting"
111
exit 1
112
fi
113
elif [ ! -d $RMANBACKUP_MOUNTPOINT/${SID}'/archivelogs' ];
114
then
115
echo "$RMANBACKUP_MOUNTPOINT is not a directory... exiting"
116
exit 1
117
fi
118
export LOG_FILE_DIR=$RMANBACKUP_MOUNTPOINT/'_workspace/RMAN_Logs'
119
echo "Creating Log File Dir: =$RMANBACKUP_MOUNTPOINT'/_workspace/RMAN_Logs'"
120
if [ ! -e $LOG_FILE_DIR ]
121
then
122
mkdir -p $LOG_FILE_DIR
123
if [ $? -eq 0 ];
124
then
125
echo "Created log directory for oracle backup $LOG_FILE_DIR"
126
else
127
echo "Oracle user does not have permission for $LOG_FILE_DIR directory... exiting"
128
exit 1
129
fi
130
fi
131
RMANBACKUP_MOUNTPOINT_FULL=$RMANBACKUP_MOUNTPOINT/$SID
132
echo -n >$LOG_FILE_DIR'/rman_archivelog_backup.log'
133
touch $RMANBACKUP_MOUNTPOINT/_workspace/
134
if [ $? -ne 0 ];
135
then
136
echo "$RMANBACKUP_MOUNTPOINT directory is not writable.. exiting"
137
exit 1
138
fi
139
#Checking if any .lock file is present and deleting the same if the PID is NOT running.
140
export is_lock_file_present=`find ${RMANBACKUP_MOUNTPOINT} -type f -name ".RMAN_FULL_lock_*"|wc -l `
141
if [[ ${is_lock_file_present} -ne 0 ]]
142
then
143
for _lock_file in `find ${RMANBACKUP_MOUNTPOINT} -type f -name ".RMAN_FULL_lock_*" | xargs `
144
do
145
export _pid=`echo ${_lock_file}|cut -d"_" -f4`
146
export is_pid_proc_running=`ps -ef|grep ${_pid}|grep -v grep | wc -l`
147
if [[ ${is_pid_proc_running} -ne 0 ]]
148
then
149
echo "[INFO] Full backup Lock File: ${_lock_file} is present and PID is active"
150
echo "[ERROR] One Full backup is already in progress with process ${_pid}. Exiting current backup"
151
exit 1
152
else
153
echo "[INFO] Full backup Lock File: ${_lock_file} is present and PID is NOT active"
154
echo "Deleting ${_lock_file}"
155
rm ${_lock_file}
156
if [ -e ${_lock_file} ]
157
then
158
echo "ERROR deleting file ${_lock_file}"
159
fi
160
fi
161
done
162
fi
163
# Creating a .lock file to represnt current active full/diff backup.
164
export file_stamp=`date | sed -e 's/ /_/g'`
165
export PID=`echo $$`
166
export LOCK_FILE=`echo ${RMANBACKUP_MOUNTPOINT}/.RMAN_FULL_lock_${PID}_${file_stamp}`
167
echo -n > ${LOCK_FILE}
168
if [ -e ${LOCK_FILE} ]
169
then
170
echo "[INFO] Lock file created: ${LOCK_FILE}"
171
else
172
echo "Error creating lock file: ${LOCK_FILE}"
173
echo "[ERROR] Backup will now stop"
174
exit 3
175
fi
176
#Calling Start RMAN Backup
177
export res_rmanbackup=$(curl -X POST http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/${SID}/full/rmanbackup 2> /dev/null)
178
if [ $? -ne 0 ];
179
then
180
echo "Request to start phoenix backup failed... exiting"
181
echo "Response from Phoenix Backup Store: "$res_rmanbackup
182
exit 1
183
fi
184
echo "Response RMAN Backup: ${res_rmanbackup}"
185
export SNAPSHOT_NAME=`echo $res_rmanbackup|awk -F "snap_name" '{print $2}'|cut -d '"' -f3`
186
if [ -z "$SNAPSHOT_NAME" ];
187
then
188
echo "Failed to get Snapshot name. Exiting. Please check Export Service Logs in PBS"
189
exit 1
190
fi
191
echo "Snapshot to be created ${SNAPSHOT_NAME}"
192
echo -n >$LOG_FILE_DIR'/rman_archivelog_backup_'${SNAPSHOT_NAME}_${ORACLE_SID}'.log'
193
export RMAN_LOGFILE=$LOG_FILE_DIR'/rman_archivelog_backup_'${SNAPSHOT_NAME}_${ORACLE_SID}'.log'
194
echo "RMAN Logfile: ${RMAN_LOGFILE}"
195
echo "Starting with RMAN backup. RMAN Log File: $RMAN_LOGFILE"
196
PARALLELISM=1
197
rman log=$RMAN_LOGFILE 2> /dev/null << EOF
198
connect target /
199
set echo on;
200
configure backup optimization on;
201
configure controlfile autobackup on;
202
configure device type disk parallelism ${PARALLELISM} BACKUP TYPE TO COPY;
203
configure datafile backup copies for device type disk to 1;
204
configure archivelog backup copies for device type disk to 1;
205
configure controlfile autobackup format for device type disk to '${RMANBACKUP_MOUNTPOINT_FULL}/archivelogs/arch_controlfile_%%d_%%F.bkp';
206
run
207
{
208
sql 'alter system archive log current';
209
backup as backupset format '${RMANBACKUP_MOUNTPOINT_FULL}/archivelogs/%%d_%%h_%%e_%%s_%%t.arc' archivelog all not backed up;
210
#Force is to ignore I/O errors
211
delete noprompt obsolete device type disk;
212
delete force NOPROMPT expired copy;
213
delete force NOPROMPT expired backup;
214
crosscheck backup;
215
crosscheck copy;
216
}
217
configure backup optimization clear;
218
configure controlfile autobackup clear;
219
exit
220
EOF
221
export RMAN_EXIT_STATUS=$?
222
if [ $RMAN_EXIT_STATUS -ne 0 ];
223
then
224
echo ""
225
echo "rman failed with status $RMAN_EXIT_STATUS.. exiting"
226
rm ${LOCK_FILE}
227
if [ -e ${LOCK_FILE} ]
228
then
229
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"
230
else
231
dt=`date | sed -e 's/ /_/g'`
232
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "
233
fi
234
exit 1
235
fi
236
echo "Triggering Post-Script operations"
237
echo "Notifying Phoenix to upload RMAN Logs"
238
echo "RMAN log location: $LOG_FILE_DIR/rman_archivelog_backup_${SNAPSHOT_NAME}_${ORACLE_SID}.log"
239
echo "Notifying Phoenix to upload RMAN Logs"
240
rman_uploadlog_res=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@$LOG_FILE_DIR/rman_archivelog_backup_${SNAPSHOT_NAME}_${ORACLE_SID}.log" -F mountpoint=$RMANBACKUP_MOUNTPOINT -F platform=linux http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/uploadlog 2> /dev/null)
241
if [ $? -ne 0 ];
242
then
243
echo "Request to send RMAN Logs failed..."
244
echo "Response from Phoenix Backup Store: "$rman_uploadlog_res
245
fi
246
rm ${LOCK_FILE}
247
if [ -e ${LOCK_FILE} ]
248
then
249
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"
250
else
251
dt=`date | sed -e 's/ /_/g'`
252
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "
253
fi
254
echo "Notifying Phoenix to end backup"
255
export final_res=$(curl -X PUT http://$BACKUP_STORE_IP:9090/druva-phoenix/v1/mounts/$BACKUP_MOUNT/backup 2> /dev/null)
256
if [ $? -ne 0 ];
257
then
258
echo "Request to end phoenix backup failed... exiting"
259
echo "Response from Phoenix Backup Store: "$final_res
260
rm ${LOCK_FILE}
261
if [ -e ${LOCK_FILE} ]
262
then
263
echo "[ERROR] Could NOT delete Lock file: ${LOCK_FILE}"
264
else
265
dt=`date | sed -e 's/ /_/g'`
266
echo "[INFO] Lock file deleted: ${LOCK_FILE} at ${dt} "
267
fi
268
exit 5
269
fi
270
export ERROR_CODE=$(echo $final_res|awk -F "error_code" '{print $2}' | cut -d ':' -f2|cut -d ',' -f1)
271
if [ $ERROR_CODE -ne 0 ];
272
then
273
echo "Response from Phoenix Backup Store: "$res
274
echo "Request to start Phoenix backup failed... exiting"
275
exit 7
276
fi
277
echo $final_res
278
echo "Exiting with successful status"
Did this answer your question?