Home Database Mysql Tutorial Oracle RMAN模拟数据文件丢失简单恢复方法

Oracle RMAN模拟数据文件丢失简单恢复方法

Jun 07, 2016 pm 05:12 PM

1 Oracle创建简单项目环境1)创建表空间SQLgt; create tablespace dreamtry_tbs datafile

1 Oracle创建简单项目环境
1)创建表空间
SQL> create tablespace dreamtry_tbs datafile 'd:\oracledate\dreamtry_tbs01.dbf' size 100M;
表空间已创建。
2)创建用户
SQL> create user dreamtry identified by dreamtry;
用户已创建。
3)给用户分配表空间
SQL> alter user dreamtry default tablespace dreamtry_tbs quota unlimited on dreamtry_tbs;
用户已更改。
4)取消用户对表空间都拥有写权限(这点非必须,建议执行)
SQL> alter user dreamtry default tablespace dreamtry_tbs quota unlimited on dreamtry_tbs;
用户已更改。
5)给用户分配基本权限 (可以加上with admin option)
SQL> grant connect,resource to dreamtry;
授权成功。
6)切换用户
SQL> conn dreamtry/dreamtry;
已连接。
2 模拟数据文件丢失的恢复(前提是以前有过备份,并且有日志)
1)       备份数据文件
RMAN> backup datafile 'd:\oracledate\dreamtry_tbs01.dbf' format 'D:\oracle\product\10.2.0\oradata\orcl\dreamtry_tbs01.dbf';
启动 backup 于 01-3月 -12
使用目标数据库控制文件替代恢复目录
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=145 devtype=DISK
通道 ORA_DISK_1: 启动全部数据文件备份集
通道 ORA_DISK_1: 正在指定备份集中的数据文件
输入数据文件 fno=00007 name=D:\ORACLEDATE\DREAMTRY_TBS01.DBF
通道 ORA_DISK_1: 正在启动段 1 于 01-3月 -12
通道 ORA_DISK_1: 已完成段 1 于 01-3月 -12
段句柄=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF 标记=TAG20120301T223142 注释=NONE
通道 ORA_DISK_1: 备份集已完成, 经过时间:00:00:03
完成 backup 于 01-3月 -12
2)       切换用户dreamtry模拟数据操作
SQL> conn dreamtry/dreamtry;
已连接。
SQL> create table test(id number(10), name varchar2(20));
表已创建。
SQL> insert into test(id,name) values(1,'zhangsan');
已创建 1 行。
SQL> select * from test;
ID NAME
---------- --------------------
1 zhangsan
3)       模拟数据文件dreamtry_tbs01.dfb丢失
手工删除OS文件dreamtry_tbs01.dbf(移到别处也可,以防万一)
SQL> startup
ORACLE 例程已经启动。
Total System Global Area  612368384 bytes
Fixed Size                  1250428 bytes
Variable Size             251661188 bytes
Database Buffers          352321536 bytes
Redo Buffers                7135232 bytes
数据库装载完毕。
ORA-01157: 无法标识/锁定数据文件 7 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 7: 'D:\ORACLEDATE\DREAMTRY_TBS01.DBF'
SQL> select status from v$instance;
STATUS
------------
MOUNTED
如上数据库只能启动mount状态.
4)       使用备份的数据文件恢复(当然在有日志的情况下没有备份也是可以恢复的)
RMAN> restore datafile 7;
启动 restore 于 01-3月 -12
使用通道 ORA_DISK_1
通道 ORA_DISK_1: 正在开始恢复数据文件备份集
通道 ORA_DISK_1: 正在指定从备份集恢复的数据文件
正将数据文件00007恢复到D:\ORACLEDATE\DREAMTRY_TBS01.DBF
通道 ORA_DISK_1: 正在读取备份段 D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF
通道 ORA_DISK_1: 已恢复备份段 1
段句柄 = D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF 标记 = TAG20120301T223142
通道 ORA_DISK_1: 恢复完成, 用时: 00:00:04
完成 restore 于 01-3月 -12
5)       通过日志恢复备份以后操作数据库的内容
RMAN> recover datafile 7;
启动 recover 于 01-3月 -12
使用通道 ORA_DISK_1
正在开始介质的恢复
介质恢复完成, 用时: 00:00:03
完成 recover 于 01-3月 -12
6)       打开数据库
RMAN> alter database open;
数据库已打开
7)       验证数据
SQL> select * from dreamtry.test;
ID NAME
---------- --------------------
1 zhangsan
8)       由于是模拟,我还是把备份删掉以免占用空间
RMAN> list backup;
备份集列表
===================
BS 关键字  类型 LV 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
3       Full    88.00K     DISK        00:00:02     01-3月 -12
BP 关键字: 3   状态: AVAILABLE  已压缩: NO  标记: TAG20120301T223142
段名:D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF
备份集 3 中的数据文件列表
文件 LV 类型 Ckp SCN    Ckp 时间   名称
---- -- ---- ---------- ---------- ----
7       Full 1068184    01-3月 -12 D:\ORACLEDATE\DREAMTRY_TBS01.DBF
RMAN> delete backupset 3;
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=145 devtype=DISK
备份段列表
BP 关键字  BS 关键字  Pc# Cp# 状态      设备类型段名称
------- ------- --- --- ----------- ----------- ----------
3       3       1   1   AVAILABLE   DISK        D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF
是否确定要删除以上对象 (输入 YES 或 NO)? YES
已删除备份段
备份段 handle=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DREAMTRY_TBS01.DBF recid=3 stamp=776817102
1 对象已删除
RMAN> crosscheck backup;
使用通道 ORA_DISK_1
RMAN> delete expired backup;
使用通道 ORA_DISK_1
9)       结论:日志是最后一道防线,所以最好先备份,最好也对archive log也备份,还是以防万一.

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement? How do you drop a table in MySQL using the DROP TABLE statement? Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns? How do you create indexes on JSON columns? Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do you represent relationships using foreign keys? How do you represent relationships using foreign keys? Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)? Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles