Home Database Mysql Tutorial Oracle数据文件误删除的不完全恢复

Oracle数据文件误删除的不完全恢复

Jun 07, 2016 pm 02:52 PM
oracle delete application recover I data document environment

应用环境: 我的一个表被人不小心误删除了,这时候,我不可以把整个库都恢复回去,那样太麻烦了。 所以现在我就从新到一个新库,只将这一个数据文件拷贝过来恢复。 那我们Oracle在恢复文件的时候是不可以只恢复一部分数据文件的,因为oracle 要保证数据文件

应用环境: 我的一个表被人不小心误删除了,这时候,我不可以把整个库都恢复回去,那样太麻烦了。

所以现在我就从新到一个新库,只将这一个数据文件拷贝过来恢复。


那我们Oracle在恢复文件的时候是不可以只恢复一部分数据文件的,因为oracle  要保证数据文件块头信息一致,所以如果我们要恢复部分文件的话,就得采取以下这种方法:


可以另起一个库,再把要恢复的数据文件拷贝过来,恢复。(当然不单单是该数据文件,还要包括system表空间,undo表空间)

1)另起一个库很简单,可以搞出参数文件,在参数文件中添加一行*.db_unique_name='rt'和修改控制文件路径。

$ORACLE_SID=rt
sqlplus / as sysdba
>startup nomount pfile='/tmp/pfile.ora'
Copy after login

接着控制文件怎么办呢,

2)当然我们可以将之前备份的数据文件直接恢复到我们配置的参数文件中控制文件的路径。

恢复控制文件:

rman target >  restore controlfile to '/u01/app/oracle/oradata/test/rt_con01.ctl' from '/tmp/FULL_04pe7jue_1_1.bak';
Copy after login


那现在可以mount了。

现在是不可以open的,如果你现在open,他就会把原来的logfile 覆盖,那肯定原来的那个库会出问题。

3)我们这里要做的就是先恢复数据文件:

在rman中用到一个newname,首先确定原来的system,undo,还有要恢复的表空间文件号。

run {
allocate channel di type disk;
set newname for datafile 1 to '/tmp/disk1/system01.dbf';
set newname for datafile 3 to '/tmp/disk1/undotbs01.dbf';
set newname for datafile 9 to '/tmp/disk1/test_01.dbf';
restore datafile 1,3,9;
}
Copy after login

当然你执行上面会报错,因为我们是新创建的控制文件,所以要注册一下:

rman >catalog start with '/tmp/FULL_04pe7jue_1_1.bak'

4) 然后在主库更改redo日志:

select * from v$log;
    GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE#
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------
NEXT_TIME
-------------------
         1 1 75 52428800 512 2 YES INACTIVE 4215102 2014-07-26:22:18:25 4215195
2014-07-26:22:19:55
         2 1 74 52428800 512 2 YES INACTIVE 4211699 2014-07-26:20:55:55 4215102
2014-07-26:22:18:25
         3 1 76 52428800 512 2 NO CURRENT 4215195 2014-07-26:22:19:55 2.8147E+14
Copy after login

当前正在用的是group 3,那我们可以删除group1;

SYS@_connect_identifier>alter database drop logfile group 1; 数据库已更改。
SYS@_connect_identifier>alter database add logfile group 1('/u01/app/oracle/oradata/test/mredo01.log') size 60m reuse; 数据库已更改。
Copy after login

跟着删除group 2 :

SYS@_connect_identifier
>
alter database drop logfile group 2; 
数据库已更改。 
SYS@_connect_identifier
>
alter database add logfile group 2('/u01/app/oracle/oradata/test/mredo02.log') size 60m reuse; 
数据库已更改。
Copy after login

那3就要跟着切换日志,做完全检查点了:

SYS@_connect_identifier>select * from v$log;
 GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# ---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ NEXT_TIME ------------------- 1 1 0 62914560 512 1 YES UNUSED 0 0 2 1 
 0 62914560 512 1 YES UNUSED 0 0 3 1 
 76 52428800 512 2 NO CURRENT 4215195 2014-07-26:22:19:55 2.8147E+14

 SYS@_connect_identifier>alter system switch logfile; 
系统已更改。 
SYS@_connect_identifier>alter system checkpoint; 
系统已更改。 
SYS@_connect_identifier>alter database drop logfile group 3; 
数据库已更改。 
SYS@_connect_identifier>alter database add logfile group 3('/u01/app/oracle/oradata/test/mredo03.log')size 60m reuse;
 数据库已更改。
Copy after login

将备库中不用数据文件更改掉

alter database datafile 2 offline drop;

alter database datafile 4 offline drop;

alter database datafile 5 offline drop;

alter database datafile 6 offline drop;

alter database datafile 8 offline drop;

alter database datafile 10 offline drop;

6)备库更改数据文件路径和归档日志文件路径:

SYS@_connect_identifier>alter database rename file '/u01/app/oracle/oradata/test/system01.dbf' to '/tmp/disk1/system01.dbf' 2 ; 
数据库已更改。 

SYS@_connect_identifier>alter database rename file '/u01/app/oracle/oradata/test/undotbs01.dbf' to '/tmp/disk1/undotbs01.dbf';
 数据库已更改。 
 
 SYS@_connect_identifier>alter database rename file '/u01/app/oracle/oradata/test/test_01' to '/tmp/disk1/test_01.dbf'; 
 数据库已更改。

 SYS@_connect_identifier>set LOGSOURCE '/tmp/disk1/arch';
Copy after login

7)恢复日志文件

SYS@_connect_identifier
>recover database using BACKUP controlfile until cancel; 
ORA-00279: 更改 4203853 (在 07/24/2014 19:57:38 生成) 对于线程 1 是必需的 ORA-00289: 
建议: /tmp/disk1/arch/1_73_831746264.dbf 
ORA-00280: 更改 4203853 (用于线程 1) 在序列 #73 中
Copy after login

检查数据文件路径,日志文件路径:

SYS@_connect_identifier
>select * from v$dbfile; 
FILE# NAME 
---------- ---------------------------------------- 
10 /u01/app/oracle/oradata/test/rman01.dbf 
9 /tmp/disk1/test_01.dbf 
8 /tmp/perstat.ora 
6 /home/oracle/trans.dbf 
5 /u01/app/oracle/oradata/test/example01.d 
bf 
4 /u01/app/oracle/oradata/test/users01.dbf 
3 /tmp/disk1/undotbs01.dbf 
2 /u01/app/oracle/oradata/test/sysaux01.db 
f 
FILE# NAME 
---------- ---------------------------------------- 
1 /tmp/disk1/system01.dbf 
已选择9行。
Copy after login

8)打开数据库,任务结束:

SYS@_connect_identifier
>
alter database open resetlogs; 
数据库已更改。 
SYS@_connect_identifier
>select * from v$log; 
GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# 
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------- ------------ 
NEXT_TIME 
------------------- 
1 1 1 52428800 512 2 NO CURRENT 4203854 2014-07-27:12:39:11 2.8147E+14 
2 1 0 52428800 512 2 YES UNUSED 0 0 
3 1 0 52428800 512 2 YES UNUSED 0 0 
SYS@_connect_identifier
>
Copy after login


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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

See all articles