一、標記資料
使用scott使用者登入,並設定標記資料
SQL>select table_name from user_tables;
TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE
EMP_BAK
建立了emp表的一個備份表emp_bak。
二、備份資料庫
1 乾淨的關閉資料庫
SQL> shutdownimmediate
Databaseclosed.
Databasedismounted.
Oracle instance shut down.
2 將備份的資料打包
[oracle@study oracle]$ tar -zcvf admin.tar.gz admin/ &
[oracle@study oracle]$ tar -zcvf oradata.tar.gz oradata/ &
[oracle@study db_1]$ tar -zcvf dbs.tar.gz dbs/ &
3 記錄安裝目錄
[oracle@studyoracle]$ pwd
/u01/app/oracle
4 將備份的tar包儲存。
三、恢複
1 安裝資料庫軟體
2 建立同名資料庫
3 資料庫恢複
資料庫恢複之前,啟動資料庫,使用scott使用者登入。
SQL>startup
ORACLEinstance started.
TotalSystem Global Area 285212672 bytes
FixedSize 1267068 bytes
VariableSize 92277380 bytes
DatabaseBuffers 188743680 bytes
RedoBuffers 2924544 bytes
Databasemounted.
Databaseopened.
SQL>
SQL>conn scott/scott
ERROR:
ORA-28000:the account is locked
Warning:You are no longer connected to ORACLE.
Scott使用者無法正常登入,因為剛剛安裝的資料庫並沒有對scott使用者進行解鎖。現在乾淨的關閉資料庫。
SQL>shutdown immediate
Databaseclosed.
Databasedismounted.
ORACLE instance shut down.
資料庫恢複
將備份的打包資料解壓到相關目錄,主要涉及oradata,admin,dbs三個檔案夾。
[oracle@study oracle]$ mv oradata/ oradata_bak/
[oracle@study oracle]$ cp /home/oracle/oradata.tar.gz ./
[oracle@study oracle]$ tar -zxvf oradata.tar.gz &
[oracle@study oracle]$ mv admin/ admin_bak/
[oracle@study oracle]$ cp /home/oracle/admin.tar.gz ./
[oracle@study oracle]$ tar -zxvf admin.tar.gz &
回複後,啟動資料庫。資料庫可以正常啟動,並且scott使用者可以正常登入,且可以正常查看標記資料。
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1267068 bytes
Variable Size 92277380 bytes
Database Buffers 188743680 bytes
Redo Buffers 2924544 bytes
Database mounted.
Database opened.
SQL> conn scott/scott
Connected.
SQL> select table_name from user_tables;
TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE
EMP_BAK
四、總結
冷備份是最簡單的備份方式,但是也是恢複最快的方式。在工作中,冷備份也是會遇到的,這裡簡單的測試一下。