Oracle自动备份脚本(网上找到的资料)
废话不多说了,直接给大家贴代码了,具体代码如下所示:
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
|
#!/bin/sh #****************************************************************** # File: oraclebak.sh # Creation Date : 2014/1/22 17:57:32 # Last Modified: 2014/1/22 17:57:34 # 脚本功能:oracle备份脚本 # 执行方法:1、第一次执行需要root用户执行,脚本会以询问的方式创建备份目录和相关参数 # 2、脚本会自动写入crontab调度里面定时执行,crontab设置是在第一次执行的时候自动添加的 #****************************************************************** echo $ USER if [ $ USER != root ] then echo "检测到安装用户不是root用户,请用root用户登录再执行安装文件" exit 1 fi echo "开始安装oracle数据库备份工具.........................." echo "请输入备份程序的安装目录:" read installdir mkdir -p $installdir result=$? while [ $result -ne 0 ] do echo "无法创建目录,请重新输入或退出安装。输入y重新输入,输入n退出安装。" read redo if [ $redo != y ] then echo "用户退出安装。" exit 0 fi echo "请输入备份程序的安装目录:" read installdir mkdir $installdir result=$? done echo "安装目录创建完成。" echo "请输入执行备份用户(一般为oracle用户):" read execuser id $execuser result=$? while [ $result -ne 0 ] do echo "不存在该用户,是否更换其它用户或者退出安装新建用户,输入y更换用户,输入n退出安装" read redo if [ $redo != y ] then echo "用户退出安装" exit 0 fi echo "请输入执行备份的用户(一般为tnmsdb2用户)" read execuser id $execuser result=$? done echo "你希望建立备份的数据库数量(一般为1)" read backnum if [ $backnum -eq 0 ] then echo "无备份数据库,退出安装" exit 0 fi scount=0 while [ $scount -lt $backnum ] do echo "请输入第" $(($scount+1)) "个备份登录登录oracle数据库的用户名和密码,以及本地服务名" echo "用户名" read username[$scount] echo "密码" read password [$scount] echo "服务名" read sname[$scount] su -l -c "sqlplus /nolog" $execuser<< insert whenever sqlerror exit sql.sqlcode; connect ${username[$scount]}/${ password [$scount]}@${sname[$scount]} exit insert result=$? if [ $result -ne 0 ] then echo "输入数据库信息无法被连接,是否重新输入?输入y重新输入,输入n退出安装。" read redo if [ $redo != y ] then echo "用户退出安装" exit 0 fi else scount=$(($scount+1)) fi done echo "输入值守时间,值守时间的格式为 mm hh dd MM E 。" echo "m代表分钟,h代表小时,d代表日期,M代表月份,E代表星期" echo "不输入则为任意时间" scount=0 iscontinue=y while [ $iscontinue == y ] do echo "输入第$(($scount+1))个值守时间" echo "分钟" read min echo "小时" read hour echo "日期" read day if [ ! $ day ] then day = "*" fi echo "月份" read mouth if [ ! $mouth ] then mouth= "*" fi week= "*" backtime[$scount]= "$min $hour $day $mouth $week" echo -e "${backtime[$scount]}" echo "是否输入更多值守时间?输入y继续,输入n进入下一步。" read iscontinue scount=$(($scount+1)) done echo "是否要进行远程备份?输入y为进行远程备份,输入n进入下一步" scount=0 read iscontinue while [ $iscontinue == y ] do echo "请选择远程备份类型,输入s为sftp备份类型,否则为ftp备份类型" read iss if [ $iss == s ] then rtype[$scount]= "sftp" else rtype[$scount]= "ftp" fi echo "请输入远程备份地址,可以为域名,计算机名或者ip地址" read rurl[$scount] echo "请输入远程备份登录名" read rname[$scount] echo "请输入远程备份登录密码" read rpass[$scount] echo "是否输入更多远程备份地址?输入y重新输入,n进入下一步" read iscontinue scount=$(($scount+1)) done # installdir # execuser # username password sname # backtime # rtype rurl rname rpass echo "您所作的备份配置如下:" sresult=$(echo -n "$installdir" | grep '^/' ) if [ ! $sresult ] then installdir= "$PWD/$installdir" else installdir=$installdir fi echo "本地备份目录为$installdir" echo "执行备份系统用户为$execuser" echo "系统备份数据库:" allcount=${#username[@]} scount=0 while [ $scount -lt $allcount ] do echo "${username[$scount]}/${password[$scount]}@${sname[$scount]}" scount=$(($scount+1)) done echo "执行备份的值守时间表,*代表任意" scount=0 backnum=${#backtime[@]} while [ $scount -lt $backnum ] do echo "${backtime[$scount]}" scount=$(($scount+1)) done rnum=${#rtype[@]} if [ $rnum -ne 0 ] then echo "远程备份的服务地址为:" scount=0 while [ $scount -lt $rnum ] do echo "连接方式:${rtype[$scount]},连接地址:${rurl[$scount]},用户名:${rname[$scount]},密码:${rpass[$scount]}" scount=$(($scount+1)) done fi echo "是否确认安装?输入y继续,输入n退出安装" read isgoon if [ $isgoon != y ] then exit 0; fi echo "正在生产目录结构................................" ; mkdir -p $installdir/logs mkdir -p $installdir/ temp mkdir -p $installdir/zip chown -Rvf $execuser $installdir echo "目录结构生成完成................................" echo "生成备份执行文件................................" echo "#!/bin/bash" >$installdir/runback.sh echo "source ~/.bash_profile" >>$installdir/runback.sh echo "nowdate=\$(date +%Y-%m-%d_%k.%M.%S)" >>$installdir/runback.sh echo "nowmouth=\$(date +%Y-%m)" >>$installdir/runback.sh echo "echo \"\$nowdate开始备份.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh scount=0 snum=${#username[@]} while [ $scount -lt $snum ] do echo "exp ${username[$scount]}/${password[$scount]}@${sname[$scount]} file=$installdir/temp/${username[$scount]}_${sname[$scount]}\$nowdate.dmp compress=N>>$installdir/logs/\$nowmouth.log 2>&1" >>$installdir/runback.sh scount=$(($scount+1)) done echo "echo \"\$(date +%Y-%m-%d_%k.%M.%S)完成备份.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh echo "echo \"\$(date +%Y-%m-%d_%k.%M.%S)开始打包.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh echo "gzip $installdir/zip/\$nowdate.zip $installdir/temp/>>$installdir/logs/\$nowmouth.log 2>&1" >>$installdir/runback.sh echo "rm -Rvf $installdir/temp/*>>$installdir/logs/\$nowmouth.log 2>&1" >>$installdir/runback.sh echo "echo \"\$(date +%Y-%m-%d_%k.%M.%S)打包完成.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh scount=0 if [ ${#rtype[@]} -ne 0 ] then echo "echo \"\$(date +%Y-%m-%d_%k.%M.%S)进行远程备份.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh snum=${#rtype[@]} while [ $scount -lt $snum ] do echo "lftp -u ${rname[$scount]},${rpass[$scount]} ${rtype[$scount]}://${rurl[$scount]}<<remote" >>$installdir/runback.sh echo "mkdir remotedbback" >>$installdir/runback.sh echo "cd remotedbback" >>$installdir/runback.sh echo "mput $installdir/zip/\$nowdate.zip" >>$installdir/runback.sh echo "exit" >>$installdir/runback.sh echo "remote" >>$installdir/runback.sh scount=$(($scount+1)) done echo "echo \"\$(date +%Y-%m-%d_%k.%M.%S)完成远程备份.......................................\">>$installdir/logs/\$nowmouth.log" >>$installdir/runback.sh fi echo "exit 0" >>$installdir/runback.sh chmod 775 $installdir/runback.sh chown $execuser $installdir/runback.sh echo "生成备份执行文件完成............................" echo "开始定制值守时间................................" scount=0 snum=${#backtime[@]} while [ $scount -lt $snum ] do echo "${backtime[$scount]} $installdir/runback.sh" >>$installdir/planlist scount=$(($scount+1)) done su -l -c "crontab $installdir/planlist" oracle echo "完成值守时间定制................................" exit 0 |
接下来给大家介绍linux oracle自动备份脚本
1、备份脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/bin/sh export ORACLE_BASE=/home/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORACLE_SID=orcl export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin export DATA_DIR=/home/bakup/data export LOGS_DIR=/home/bakup/logs export DELTIME=` date -d "7 days ago" +%Y%m%d` export BAKUPTIME=` date +%Y%m%d%H%M%S` mkdir -p $DATA_DIR mkdir -p $LOGS_DIR echo "Starting bakup..." echo "Bakup file path $DATA_DIR/$BAKUPTIME.dmp" exp shop/lyisABC0987@orcl file=$DATA_DIR/$BAKUPTIME.dmp log=$LOGS_DIR/$BAKUPTIME.log echo "Delete the file bakup before 7 days..." rm -rf $DATA_DIR/$DELTIME*.dmp rm -rf $LOGS_DIR/$DELTIME*.log echo "Delete the file bakup successfully. " echo "Bakup completed." |
2、添加到任务调度
crontab -u oracle -e * 3 * * * /home/bakup/bakup.sh 即每天凌晨3点进行备份 如需每天备份多次,可设置不同时间段备份: 例如:* 3,13,18 * * * /home/bakup/bakup.sh,即每天3点、13点、18点进行备份。 说明:文件备份目录,用户oracle必须有更改权限,否则无法备份。
Oracle自动备份脚本(网上找到的资料)的更多相关文章
- Oracle自动备份脚本的实现
问题描述: Oracle自动备份脚本的实现. 错误提示1: Message file RMAN.msb not found Verify that Oracle_HOME is set properl ...
- Oracle自动备份脚本
set mydate=%date:~0,4%%date:~5,2%%date:~8,2%exp 用户名/密码@实例名 file=D:\mydata_%mydate%.dmp owner=用户名 log ...
- Windows环境下Oracle数据库的自动备份脚本
批处理文件(.bat) @echo off echo ================================================ echo Windows环境下Oracle数据 ...
- oracle expdp自动备份脚本
windows: @echo off echo ================================================ echo Windows环境下Oracle数据库的自动 ...
- Oracle数据库的自动备份脚本
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- Windows环境下Oracle数据库的自动备份脚本自动删除30天前的备份
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- Windows:Oracle 11g 备份脚本
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- Oracle自动备份bat
很多时候我们需要自动备份数据库这边推荐bat+Windows计划任务实现 方案1 创建以下bat 然后添加到TaskSchedule(路径最好不要包含中文) @echo off @echo ===== ...
- oracle自动备份
因为一个项目上马,需要设置自动备份,网上搜索了一下,windows平台下基本上是通过系统的任务计划完成的,于是我也写了一下,无非就是exp xxxx.dmp,文件名是用的日期加时间,精确到秒,一小时备 ...
随机推荐
- struts2 插件使用
1.引用这个jar包 2.http://localhost:8080/strute2demo/config-browser/actionNames.action
- iOS 目录的使用
Table 1-1 Commonly used directories of an iOS app Directory Description AppName.app This is the ap ...
- java压缩
/* @description:压缩文件操作 * @param filePath 要压缩的文件路径 * @param descDir 压缩文件保存的路径 d:\\aaa.zip */ public s ...
- 2.nodejs权威指南--Buffer
1. Buffer 1.1 创建 var buf1 = new Buffer(100); var buf2 = new Buffer([0,1,2]); var buf3 = new Buffer(' ...
- ePass.CreateFile
javascript和vbscript中没有结构体Struct,ePass的ActiveX对象中把各个参数都展开了,官方文档只给出了对应的代码,没有给出相应的数字,示例代码中却都是数字,其VC代码中有 ...
- Java for LeetCode 228 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. For example, give ...
- js中apply方法的使用
js中apply方法的使用 1.对象的继承,一般的做法是复制:Object.extend prototype.js的实现方式是: Object.extend = function(destinat ...
- Oracle 修改现有列的数据类型
如果表中有数据,Oracle是不能修改其数据类型的.但可以通过新建一个临时列,将要修改列的数据复制到临时列中,删除原列再修改临时列的名字.这样说好像有点拗口,分步解说一下. 表AC_REG中有列:is ...
- iOS MRC ARC 内存管理
转自:http://www.jianshu.com/p/48665652e4e4 1. 什么是内存管理 程序在运行的过程中通常通过以下行为,来增加程序的的内存占用 创建一个OC对象 定义一个变量 调用 ...
- 【2016-08-18】转载:总结C++中几种结构体初始化的方法
作者:Ac_Von 博客地址:http://www.cnblogs.com/vongang/ 文章地址:http://www.cnblogs.com/vongang/archive/2011/07/3 ...