oracle 恢复用户表空间,Oracle以TSPITR方式恢复表空间数据一例
SQL> show user
USER is ""
SQL> conn zlm/zlm@ora10g213
Connected.
SQL> !
--创建一个RMAN备份集
[oracle@bak ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Dec 26 16:44:00 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10G (DBID=4175411955)
RMAN> backup as compressed backupset database format '/u01/orabackup/backupsets/full_ora10g_%U' plus archive log format '/u01/orabackup/backupsets/arc_ora10g_%U' delete all input;
Starting backup at 26-DEC-14
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=138 devtype=DISK
channel ORA_DISK_1: starting compressed archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=30 recid=30 stamp=867343597
channel ORA_DISK_1: starting piece 1 at 26-DEC-14
channel ORA_DISK_1: finished piece 1 at 26-DEC-14
piece handle=/u01/orabackup/backupsets/arc_ora10g_13pr577g_1_1 tag=TAG20141226T164639 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/oracle/flash_recovery_area/ORA10G/archivelog/2014_12_26/o1_mf_1_30_b9t83f1s_.arc recid=30 stamp=867343597
Finished backup at 26-DEC-14
Starting backup at 26-DEC-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/data/oradata/ora10g/system01.dbf
input datafile fno=00003 name=/data/oradata/ora10g/sysaux01.dbf
input datafile fno=00002 name=/data/oradata/ora10g/undotbs01.dbf
input datafile fno=00005 name=/data/oradata/ora10g/example01.dbf
input datafile fno=00006 name=/data/oradata/ora10g/tspitr01.dbf
input datafile fno=00004 name=/data/oradata/ora10g/users01.dbf
channel ORA_DISK_1: starting piece 1 at 26-DEC-14
channel ORA_DISK_1: finished piece 1 at 26-DEC-14
piece handle=/u01/orabackup/backupsets/full_ora10g_14pr577l_1_1 tag=TAG20141226T164644 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:47
Finished backup at 26-DEC-14
Starting backup at 26-DEC-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=31 recid=31 stamp=867343772
channel ORA_DISK_1: starting piece 1 at 26-DEC-14
channel ORA_DISK_1: finished piece 1 at 26-DEC-14
piece handle=/u01/orabackup/backupsets/arc_ora10g_15pr57ct_1_1 tag=TAG20141226T164933 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archive log(s)
archive log filename=/oracle/flash_recovery_area/ORA10G/archivelog/2014_12_26/o1_mf_1_31_b9t88wnv_.arc recid=31 stamp=867343772
Finished backup at 26-DEC-14
Starting Control File and SPFILE Autobackup at 26-DEC-14
piece handle=/u01/orabackup/backupsets/ora10g-c-4175411955-20141226-05.ctl comment=NONE
Finished Control File and SPFILE Autobackup at 26-DEC-14
RMAN> exit
Recovery Manager complete.
--连接到测试用户zlm查看当前日志
[oracle@bak ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Dec 26 16:50:46 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn zlm/zlm@ora10g213
Connected.
SQL> select sequence#,status from v$log;
SEQUENCE# STATUS
---------- ----------------
32 CURRENT
30 INACTIVE
31 ACTIVE
--创建测试表t1,并切换若干次日志
SQL> create table t1 as select * from dba_objects;
Table created.
SQL> alter system switch logfile;
System altered.
SQL> select sequence#,status from v$log;
SEQUENCE# STATUS
---------- ----------------
32 ACTIVE
33 CURRENT
31 ACTIVE
SQL> alter system switch logfile;
System altered.
SQL> select sequence#,status from v$log;
SEQUENCE# STATUS
---------- ----------------
32 ACTIVE
33 ACTIVE
34 CURRENT --此时仍然时候数据的
SQL> select count(*) from t1;
COUNT(*)
----------
50382
--对表进行truancate操作,模拟误操作
SQL> truncate table t1;
Table truncated.
SQL> select count(*) from t1;
COUNT(*)
----------
0
SQL> alter system switch logfile;
System altered.
SQL> select sequence#,status from v$log;
SEQUENCE# STATUS
---------- ----------------
35 CURRENT --truncate之后又切换了一次日志,当前日志为35
33 ACTIVE
34 ACTIVE
SQL> !
创建表的时候,logseq是32,之后切换了一次日志,到33,此时的表中仍然是有数据的,但是truncate操作后表中的数据就没有了,这个动作基本就是在logseq 34的时候发生的,truncate完以后又切了日志,到了35,我们实验的目的就是要把表空间恢复到logseq=34这个时间点(Time In Point)。根据刚才说的那个例子,就是到故障点8点以前的某个数据未丢失的时间点(5点)
--创建一个auxiliary目录(必要步骤)
[oracle@bak ~]$ mkdir /u01/aux
[oracle@bak ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Fri Dec 26 16:54:36 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10G (DBID=4175411955)
auxiliary目标目录中会在之后的RMAN脚本执行过程中,生成一些系统恢复需要的文件,等RMAN恢复完后会展示一下这个目录的结构。
--最关键的来了,用RMAN命令进行TSPITR恢复到故障点之前的某个时刻
RMAN> recover tablespace tspitr until logseq 33 auxiliary destination '/u01/aux';
Starting recover at 26-DEC-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point in time
List of tablespaces expected to have UNDO segments --有undo段的表空间列表
tablespace SYSTEM
tablespace UNDOTBS1
Creating automatic instance, with SID='xvBc' --创建一个自动化实例,随机SID为xvBc
initialization parameters used for automatic instance: --为自动化实例分配的参数
db_name=ORA10G
compatible=10.2.0.1.0
db_block_size=8192
db_files=200
db_unique_name=tspitr_ORA10G_xvBc
large_pool_size=1M
shared_pool_size=110M
#No auxiliary parameter file used
db_create_file_dest=/u01/aux --之前创建的auxiliary目录
control_files=/u01/aux/cntrl_tspitr_ORA10G_xvBc.f --控制文件的位置
starting up automatic instance ORA10G--启动自动化实例
Oracle instance started
Total System Global Area 201326592 bytes
Fixed Size 1218508 bytes
Variable Size 146802740 bytes
Database Buffers 50331648 bytes
Redo Buffers 2973696 bytes
Automatic instance created
contents of Memory Script: --第1个内存脚本内容
{
# set the until clause
set until logseq 33 thread 1; --指定的需要恢复到的logseq
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log for tspitr to a resent until time
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script
executing command: SET until clause
Starting restore at 26-DEC-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=36 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/orabackup/backupsets/ora10g-c-4175411955-20141226-05.ctl
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/orabackup/backupsets/ora10g-c-4175411955-20141226-05.ctl tag=TAG20141226T164935
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output filename=/u01/aux/cntrl_tspitr_ORA10G_xvBc.f
Finished restore at 26-DEC-14
sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
released channel: ORA_DISK_1
released channel: ORA_AUX_DISK_1
contents of Memory Script:--第2个内存脚本内容
{
# generated tablespace point-in-time recovery script
# set the until clause
set until logseq 33 thread 1;
plsql <<
declare
sqlstatement varchar2(512);
offline_not_needed exception;
pragma exception_init(offline_not_needed, -01539);
begin
sqlstatement := 'alter tablespace '|| 'TSPITR' ||' offline for recover';
krmicd.writeMsg(6162, sqlstatement);
krmicd.execSql(sqlstatement);
exception
when offline_not_needed then
null;
end; >>>;
# set an omf destination filename for restore
set newname for clone datafile 1 to new;
# set an omf destination filename for restore
set newname for clone datafile 2 to new;
# set an omf destination tempfile
set newname for clone tempfile 2 to new;
# set a destination filename for restore
set newname for datafile 6 to
"/data/oradata/ora10g/tspitr01.dbf";
# rename all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set plus the auxilliary tablespaces
restore clone datafile 1, 2, 6;
switch clone datafile all;
#online the datafiles restored or flipped
sql clone "alter database datafile 1 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 2 online";
#online the datafiles restored or flipped
sql clone "alter database datafile 6 online";
# make the controlfile point at the restored datafiles, then recover them
recover clone database tablespace "TSPITR", "SYSTEM", "UNDOTBS1" delete archivelog;
alter clone database open resetlogs;
# PLUG HERE the creation of a temporary tablespace if export fails due to lack
# of temporary space.
# For example in Unix these two lines would do that:
#sql clone "create tablespace aux_tspitr_tmp
# datafile ''/tmp/aux_tspitr_tmp.dbf'' size 500K";
}
executing Memory Script
executing command: SET until clause
sql statement: alter tablespace TSPITR offline for recover
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed temporary file 2 to /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 26-DEC-14
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: sid=39 devtype=DISK
channel ORA_AUX_DISK_1: starting datafile backupset restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_system_%u_.dbf
restoring datafile 00002 to /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_undotbs1_%u_.dbf
restoring datafile 00006 to /data/oradata/ora10g/tspitr01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/orabackup/backupsets/full_ora10g_14pr577l_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/orabackup/backupsets/full_ora10g_14pr577l_1_1 tag=TAG20141226T164644
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:26
Finished restore at 26-DEC-14
datafile 1 switched to datafile copy
input datafile copy recid=4 stamp=867344300 filename=/u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_system_b9t8nvw3_.dbf
datafile 2 switched to datafile copy
input datafile copy recid=5 stamp=867344300 filename=/u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_undotbs1_b9t8nvx5_.dbf
sql statement: alter database datafile 1 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 6 online
Starting recover at 26-DEC-14
using channel ORA_AUX_DISK_1
starting media recovery
archive log thread 1 sequence 32 is already on disk as file /oracle/flash_recovery_area/ORA10G/archivelog/2014_12_26/o1_mf_1_32_b9t8dkr8_.arc
channel ORA_AUX_DISK_1: starting archive log restore to default destination
channel ORA_AUX_DISK_1: restoring archive log
archive log thread=1 sequence=31
channel ORA_AUX_DISK_1: reading from backup piece /u01/orabackup/backupsets/arc_ora10g_15pr57ct_1_1
channel ORA_AUX_DISK_1: restored backup piece 1
piece handle=/u01/orabackup/backupsets/arc_ora10g_15pr57ct_1_1 tag=TAG20141226T164933
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
archive log filename=/u01/app/oracle/product/10.2.0/db_1/dbs/arch1_31_860802036.dbf thread=1 sequence=31
channel clone_default: deleting archive log(s)
archive log filename=/u01/app/oracle/product/10.2.0/db_1/dbs/arch1_31_860802036.dbf recid=32 stamp=867344306
archive log filename=/oracle/flash_recovery_area/ORA10G/archivelog/2014_12_26/o1_mf_1_32_b9t8dkr8_.arc thread=1 sequence=32
media recovery complete, elapsed time: 00:00:05
Finished recover at 26-DEC-14
database opened
contents of Memory Script: --第3个内存脚本(逻辑导入导出)
{
# export the tablespaces in the recovery set
host 'exp userid =\"/@\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=beq\)\(PROGRAM=/u01/app/oracle/product/10.2.0/db_1/bin/oracle\)\(ARGV0=oraclexvBc\)\(ARGS=^'\(DESCRIPTION=\(LOCAL=YES\)\(ADDRESS=\(PROTOCOL=beq\)\)\)^'\)\(ENVS=^'ORACLE_SID=xvBc^'\)\)\(CONNECT_DATA=\(SID=xvBc\)\)\) as sysdba\" point_in_time_recover=y tablespaces=
TSPITR file=
tspitr_a.dmp';
# shutdown clone before import
shutdown clone immediate
# import the tablespaces in the recovery set
host 'imp userid =\"/@ as sysdba\" point_in_time_recover=y file=
tspitr_a.dmp';
# online/offline the tablespace imported
sql "alter tablespace TSPITR online";
sql "alter tablespace TSPITR offline";
# enable autobackups in case user does open resetlogs from RMAN after TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
Export: Release 10.2.0.1.0 - Production on Fri Dec 26 16:58:55 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses ZHS16GBK character set (possible charset conversion)
Note: table data (rows) will not be exported
About to export Tablespace Point-in-time Recovery objects... --执行导出TSPITR对象
For tablespace TSPITR ...
. exporting cluster definitions
. exporting table definitions
. . exporting table T
. . exporting table T1--导出误删除的测试表
. exporting referential integrity constraints
. exporting triggers
. end point-in-time recovery
Export terminated successfully without warnings. --导出完成无报错
host command complete
database closed
database dismounted
Oracle instance shut down
Import: Release 10.2.0.1.0 - Production on Fri Dec 26 16:59:17 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Export file created by EXPORT:V10.02.01 via conventional path
About to import Tablespace Point-in-time Recovery objects...
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
. importing SYS's objects into SYS
. importing ZLM's objects into ZLM
. . importing table "T"
. . importing table "T1"--导入误删除的测试表
. importing SYS's objects into SYS
Import terminated successfully without warnings.
host command complete
sql statement: alter tablespace TSPITR online
sql statement: alter tablespace TSPITR offline --最后一步操作是把要恢复的表空间offline的
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
Removing automatic instance --删除自动化实例以及相关文件
Automatic instance removed
auxiliary instance file /u01/aux/cntrl_tspitr_ORA10G_xvBc.f deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_system_b9t8nvw3_.dbf deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_undotbs1_b9t8nvx5_.dbf deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/datafile/o1_mf_temp_b9t8t370_.tmp deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/onlinelog/o1_mf_1_b9t8srrv_.log deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/onlinelog/o1_mf_2_b9t8svp8_.log deleted
auxiliary instance file /u01/aux/TSPITR_ORA10G_XVBC/onlinelog/o1_mf_3_b9t8sy5v_.log deleted
Finished recover at 26-DEC-14
oracle 恢复用户表空间,Oracle以TSPITR方式恢复表空间数据一例相关推荐
- oracle创建表不在对应表空间,oracle创建表空间
创建表空间参数详解 语法描述: CREATE [UNDO] TABLESPACE tablespace_name [DATAFILE datefile_spec1 [,datefile_spec2] ...
- Oracle database TSPITR(TableSpace Point-In-Time Recovery) 表空间基于时间点的恢复
主要用于恢复人为的错误 需要有之前的backup. 适用场景 (1)恢复错误的dml语句 (2)恢复错误的ddl语句,比如说更改了表结构,这个时候无法使用flashback table (3)恢复d ...
- oracle rman恢复表空间,Oracle数据库RMAN恢复之表空间和数据块介质的恢复
示例一:表空间的数据文件被误删除 open状态下删除表空间对应的所有数据文件. 在open状态下使用alter tablespace ... offline for recover 脱机表空间. 使用 ...
- oracle 授权访问条空间,oracle创建用户和角色、管理授权以及表空间操作
show user 显示当前用户 connect username/password@datebasename as sysdba 切换用户和数据库 和用户身份 Oracle登录身份有三种: norm ...
- oracle 给表指定表空间,oracle数据库创建用户指定表空间
--创建临时表空间 create temporary tablespace test_temp --test_temp表空间名称 tempfile 'E:\oracle\product\10.2.0\ ...
- oracle级联删除表空间,Oracle表的创建.表空间创建删除,导入导出等
创建表空间; 先在E盘建立oradate再在里面建一个temp, 再打开命令行cmd在写入sqlplus再写入sys/oracle@orcl as sysdba再写入 create tablespac ...
- oracle建表语句空间,oracle建表空间语句
一.能帮我解释一下oracle创建表空间的语句吗 1. 创建表空间,名称为db_name; 2. 表空间有一个数据文件*.dbf,大小为200MB; 3. 允许表空间自动扩展(autoextends) ...
- oracle数据库迁移 增大空间,Oracle数据库迁移、创建表空间、创建数据表实例讲解-Oracle...
数据库迁移 对于数据库迁移来说,如果源数据库与目标数据库版本一致,推荐使用Oracle导入或者pl/sql导入:如果版本不一致,则可以使用sql导入的方式. 创建表空间 create tablespa ...
- oracle移动表所在的表空间,ORACLE移动表空间(原)
缺省情况下,导入试图在与导出相同的表空间中创建对象.如果用户不具有那个表空间的权限,或者那个表空间不存在时,Oracle在用户帐户的缺省表空间中创建数据库对象.这些特性可以用于使用导出与导入在表空间之 ...
- 如何手动修改oracle表空间,ORACLE数据库创建和修改表空间
-建立表空间(oracle中的tablespace(表空间)) CREATE TABLESPACE data01 DATAFILE 'D:\oracle\ora92\oradata\db\DATA01 ...
最新文章
- 文巾解题 45. 跳跃游戏 II
- 七步精通Python机器学习
- 算法导论——贪心算法:哈夫曼编码(霍夫曼编码)
- 让Tee 7.x版本和FastReport 3.x版本共存
- Go-项目结构和代码组织
- 嵌入式常见笔试题总结(4)
- 为什么需要建设中台?
- c#多通道波形显示_因为每秒要采集50多个波形,需要大量的数据分析和波形分析,有什么好的解决办法吗?...
- 这四行棘手的C代码背后的概念
- Markdown支持的语言
- 企业级应用架构(二)三层架构之数据访问层的封装与抽象
- 计算机组成flash小游戏,flash小游戏动画制作步骤(带源文件)
- 两个EXCEL对比是完全否相同
- Python手机App数据抓取实战:抖音用户的抓取
- 漂亮的JQUERY SLIDESHOW 磨砂玻璃背景
- 医疗后台管理系统项目
- JAVA毕业设计淮安城市开放大学实习实训管理系统计算机源码+lw文档+系统+调试部署+数据库
- 多模态情感分析的研究现状
- css3属性基本骨架
- C++之适配器(Adapter)模式