獲取命令幫助
exp -help imp -help expdp -help impdp -help rman target / ?
測驗資料準備
CREATE TABLESPACE test01 datafile 'C:\APP\ADMINISTRATOR\ORADATA\TEST\test01.dbf' SIZE 10M autoextend off; CREATE USER hello IDENTIFIED BY world DEFAULT TABLESPACE test01; grant dba to hello; conn hello/world; create table emp01 (id number(3),name varchar2(10)); insert into emp01 values(1,'hello01'); insert into emp01 values(2,'hello02'); insert into emp01 values(3,'hello03');
案例一
1.1、案例說明:在Oracle生產環境中,如何使用exp備份的整個資料庫?
1)查看資料庫字符集:
select * from nls_database_parameters where parameter='NLS_CHARACTERSET'; --或者 select userenv('language') from dual;
本機資料庫的字符集是:ZHS16GBK,若資料庫與環境字符集不一樣的話,請先設定字符集,如:
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
2)使用exp備份的整個資料庫:
exp system/oracle buffer=65536 feedback=10000 full=y file=exp.dmp log=exp.log


案例二
2.1、案例說明:在Oracle生產環境中,如果某員工刪庫跑路,把hello整個用戶全誤刪,請使用imp進行恢復,
1)模擬洗掉hello整個用戶:
drop user hello cascade; DROP TABLESPACE test01 INCLUDING CONTENTS AND DATAFILES;


2)先創建表空間,再創建用戶授權:
CREATE TABLESPACE test01 datafile 'C:\APP\ADMINISTRATOR\ORADATA\TEST\test01.dbf' SIZE 10M autoextend off; CREATE USER hello IDENTIFIED BY world DEFAULT TABLESPACE test01; grant dba to hello;

3)恢復hello整個用戶:
imp system/oracle fromuser=hello touser=hello commit=y buffer=65536 feedback=10000 ignore=y file=exp.dmp log=imp.log


案例三
3.1、案例說明:在Oracle生產環境中,如何使用expdp備份的整個資料庫?
1)先建一個備份的檔案夾:
cd c:\users\administrator mkdir dump

2)創建一個Oralce內部用來識別OS檔案系統路徑目錄并授權:
create directory dump_dir as 'C:\Users\Administrator\dump'; grant read,write on directory dump_dir to system;

3)使用expdp備份的整個資料庫:
expdp system/oracle directory=dump_dir dumpfile=full_expdp.dmp full=y logfile=expdp.log parallel=2


案例四
4.1、案例說明:在Oracle生產環境中,如果某員工刪庫跑路,把整個資料庫誤刪,請使用impdp進行恢復,
1)這里就不刪資料庫了,只模擬洗掉hello整個用戶來搞破壞:
drop user hello cascade; DROP TABLESPACE test01 INCLUDING CONTENTS AND DATAFILES;
2)創建資料庫(此處略去),再創建表空間:
CREATE TABLESPACE test01 datafile 'C:\APP\ADMINISTRATOR\ORADATA\TEST\test01.dbf' SIZE 10M autoextend off;
3)配置directory(案例三2)已授權,此步可以省略):
create directory dump_dir as 'C:\Users\Administrator\dump'; grant read,write on directory dump_dir to system;
4)使用impdp進行恢復:
impdp system/oracle directory=dump_dir dumpfile=full_expdp.dmp full=y logfile=impdb.log

5)編譯無效物件:
@?:@是sqlplus呼叫腳本的標識,?是指Oracle的安裝路徑(ORACLE_HOME),
@?/rdbms/admin/utlrp.sql

6)結果驗證:

案例五
5.1、案例說明:在Oracle中,機房需停電維修UPS,請備份整個Oracle環境,
1)停止監聽:
lsnrctl stop

2)關閉資料庫:
shutdown immediate;

3)創建備份目錄:
cd c:\users\administrator mkdir backup

4)使用WinRar備份整個Oracle環境:
cd C:\Program Files\WinRAR
Rar a C:\Users\Administrator\backup\oraclebak20201016.rar C:\app
案例六
6.1、案例說明:在Oracle中,機房完成UPS維護后,啟動系統,發現Oracle啟動失敗,資料檔案損壞,為了快速恢復業務,你應該怎么處理?
1)洗掉資料庫安裝目錄(僅為測驗,請慎重):
rd /s /q c:\app
2)目錄恢復:
cd C:\Program Files\WinRAR Rar x -o+ C:\Users\Administrator\backup\oraclebak20201016.rar C:\
案例七
7.1、案例說明:在Oracle生產環境中,如何使用rman備份整個資料庫?
1)創建備份目錄:
cd c:\users\administrator
mkdir backup1

2)進入rman:
rman target /

3)使用rman備份整個資料庫:
CONFIGURE CONTROLFILE AUTOBACKUP ON; run{ allocate channel d1 type disk; sql 'alter system archive log current'; backup format 'C:\Users\Administrator\backup1\testfull_%U' database include current controlfile plus archivelog; release channel d1; }

案例八
8.1、案例說明:在Oracle生產環境中,如果某員工刪庫跑路,把Oracle資料目錄誤刪,請使用RMAN進行恢復,
1)模擬把資料檔案洗掉:
關閉資料庫:
shutdown immediate;
洗掉資料檔案:
DEL /S /Q C:\app\Administrator\oradata\test\*.*

2)把資料庫啟動到nomount狀態:
startup nomount;

3)進入rman:
rman target /

4)恢復控制檔案:
restore controlfile from 'C:\Users\Administrator\backup1\TESTFULL_04VCQ4PG_1_1';

5)將資料庫啟動到mount狀態:
alter database mount;

6)恢復資料庫:
restore database; recover database; alter database open resetlogs;
7)結果驗證:

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/175757.html
標籤:Oracle
