rman 操作

2016-12-15 10:36:57来源:oschina作者:wzl_up人点击

1 创建表空间space2


1* create tablespace space2 datafile '/data/vdb/u01/product/oracle/oradata/myyun1/space2.dbf' size 20M
SQL> /
Tablespace created.
SQL> select tablespace_name,status from user_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
TEST READ ONLY
TEST2 READ ONLY
SPACE2 ONLINE
8 rows selected.
# 在表空间里面创建一些数据
SQL> create table tmp_10 tablespace space2 as select 'hello' name from dual;
Table created.
SQL> select * from tmp_10;
NAME
-----
hello

2 记录下当前时间点并在rman中进行备份


SQL> select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2016-12-14 20:26:21 [oracle@myyun1 ~]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Wed Dec 14 09:52:36 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.All rights reserved.
connected to target database: MYYUN1 (DBID=4226016602)
RMAN> backup database;
Starting backup at 14-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/data/vdb/u01/product/oracle/oradata/myyun1/sysaux01.dbf
input datafile file number=00001 name=/data/vdb/u01/product/oracle/oradata/myyun1/system01.dbf
input datafile file number=00003 name=/data/vdb/u01/product/oracle/oradata/myyun1/undotbs01.dbf
input datafile file number=00005 name=/data/vdb/u01/product/oracle/oradata/myyun1/test.dbf
input datafile file number=00006 name=/data/vdb/u01/product/oracle/oradata/myyun1/test2.dbf
input datafile file number=00004 name=/data/vdb/u01/product/oracle/oradata/myyun1/users01.dbf
input datafile file number=00007 name=/data/vdb/u01/product/oracle/oradata/myyun1/space2.dbf
channel ORA_DISK_1: starting piece 1 at 14-DEC-16
channel ORA_DISK_1: finished piece 1 at 14-DEC-16
piece handle=/data/vdb/u01/product/oracle/fast_recovery_area/MYYUN1/backupset/2016_12_14/o1_mf_nnndf_TAG20161214T095248_d519hjmz_.bkp tag=TAG20161214T095248 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 14-DEC-16
channel ORA_DISK_1: finished piece 1 at 14-DEC-16
piece handle=/data/vdb/u01/product/oracle/fast_recovery_area/MYYUN1/backupset/2016_12_14/o1_mf_ncsnf_TAG20161214T095248_d519j18o_.bkp tag=TAG20161214T095248 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-DEC-16
# rman 数据库备份成功

3 删除之前的表删除并重新建一个表


-- 把表 TMP_10 删除,然后重新建一个表 TMP_20
drop table TMP_10 purge;
create table tmp_20 tablespace SPACE2 as select sysdate time_now from dual;
TIME_NOW
2016-12-14 20:29:31
# 在表tmp_20已经创建成功

4 关闭数据库进行冷备份


[oracle@myyun1 oradata]$ cp myyun1 /tmp/myyun.back -r
[oracle@myyun1 oradata]$

5 rman启动到nomount状态下恢复控制文件


RMAN> startup nomount;
Oracle instance started
Total System Global Area 588746752 bytes
Fixed Size 2230592 bytes
Variable Size360711872 bytes
Database Buffers222298112 bytes
Redo Buffers 3506176 bytesRMAN> restore controlfile from '/data/vdb/u01/product/oracle/fast_recovery_area/MYYUN1/backupset/2016_12_14/o1_mf_ncsnf_TAG20161214T202713_d52gol7w_.bkp';
Starting restore at 14-DEC-16
using channel ORA_DISK_1
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/data/vdb/u01/product/oracle/oradata/myyun1/control01.ctl
output file name=/data/vdb/u01/product/oracle/fast_recovery_area/myyun1/control02.ctl
Finished restore at 14-DEC-16
# 控制文件恢复成功

6 rman启动到mount状态下


RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

7 通过恢复脚本恢复之前删除掉的表空间space2


RMAN> run{
2> sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
3> set until time '2016-12-14 09:51:06';
4> restore database;
5> recover database;
6> }
# 在rman中用下面的代码恢复

恢复成功后打开数据库


RMAN> alter database open;
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/14/2016 10:29:50
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
RMAN> alter database open NORESETLOGS;
database opened

检查之前的表空间是否存在


SQL> select tablespace_name,status from user_tablespaces;
TABLESPACE_NAME STATUS
------------------------------ ---------
SYSTEM ONLINE
SYSAUX ONLINE
UNDOTBS1 ONLINE
TEMP ONLINE
USERS ONLINE
TEST READ ONLY
TEST2 READ ONLY
SPACE2 ONLINE
8 rows selected.
# 表空间space2 已经恢复,
1* select tablespace_name,table_name from user_tables where tablespace_name = 'SPACE2'
SQL> /
TABLESPACE_NAME TABLE_NAME
------------------------------ ------------------------------
SPACE2 TMP_10
# 空间里面的表也恢复了
SQL> select * from TMP_10;
NAME
-----
hello
SQL> select * from dba_tables where table_name = 'TMP_20';
no rows selected
# 但是之前删除表空间space2之后在表空间users下面新建的表tmp_20被恢复掉不在了

8 用数据传输工具exp 导出表空间的数据


SQL> alter tablespace space2 read only;
Tablespace altered.
# 先把表空间设置为只读
[oracle@myyun1 ~]$ exp /'/ as sysdba/' file = '/tmp/space2.dump' transport_tablespace=y tablespaces=space2;
Export: Release 11.2.0.3.0 - Production on Wed Dec 14 10:37:19 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.All rights reserved.Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and UTF8 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)
Note: table data (rows) will not be exported
About to export transportable tablespace metadata...
For tablespace SPACE2 ...
. exporting cluster definitions
. exporting table definitions
. . exporting tableTMP_10
. exporting referential integrity constraints
. exporting triggers
. end transportable tablespace metadata export
Export terminated successfully without warnings.
# 导出成功

9 重新在rman中备份整个数据库并关机恢复冷备份

冷备份恢复后再把之前的exp导出的表空间文件用imp 导入就可以了。


注意:上面rman恢复之后启动数据库用NORESETLOGS 而不是用RESETLOGS


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台