日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

rman备份与恢复

發布時間:2023/12/31 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 29

2.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級增量備份和1及增量備份
    全備份和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 Time

    5.備份表空間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.

    1: mkdir -p /u01/app/oracle/rmanbak/scripts/ (放備份腳本目錄) 2: mkdir -p /u01/app/oracle/rmanbak/logs/ (放日志目錄) 3: mkdir -p /u01/app/oracle/rmanbak/bak/ (放備份文件的目錄) 4: crontab -e -u root30 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl030 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl230 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl230 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl130 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl230 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl230 23 * * 0 /u01/app/oracle/rmanbak/scripts/bakl25: service crond restart6: 附件-------------------bakl0腳本------------------#!/bin/shcd /u01/app/oracle/rmanbak/scriptssu - oracle -c "rman target / msglog=/u01/app/oracle/rmanbak/logs/bakl0.log < /u01/app/oracle/rmanbak/scripts/bakl0.bak"-------------------bakl0.bak腳本--------------run {allocate channel c1 device type disk;allocate channel c2 device type disk;allocate channel c3 device type disk;allocate channel c4 device type disk;backup incremental level 0 format '/u01/app/oracle/rmanbak/bak/inc0_%u_%T' tag sunday_inc0 database;release channel c1;release channel c2;release channel c3;release channel c4;}-------------------bakl1腳本------------------#!/bin/shcd /u01/app/oracle/rmanbak/scriptssu - oracle -c "rman target / msglog=/u01/app/oracle/rmanbak/logs/bakl1.log < /u01/app/oracle/rmanbak/scripts/bakl1.bak"-------------------bakl1.bak腳本--------------run {allocate channel c1 device type disk;allocate channel c2 device type disk;allocate channel c3 device type disk;allocate channel c4 device type disk;backup incremental level 1 format '/u01/app/oracle/rmanbak/bak/inc1_%u_%T' tag inc1 database;release channel c1;release channel c2;release channel c3;release channel c4;}-------------------bakl2腳本------------------#!/bin/shcd /u01/app/oracle/rmanbak/scriptssu - oracle -c "rman target / msglog=/u01/app/oracle/rmanbak/logs/bakl2.log < /u01/app/oracle/rmanbak/scripts/bakl2.bak"-------------------bakl2.bak腳本--------------run {allocate channel c1 device type disk;allocate channel c2 device type disk;allocate channel c3 device type disk;allocate channel c4 device type disk;backup incremental level 2 format '/u01/app/oracle/rmanbak/bak/inc2_%u_%T' tag inc2 database;release channel c1;release channel c2;release channel c3;release channel c4;}

    ————————————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 bytes

    2.controlfile丟失
    注意:在做了alter database open resetlogs;會把online redelog file清空,數據文件丟失.所以這個時候要做一個全備份。https://www.cndba.cn/hbhe0316/article/4782

    [oracle@db01 dbs]$ sqlplus / as sysdbaSQL*Plus: Release 19.0.0.0.0 - Production on Fri Oct 1 11:30:11 2021 Version 19.12.0.0.0Copyright (c) 1982, 2021, Oracle. All rights reserved.Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.12.0.0.0SQL> select name from v$controlfile;NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/ORCL/control01.ctl /u01/app/oracle/oradata/ORCL/control02.ctl[root@db01 ORCL]# mv control01.ctl control01.ctl.bak [root@db01 ORCL]# mv control02.ctl control02.ctl.bakRMAN> startup nomount;connected to target database (not started) Oracle instance startedTotal System Global Area 2516581448 bytesFixed Size 9141320 bytes Variable Size 1174405120 bytes Database Buffers 1325400064 bytes Redo Buffers 7634944 bytesRMAN> restore controlfile from autobackup;Starting restore at 2021:10:0111:32:24 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=2429 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 control file from AUTOBACKUP c-1610869203-20210926-00 channel ORA_DISK_1: control file restore from AUTOBACKUP complete output file name=/u01/app/oracle/oradata/ORCL/control01.ctl output file name=/u01/app/oracle/oradata/ORCL/control02.ctl Finished restore at 2021:10:0111:32:27RMAN> alter database mount;released channel: ORA_DISK_1 Statement processedRMAN> recover database;Starting recover at 2021:10:0111:32:46 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=1216 device type=DISKstarting media recoveryarchived log for thread 1 with sequence 19 is already on disk as file /u01/app/oracle/oradata/ORCL/redo01.log archived log for thread 1 with sequence 20 is already on disk as file /u01/app/oracle/oradata/ORCL/redo02.log archived log file name=/u01/app/oracle/oradata/ORCL/redo01.log thread=1 sequence=19 archived log file name=/u01/app/oracle/oradata/ORCL/redo02.log thread=1 sequence=20 media recovery complete, elapsed time: 00:00:02 Finished recover at 2021:10:0111:32:50RMAN> alter database open resetlogs;Statement processed

    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

    總結

    以上是生活随笔為你收集整理的rman备份与恢复的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。