ORACLE_备份恢复_RMAN相关内容

2023年 12月 22日 22.6k 0

1.配置控制文件自动备份

 

从9i开始,可以用rman来配置控制文件的自动备份,默认备份到$ORACLE_HOME/dbs目录下,如果是10g且使用了闪回区(flash_recovery_area),则备份到闪回区。

使用rman配置控制文件自动备份,前提是一定要设置数据库为归档模式,否则不生效,这个我试验过。

 

1.1环境

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE    10.2.0.3.0      Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production

SQL>

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     23
Next log sequence to archive   25
Current log sequence           25

SQL>

SQL> show parameter recovery;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /oracle10/flash_recovery_area
db_recovery_file_dest_size           big integer 1048M
recovery_parallelism                 integer     0
SQL>

 

 

1.2 配置控制文件自动备份

[oracle10@seagull ~]$ rman target /

RMAN> configure controlfile autobackup on;

old RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

RMAN>

RMAN> show controlfile autobackup;

RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN>

 

1.3 测试

 

1.3.1创建1个新的表空间(在数据库结构发生变化时,就会自动备份控制文件)

[oracle10@seagull 2008_01_04]$ sqlplus "/ as sysdba"

SQL> create tablespace tbs_test datafile '/oracle10/oradata/ora10g/tbs_test_01.dbf' size 10M;

Tablespace created.

SQL>

 

1.3.2观察alert_ora10g日志文件,发现发生了控制文件的自动备份

Tue Jan  8 20:52:15 2008
create tablespace tbs_test datafile '/oracle10/oradata/ora10g/tbs_test_01.dbf' size 10M
Tue Jan  8 20:52:19 2008
Starting control autobackup
Control autobackup written to DISK device
        handle '/oracle10/flash_recovery_area/ORA10G/autobackup/2008_01_08/o1_mf_s_643495940_3r6wj9j1_.bkp'
Completed: create tablespace tbs_test datafile '/oracle10/oradata/ora10g/tbs_test_01.dbf' size 10M

 

PS:其实控制文件和spfile同时被自动备份了
 

1.3.3观察闪回区的文件

cd[oracle10@seagull ~]$ cd /oracle10/flash_recovery_area/ORA10G/autobackup/2008_01_08/
[oracle10@seagull 2008_01_08]$ ls -l
total 6988
-rw-r-----  1 oracle10 oinstall 7143424 Jan  8 20:52 o1_mf_s_643495940_3r6wj9j1_.bkp

 

1.4恢复控制文件和spfile

 

1.4.1恢复控制文件到一个临时目录下

RMAN> restore controlfile to '/tmp/control01.ctl' from autobackup;

Starting restore at 08-JAN-08
using channel ORA_DISK_1
using channel ORA_DISK_2

recovery area destination: /oracle10/flash_recovery_area
database name (or database unique name) used for search: ORA10G
channel ORA_DISK_1: autobackup found in the recovery area
recovery area destination: /oracle10/flash_recovery_area
database name (or database unique name) used for search: ORA10G
channel ORA_DISK_2: autobackup found in the recovery area
channel ORA_DISK_2: skipped, autobackup already found
channel ORA_DISK_1: autobackup found: /oracle10/flash_recovery_area/ORA10G/autobackup/2008_01_08/o1_mf_s_643498273_3r6ys3r1_.bkp
channel ORA_DISK_1: control file restore from autobackup complete
Finished restore at 08-JAN-08

RMAN>

 

PS:如果数据库没有mount,则此操作会报错,可以采用set dbid命令或者恢复时指定自动备份集(restore controlfile to 'xx' from 'xxxx')。

 

1.4.2恢复spfile到一个临时目录下

RMAN> restore spfile to '/tmp/spfile.ora' from autobackup;

Starting restore at 08-JAN-08
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=142 devtype=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: sid=139 devtype=DISK

recovery area destination: /oracle10/flash_recovery_area
database name (or database unique name) used for search: ORA10G
channel ORA_DISK_1: autobackup found in the recovery area
recovery area destination: /oracle10/flash_recovery_area
database name (or database unique name) used for search: ORA10G
channel ORA_DISK_2: autobackup found in the recovery area
channel ORA_DISK_2: skipped, autobackup already found
channel ORA_DISK_1: autobackup found: /oracle10/flash_recovery_area/ORA10G/autobackup/2008_01_08/o1_mf_s_643498273_3r6ys3r1_.bkp
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 08-JAN-08

RMAN>

 

ps:如果实例无法nomount,则此操作会报错,此时可以先手工编辑1个pfile启动实例,然后用上面的命令来恢复spfile;

 

2.归档和rman、闪回区的关系

 

2.1手工归档

SQL> alter system archive log current;

System altered.

2.2查看视图,发现归档日志已经到了闪回区

SQL> select name||'  '||space_used||'  '||number_of_files from v$recovery_file_dest;

NAME||''||SPACE_USED||''||NUMBER_OF_FILES
--------------------------------------------------------------------------------
/oracle10/flash_recovery_area  5400064  1

SQL>

 

2.3进入闪回区查看文件

[oracle10@seagull 2008_01_08]$ cd /oracle10/flash_recovery_area/ORA10G/archivelog/2008_01_08
[oracle10@seagull 2008_01_08]$ ls -l
total 5288
-rw-r-----  1 oracle10 oinstall 5400576 Jan  8 21:07 o1_mf_1_26_3r6xcp0s_.arc
[oracle10@seagull 2008_01_08]$

 

2.4利用rman查看归档,发现该归档日志也被rman管理了

RMAN> list copy;

List of Archived Log Copies
Key     Thrd Seq     S Low Time  Name
------- ---- ------- - --------- ----
4       1    26      A 04-JAN-08 /oracle10/flash_recovery_area/ORA10G/archivelog/2008_01_08/o1_mf_1_26_3r6xcp0s_.arc

 

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论