1、切換服務器歸檔模式,如果已經是歸檔模式可跳過此步:
%sqlplus /nolog (啟動sqlplus)
SQL> conn / as sysdba (以DBA身份連接數據庫)
SQL> shutdown immediate; (立即關閉數據庫)
SQL> startup mount (啟動實例並加載數據庫,但不打開)
SQL> alter database archivelog; (更改數據庫為歸檔模式)
SQL> alter database open; (打開數據庫)
SQL> alter system archive log start; (啟用自動歸檔)
SQL> exit (退出)
2、連接rman
rman ?or? /data/app/oracle/product/11.2.0/dbhome_1/bin/rman
RMAN> connect ?target sys/system@orcl –連接到目標數據庫
3、備份表空間 tpm
RMAN>backup tablespace tpm plus archivelog delete input;
4、恢復表空間
SQL>alter tablespace tpm ?offline for recover;? //使tpm offline
RMAN>restore tablespace ?tpm
RMAN>recover tablespace? tpm
RMAN>alter tablespace tpm online; ? //tpm online
5、表空間的增量備份
第一天的增量基本備份:
RMAN> backup incremental level=0 tablespace tpm plus archivelog delete input;
第二天的增量差異備份:
RMAN> backup incremental level=2 tablespace tpm plus archivelog delete input;
第三天的增量差異備份:
RMAN> backup incremental level=2 tablespace tpm plus archivelog delete input;
第四天的增量差異備份:
RMAN> backup incremental level=1 tablespace tpm plus archivelog delete input;
第五天的增量差異備份:
RMAN> backup incremental level=2 tablespace tpm plus archivelog delete input;
第六天的增量差異備份:
RMAN> backup incremental level=2 tablespace tpm plus archivelog delete input;
第七天的增量差異備份:
RMAN> backup incremental level=0 tablespace tpm plus archivelog delete input;
注:需要用linux crontab 來每天自動運行上面的代碼
附:創建rman 目錄表空間和用戶
1、 ? create tablespace rman_ts datafile ‘/data/app/oracle/oradata/rman/rman_ts.dbf’ size20M;
2、 ? create user rman identified by rman default tablespace rman_ts temporary tablespace temp quota unlimited on rman_ts;
3、 ? grant recovery_catalog_owner to rman;
4、 ? grant connect, resource to rman
