-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrman_backup.sh
154 lines (127 loc) · 6.93 KB
/
rman_backup.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
#!/bin/bash
# The crontab setting on oracle user of linux server is as follows:
# 30 22 * * * ~/rman_backup/rman_backup.sh >>/dev/null 2>&1
# +------------------------------------------------------------------------+
# | |
# | Quanwen Zhao |
# | |
# | [email protected] |
# | |
# | quanwenzhao.wordpress.com |
# | |
# |------------------------------------------------------------------------|
# | |
# | Copyright (c) 2016 Quanwen Zhao. All rights reserved. |
# | |
# |------------------------------------------------------------------------|
# | |
# | File Name : ~/rman_backup/rman_backup.sh |
# | |
# | Author : Quanwen Zhao |
# | |
# | Description : This bash script file used to backup one week via rman |
# | |
# | utility on Oracle Database Server. |
# | |
# | Call Syntax : . ~/rman_backup/rman_backup.sh |
# | |
# | or |
# | |
# | sh ~/rman_backup/rman_backup.sh |
# | |
# | Last Modified: 11/10/2016 (dd/mm/yyyy) |
# | |
# | Last Updated : 30/03/2021 (dd/mm/yyyy) |
# | |
# +------------------------------------------------------------------------+
# +------------------------------------------------------------------------+
# | |
# | Export environment variable of oracle user |
# | |
# +------------------------------------------------------------------------+
source ~/.bash_profile;
# +------------------------------------------------------------------------+
# | |
# | Define some shell variables |
# | |
# +------------------------------------------------------------------------+
export BACK_PATH=~/rman_backup
export BACK_LOG=~/rman_backup/log
export DATE=`which date`
export RMAN_BIN=$ORACLE_HOME/bin
export FIND=`which find`
export DATE_W=`$DATE +%u`
# +------------------------------------------------------------------------+
# | |
# | Create a directory of current date |
# | |
# +------------------------------------------------------------------------+
if [ ! -d "$BACK_PATH/`$DATE +%m-%d`" ]; then
mkdir -p $BACK_PATH/`$DATE +%m-%d`
fi
# +------------------------------------------------------------------------+
# | |
# | One week rman backup of incremental level 0 on Friday 22:30, and |
# | |
# | incremental level 1 on Satruday ~ Thursday 22:30 |
# | |
# +------------------------------------------------------------------------+
case $DATE_W in
5)
$RMAN_BIN/rman nocatalog log $BACK_LOG/level0_`$DATE +%Y-%m-%d`.log <<EOF
connect target /
run {
allocate channel d1 type disk maxpiecesize 16g;
allocate channel d2 type disk maxpiecesize 16g;
allocate channel d3 type disk maxpiecesize 16g;
allocate channel d4 type disk maxpiecesize 16g;
backup incremental level 0 database format '$BACK_PATH/`$DATE +%m-%d`/DATA_level0_%d_%s_%p_%u.bak' include current controlfile
plus archivelog format '$BACK_PATH/`$DATE +%m-%d`/archivelog_%d_%s_%p_%u.bak' delete all input;
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
crosscheck backup;
crosscheck archivelog all;
exit;
EOF
# +------------------------------------------------------------------------+
# | |
# | Maintenace rman backup of last week on Friday |
# | |
# +------------------------------------------------------------------------+
$RMAN_BIN/rman nocatalog log $BACK_LOG/maintenance_`$DATE +%Y-%m-%d`.log <<EOF
connect target /
report obsolete;
delete noprompt expired backup;
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
exit;
EOF
# +------------------------------------------------------------------------+
# | |
# | Remove empty directories after obsolete backup deleted on Friday |
# | |
# +------------------------------------------------------------------------+
$FIND $BACK_PATH -type d -empty -exec rmdir {} \;
# adding the content about removing $BACK_LOG whose creating time is older than 6 days.
$FIND $BACK_LOG -name "*.log" -mtime +6 -exec rm -rf {} \;
;;
1|2|3|4|6|7)
$RMAN_BIN/rman nocatalog log $BACK_LOG/level1_`$DATE +%Y-%m-%d`.log <<EOF
connect target /
run {
allocate channel d1 type disk maxpiecesize 8g;
allocate channel d2 type disk maxpiecesize 8g;
backup incremental level 1 database format '$BACK_PATH/`$DATE +%m-%d`/level1_%d_%s_%p_%u.bak' include current controlfile
plus archivelog format '$BACK_PATH/`DATE +%m-%d`/archivelog_%d_%s_%p_%u.bak' delete all input;
release channel d2;
release channel d1;
}
crosscheck backup;
crosscheck archivelog all;
exit;
EOF
;;
esac