扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
首次尝试将oracle数据库备份到AWS 云,以前一般都是备份到磁带库或者磁盘,现在有了云就更方便了。这里主要是使用AWS 的S3存储作为SBT设备进行备份。至于什么是AWS,什么是S3,麻烦大家参考:http://www.amazonaws.cn/products/ 具体操作步骤如下:
创新互联为企业级客户提高一站式互联网+设计服务,主要包括成都做网站、成都网站制作、App定制开发、重庆小程序开发、宣传片制作、LOGO设计等,帮助客户快速提升营销能力和企业形象,创新互联各部门都有经验丰富的经验,可以确保每一个作品的质量和创作周期,同时每年都有很多新员工加入,为我们带来大量新的创意。
先决条件: 你要有一个AWS accunt(AWS access key ID 与 AWS secret key),你还需要有ORACLE的OTN账号与密码
1、安装Centos 6.6 64位操作系统(具体过程略)
2、 安装JAVA 1.8 JDK (具体过程略)
3、 安装 Oracle 11G数据库 (具体过程略)
4、下载OSB模块 ,可以到http://www.oracle.com/technetwork/database/database-technologies/secure-backup/secure-backup-s3-484709.html 查找到
5、 解压缩osbws_installer.zip
[oracle@localhost ~]$ unzip osbws_installer.zip
. [oracle@localhost ~]$ java -jar osbws_install.jar
Oracle Secure Backup Web Service InstallTool, build 2015-06-22
No arguments supplied
Usage: java -jar osbws_install.jar
-AWSID: AWS Access Key ID
-AWSKey: AWS Secret Access Key
-otnUser: OTN Username
-walletDir: Directory to store wallet
-configFile: File name of config file
-libDir: Directory to store library
-libPlatform: Platform of library to download
-location: Location to store backups
-proxyHost: HTTP proxy host
-proxyPort: HTTP proxy port
-proxyID: HTTP proxy userid, if needed
-proxyPass: HTTP proxy password, if needed
-newLogBucket:Force creation of new log bucket
-reRegister: Force user registration
当你看见类似上面的输出,则下载的osbws_install是正确的。
6、编辑一个脚本文件叫:osbws.sh,然后输入如下内容:
java -jar osbws_install.jar -AWSID XXXXXXXXX \
-AWSKey //XXXXXXXXX \
-otnUser XXXX@ABC.COM \
-otnPass xxxx \
-walletDir$ORACLE_HOME/dbs/osbws_wallet \
-libDir $ORACLE_HOME/lib/
解释:-AWSID 是AWS的 access key ID 例如:ABCDK234DDK39JDL
-AWSKey 是该acess key ID 的secrect key
-otnUser 与 -otnPass是你的oracle账号密码
7、输入下面的命令:
[oracle@localhost ~]$ mkdir $ORACLE_HOME/dbs/osbws_wallet
[oracle@localhost ~]$ chmod +x osbws.sh
[root@localhost ~]# ntpdate stdtime.gov.hk #切换root用户进行ntp网络时间同步,不同步会报错
8、则行osbws.sh
[oracle@localhost ~]$ ./osbws.sh
Oracle Secure Backup Web Service Install Tool, build 2015-06-22
AWS credentials are valid.
Re-creating logbucket
Created new log bucket.
Registration ID: 0a43c1d0-2e98-43e2-aca6-e4b532b408b4
S3 Logging Bucket: oracle-log-test-abcx-1
Validating log bucket location ...
Validating license file ...
Oracle Secure Backup Web Service wallet created in directory /usr/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/osbws_wallet.
Oracle Secure Backup Web Service initialization file /usr/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/osbwsorcl.ora created.
Downloading Oracle Secure Backup Web Service Software Library from file osbws_linux64.zip.
Downloaded 27151475 bytes in 2062 seconds. Transfer rate was 13167 bytes/second.
Download complete.
查看$ORACLE_HOME/lib目录
ls $ORACLE_HOME/lib/*osb*
输出如:
/usr/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libosbws11.so /usr/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libosbws.so
则AWS驱动已经安装成功。
现在测试一下表空间备份与还原的操作,我先创建一个表空间以及一个测试用户,并在该用户下创建测试表。然后通过OSB备份到AWS上面.具体过程如下:
A、创建表空间:
SQL> create tablespace up2s3
2 logging
3 datafile '/usr/oracle/app/oracle/oradata/orcl/up2s3_01.dbf' SIZE 5M
4 autoextend on;
Tablespace created.
2、创建用户
SQL> create user tests3 identified by test;
User created.
SQL>grant connect,resource to tests3;
Grant succeeded.
SQL> alter user tests3 default tablespace up2s3 ;
User altered.
SQL> conn tests3/test;
Connected.
SQL> create table test(id varchar(20));
Table created.
SQL> insert into test(id) values('abc');
1 row created.
SQL> select * from test;
ID
--------------------
abc
B、利用RMAN把up2s3表空间备份到云端,在rman输入:
RMAN> run {
2> allocate channel dev1 type
3> sbt parms='SBT_LIBRARY=/usr/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libosbws11.so,
4> SBT_PARMS=(OSB_WS_PFILE=/usr/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/osbwsorcl.ora)';
5> backup tablespace up2s3;
6> }
输出:
allocated channel: dev1
channel dev1: SID=32 device type=SBT_TAPE
channel dev1: Oracle Secure Backup Web Services Library
Starting backup at 21-JUL-15
channel dev1: starting full datafile backup set
channel dev1: specifying datafile(s) in backup set
input datafile file number=00005 name=/usr/oracle/app/oracle/oradata/orcl/up2s3_01.dbf
channel dev1: starting piece 1 at 21-JUL-15
channel dev1: finished piece 1 at 21-JUL-15
piece handle=01qck3eb_1_1 tag=TAG20150721T155035 comment=API Version 2.0,MMS Version 2.0.0.0
channel dev1: backup set complete, elapsed time: 00:00:25
Finished backup at 21-JUL-15
released channel: dev1
现在你可以尝试在rman使用list backupset 看到你刚刚的备份。
C、删除up2s3表空间,模拟表空间损毁。
SQL> alter tablespace up2s3 offline;
Tablespace altered.
[oracle@localhost ~]$ su -
Password:
[root@localhost ~]# mv /usr/oracle/app/oracle/oradata/orcl/up2s3_01.dbf /root/
SQL> alter tablespace up2s3 online;
alter tablespace up2s3 online
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/usr/oracle/app/oracle/oradata/orcl/up2s3_01.dbf'
D、现在通过RMAN去恢复up2s3表空间
RMAN> run {
2> allocate channel dev1 type
3> sbt parms='SBT_LIBRARY=/usr/oracle/app/oracle/product/11.2.0/dbhome_1/lib/libosbws11.so,
4> SBT_PARMS=(OSB_WS_PFILE=/usr/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/osbwsorcl.ora)';
5> restore tablespace up2s3;
6> recover tablespace up2s3;
7> }
SQL> alter tablespace up2s3 online;
Tablespace altered.
SQL> conn tests3/test
Connected.
SQL> select * from test;
ID
--------------------
abc
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流