標籤:Database Backup oracle aws s3
首次嘗試將oracleDatabase Backup到AWS 雲,以前一般都是備份到磁帶庫或者磁碟,現在有了雲就更方便了。這裡主要是使用AWS 的S3儲存作為SBT裝置進行備份。至於什麼是AWS,什麼是S3,麻煩大家參考:http://www.amazonaws.cn/products/ 具體操作步驟如下:
先決條件: 你要有一個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://download.oracle.com/otn/other/osbws_installer.zip 尋找到
5、 解壓縮osbws_installer.zip
[[email protected] ~]$ unziposbws_installer.zip
. [[email protected] ~]$ java -jarosbws_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 [email protected] \
-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、輸入下面的命令:
[[email protected] ~]$ mkdir$ORACLE_HOME/dbs/osbws_wallet
[[email protected] ~]$ chmod +x osbws.sh
[[email protected] ~]# ntpdate stdtime.gov.hk #切換root使用者進行ntp網路時間同步,不同步會報錯
8、則行osbws.sh
[[email protected] ~]$ ./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.
[[email protected] ~]$ su -
Password:
[[email protected] ~]# 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
本文出自 “技術部落格” 部落格,請務必保留此出處http://raytech.blog.51cto.com/7602157/1676757
Oracle RMAN 備份到AWS 雲