rman备份与恢复
1.查看數據庫是否設置歸檔
sys@CXMTDB 16:51:05> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /archivelog Oldest online log sequence 27 Next log sequence to archive 29 Current log sequence 292.rman連接數據庫
[oracle@node02:/home/oracle]$ rman catalog rman/wwwwwwRecovery Manager: Release 19.0.0.0.0 - Production on Thu Sep 30 16:49:31 2021 Version 19.3.0.0.0Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.connected to recovery catalog databaseRMAN> connect target /connected to target database: CXMTDB (DBID=2538411202)3.對整庫備份
RMAN> backup database;4.查看備份集
RMAN> list backupset;List of Backup Sets ===================BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 58 Full 10.20M DISK 00:00:01 26-SEP-21 BP Key: 59 Status: AVAILABLE Compressed: NO Tag: TAG20210926T110827Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/c-2538411202-20210926-00SPFILE Included: Modification time: 26-SEP-21SPFILE db_unique_name: CXMTDBControl File Included: Ckp SCN: 2361194 Ckp time: 26-SEP-21BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 118 Full 10.20M DISK 00:00:00 29-SEP-21 BP Key: 121 Status: AVAILABLE Compressed: NO Tag: TAG20210929T173959Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/c-2538411202-20210929-00SPFILE Included: Modification time: 29-SEP-21SPFILE db_unique_name: CXMTDBControl File Included: Ckp SCN: 3775038 Ckp time: 29-SEP-21BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 130 Full 1.48G DISK 00:00:02 30-SEP-21 BP Key: 133 Status: AVAILABLE Compressed: NO Tag: TAG20210930T165211Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/030acilr_1_1List of Datafiles in backup set 130File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name---- -- ---- ---------- --------- ----------- ------ ----1 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/system01.dbf2 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/rmants.dbf3 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/sysaux01.dbf4 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/undotbs01.dbf5 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/ogg_tbs.dbf7 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/users01.dbfBS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 144 Full 10.20M DISK 00:00:00 30-SEP-21 BP Key: 151 Status: AVAILABLE Compressed: NO Tag: TAG20210930T165219Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/c-2538411202-20210930-00SPFILE Included: Modification time: 30-SEP-21SPFILE db_unique_name: CXMTDBControl File Included: Ckp SCN: 4098008 Ckp time: 30-SEP-21其中,如下信息為整庫備份的信息。
https://www.cndba.cn/hbhe0316/article/4782 130 Full 1.48G DISK 00:00:02 30-SEP-21 BP Key: 133 Status: AVAILABLE Compressed: NO Tag: TAG20210930T165211Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/030acilr_1_1List of Datafiles in backup set 130File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name---- -- ---- ---------- --------- ----------- ------ ----1 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/system01.dbf2 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/rmants.dbf3 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/sysaux01.dbf4 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/undotbs01.dbf5 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/ogg_tbs.dbf7 Full 4097975 30-SEP-21 NO /oradata/CXMTDB/users01.dbfBS Key Type LV Size Device Type Elapsed Time Completion Time全備份和0級增量備份。全備份和0級增量備份幾乎是一樣的。唯一的區別,0級增量備份能作為增量備份的基礎,而全備份不能作為增量備份的基礎。其它方面完全一致
RMAN> backup incremental level=0 database;(增量為0的備份)
RMAN> backup incremental level=1 database;(增量為1的備份)
可以看到Incr 0為0級增量備份
RMAN> list backupset; 162 Incr 0 1.48G DISK 00:00:02 30-SEP-21 BP Key: 165 Status: AVAILABLE Compressed: NO Tag: TAG20210930T165703Piece Name: /u01/app/oracle/product/19.3.0/db/dbs/050aciuv_1_1List of Datafiles in backup set 162File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name---- -- ---- ---------- --------- ----------- ------ ----1 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/system01.dbf2 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/rmants.dbf3 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/sysaux01.dbf4 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/undotbs01.dbf5 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/ogg_tbs.dbf7 0 Incr 4098708 30-SEP-21 NO /oradata/CXMTDB/users01.dbfBS Key Type LV Size Device Type Elapsed Time Completion Time5.備份表空間https://www.cndba.cn/hbhe0316/article/4782
RMAN> report schema; Report of database schema for database with db_unique_name CXMTDBList of Permanent Datafiles =========================== File Size(MB) Tablespace RB segs Datafile Name ---- -------- -------------------- ------- ------------------------ 1 940 SYSTEM YES /oradata/CXMTDB/system01.dbf 2 1024 RMAN_TS NO /oradata/CXMTDB/rmants.dbf 3 870 SYSAUX NO /oradata/CXMTDB/sysaux01.dbf 4 340 UNDOTBS1 YES /oradata/CXMTDB/undotbs01.dbf 5 5120 OGG_TBS NO /oradata/CXMTDB/ogg_tbs.dbf 7 5 USERS NO /oradata/CXMTDB/users01.dbfList of Temporary Files ======================= File Size(MB) Tablespace Maxsize(MB) Tempfile Name ---- -------- -------------------- ----------- -------------------- 1 132 TEMP 32767 /oradata/CXMTDB/temp01.dbfRMAN> backup tablespace OGG_TBS;6.備份控制文件
RMAN> backup current controlfile; RMAN> backup database include current controlfile;7.單命令和批命令
https://www.cndba.cn/hbhe0316/article/4782 https://www.cndba.cn/hbhe0316/article/4782 https://www.cndba.cn/hbhe0316/article/4782 單命令: backup database; 批命令: run { allocate channel c1 device type disk maxpiecesize 1500m; backup database plus archivelog delete all input; release channel c1; }表示一個備份片中包含一個文件,即使沒有達到 1500M,也生成新的備份片,如我的有五個數據文件,還有 SPFILE和 CONTROLFILE 一個備份片,一共生成六個備份片.如果加上plus archivelog delete all input 這個備份選項之后,那 FIELSPERSET 這個參數就會被IGNORE 掉。
8.RMAN一周典型備份方案
1.星期天晚上 -level 0 backup performed(全備份)
2.星期一晚上 -level 2 backup performed
3.星期二晚上 -level 2 backup performed
4.星期三晚上 -level 1 backup performed
5.星期四晚上 -level 2 backup performed
6.星期五晚上 -level 2 backup performed
7.星期六晚上 -level 2 backup performedhttps://www.cndba.cn/hbhe0316/article/4782
如果星期二需要恢復的話,只需要1+2,
如果星期四需要恢復的話,只需要1+4,
如果星期五需要恢復的話,只需要1+4+5,
如果星期六需要恢復的話,只需要1+4+5+6.
————————————rman恢復測試—————————————————-
使用下來命令對control文件自動備份。
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
1.模擬spfile文件丟失
https://www.cndba.cn/hbhe0316/article/4782 [root@db01:/]$ cd /u01/app/oracle/product/19.3.0/db/dbs/ [root@db01:/u01/app/oracle/product/19.3.0/db/dbs]$ mv spfileorcl.ora spfileorcl.ora.bak [oracle@db01 dbs]$ rman target /Recovery Manager: Release 19.0.0.0.0 - Production on Fri Oct 1 11:24:51 2021 Version 19.12.0.0.0Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.connected to target database (not started)RMAN> startup nomount;startup failed: ORA-01078: failure in processing system parameters LRM-00109: could not open parameter file '/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora'starting Oracle instance without parameter file for retrieval of spfile Oracle instance startedTotal System Global Area 1073737792 bytesFixed Size 8904768 bytes Variable Size 318767104 bytes Database Buffers 738197504 bytes Redo Buffers 7868416 bytesRMAN> set dbid 1610869203executing command: SET DBIDRMAN> restore spfile from autobackup;Starting restore at 2021:10:0111:26:08 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=778 device type=DISKchannel ORA_DISK_1: looking for AUTOBACKUP on day: 20211001 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210930 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210929 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210928 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210927 channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210926 channel ORA_DISK_1: AUTOBACKUP found: c-1610869203-20210926-00 channel ORA_DISK_1: restoring spfile from AUTOBACKUP c-1610869203-20210926-00 channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete Finished restore at 2021:10:0111:26:12RMAN> shutdown immediate;Oracle instance shut downRMAN> startupconnected to target database (not started) Oracle instance started database mounted database openedTotal System Global Area 2516581448 bytesFixed Size 9141320 bytes Variable Size 1174405120 bytes Database Buffers 1325400064 bytes Redo Buffers 7634944 bytes2.controlfile丟失
注意:在做了alter database open resetlogs;會把online redelog file清空,數據文件丟失.所以這個時候要做一個全備份。https://www.cndba.cn/hbhe0316/article/4782
3.redo日志丟失
SQL> select member from v$logfile;MEMBER -------------------------------------------------------------------------------- /u01/app/oracle/oradata/ORCL/redo03.log /u01/app/oracle/oradata/ORCL/redo02.log /u01/app/oracle/oradata/ORCL/redo01.logSQL> shutdown immeidate; SP2-0717: illegal SHUTDOWN option SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down.[oracle@db01 ORCL]$ mv redo01.log redo01.log.bak [oracle@db01 ORCL]$ mv redo02.log redo02.log.bak [oracle@db01 ORCL]$ mv redo03.log redo03.log.bakSQL> startup mount; ORACLE instance started.Total System Global Area 2516581448 bytes Fixed Size 9141320 bytes Variable Size 1174405120 bytes Database Buffers 1325400064 bytes Redo Buffers 7634944 bytes Database mounted. SQL> recover database until cancel; Media recovery complete.SQL> alter database open resetlogs;Database altered.4.數據文件丟失
SQL> select file_name,file_id,tablespace_name from dba_data_files;FILE_NAME FILE_ID TABLESPACE_NAME -------------------------------------------------- ------- ------------------------------ /u01/app/oracle/oradata/ORCL/users01.dbf 7 USERS /u01/app/oracle/oradata/ORCL/undotbs01.dbf 4 UNDOTBS1 /u01/app/oracle/oradata/ORCL/system01.dbf 1 SYSTEM /u01/app/oracle/oradata/ORCL/sysaux01.dbf 3 SYSAUX /oradata/ORCL/ogg01.dbf 13 OGG_TBS1. sql "alter database datafile 13 offline"; 2. restore datafile 13 3. recover datafile 13 4. sql "alter database datafile 13 online";SQL> select tablespace_name,status from dba_tablespaces;TABLESPACE_NAME STATUS ------------------------------ --------------------------- SYSTEM ONLINE SYSAUX ONLINE UNDOTBS1 ONLINE TEMP ONLINE USERS ONLINE OGG_TBS ONLINE6 rows selected.5.表空間丟失https://www.cndba.cn/hbhe0316/article/4782https://www.cndba.cn/hbhe0316/article/4782
表空間丟失: 1. sql "alter tablespace OGG_TBS offline";//如果文件不存在,則用 sql "alter tablespace users offline immeidate"; 2. restore tablespace OGG_TBS; 3. recover tablespace OGG_TBS; //與online redolog file 信息一致 4. sql "alter tablespace OGG_TBS online";版權聲明:本文為博主原創文章,未經博主允許不得轉載。
oracle,linux
總結
- 上一篇: 【高数复盘】1.1映射与函数思维导图
- 下一篇: linux rman备份与恢复,RMAN