普通库迁移至ASM存储

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:普通库迁移至ASM存储

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

--查看当前库文件位置
SQL> select name from v$datafile
  2  union
  3  select member from v$logfile
  4  union
  5  select name from v$controlfile
  6  union
  7  select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
/u01/oradata/tos/control01.ctl
/u01/oradata/tos/control02.ctl
/u01/oradata/tos/control03.ctl
/u01/oradata/tos/example01.dbf
/u01/oradata/tos/redo01.log
/u01/oradata/tos/redo02.log
/u01/oradata/tos/redo03.log
/u01/oradata/tos/sysaux01.dbf
/u01/oradata/tos/system01.dbf
/u01/oradata/tos/temp01.dbf
/u01/oradata/tos/undotbs01.dbf
/u01/oradata/tos/users01.dbf
/u01/oradata/tos/xff01.dbf
/u01/oradata/tos/xff02.dbf
14 rows selected.
--备份控制文件
SQL> alter database backup controlfile to '/u01/control.ctl';
Database altered.
--修改spfile中的控制文件至asm
SQL>  alter system set control_files='+DATA' scope=spfile;
System altered.
--修改db_recovery_file_dest至asm中
SQL> alter system set db_recovery_file_dest='+FLASHBACK';
System altered.
--修改归档日志至asm中
SQL> alter system set log_archive_dest_1='location=+DATA';
System altered.
--关闭数据库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
--登录rman
[oracle@localhost ~]$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Mon Jun 27 08:02:37 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database (not started)
--启动数据库至nomount状态
RMAN> startup nomount;
Oracle instance started
Total System Global Area     167772160 bytes
Fixed Size                     1260672 bytes
Variable Size                 67109760 bytes
Database Buffers              92274688 bytes
Redo Buffers                   7127040 bytes
--恢复控制文件
RMAN>  restore controlfile from '/u01/control.ctl';
Starting restore at 27-JUN-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
channel ORA_DISK_1: copied control file copy
output filename=+DATA/tos/controlfile/current.268.754905785
Finished restore at 27-JUN-11
--打开数据库至mount状态
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
--copy数据文件至asm
RMAN> backup as copy database format '+DATA';
Starting backup at 27-JUN-11
Starting implicit crosscheck backup at 27-JUN-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=156 devtype=DISK
Finished implicit crosscheck backup at 27-JUN-11
Starting implicit crosscheck copy at 27-JUN-11
using channel ORA_DISK_1
Finished implicit crosscheck copy at 27-JUN-11
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile fno=00001 name=/u01/oradata/tos/system01.dbf
output filename=+DATA/tos/datafile/system.270.754905833 tag=TAG20110627T080352 recid=2 stamp=754905928
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting datafile copy
input datafile fno=00003 name=/u01/oradata/tos/sysaux01.dbf
output filename=+DATA/tos/datafile/sysaux.271.754905929 tag=TAG20110627T080352 recid=3 stamp=754905990
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile fno=00005 name=/u01/oradata/tos/example01.dbf
output filename=+DATA/tos/datafile/example.272.754905995 tag=TAG20110627T080352 recid=4 stamp=754906010
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:26
channel ORA_DISK_1: starting datafile copy
input datafile fno=00002 name=/u01/oradata/tos/undotbs01.dbf
output filename=+DATA/tos/datafile/undotbs1.273.754906021 tag=TAG20110627T080352 recid=5 stamp=754906025
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006 name=/u01/oradata/tos/xff01.dbf
output filename=+DATA/tos/datafile/xff.274.754906027 tag=TAG20110627T080352 recid=6 stamp=754906029
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00007 name=/u01/oradata/tos/xff02.dbf
output filename=+DATA/tos/datafile/xff.275.754906031 tag=TAG20110627T080352 recid=7 stamp=754906032
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile fno=00004 name=/u01/oradata/tos/users01.dbf
output filename=+DATA/tos/datafile/users.276.754906035 tag=TAG20110627T080352 recid=8 stamp=754906035
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
Finished backup at 27-JUN-11
RMAN-06497: WARNING: control file is not current, control file autobackup skipped
--恢复数据库
RMAN>  recover database;
Starting recover at 27-JUN-11
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 3 is already on disk as file /u01/oradata/tos/redo02.log
archive log filename=/u01/oradata/tos/redo02.log thread=1 sequence=3
media recovery complete, elapsed time: 00:00:03
Finished recover at 27-JUN-11
--修改数据库中数据文件路径
RMAN> switch database to copy;
datafile 1 switched to datafile copy "+DATA/tos/datafile/system.270.754905833"
datafile 2 switched to datafile copy "+DATA/tos/datafile/undotbs1.273.754906021"
datafile 3 switched to datafile copy "+DATA/tos/datafile/sysaux.271.754905929"
datafile 4 switched to datafile copy "+DATA/tos/datafile/users.276.754906035"
datafile 5 switched to datafile copy "+DATA/tos/datafile/example.272.754905995"
datafile 6 switched to datafile copy "+DATA/tos/datafile/xff.274.754906027"
datafile 7 switched to datafile copy "+DATA/tos/datafile/xff.275.754906031"
--打开数据库
RMAN> alter database open resetlogs;
database opened
--添加日志文件
SQL> alter database add logfile group 4 '+DATA' size 10m;
Database altered.
SQL> alter database add logfile group 5 '+DATA' size 10m;
Database altered.
SQL> alter database add logfile group 6 '+DATA' size 10m;
Database altered.
--添加临时文件
SQL> alter tablespace temp add tempfile '+DATA' size 30m;
Tablespace altered.
--删除原临时文件
SQL> alter tablespace temp drop tempfile '/u01/oradata/tos/temp01.dbf';
Tablespace altered.
--切换日志
SQL> alter system switch logfile; --多次
System altered.
--数据文件修改写入磁盘
SQL> alter system checkpoint;
System altered.
--检查联机日志状态
SQL> select group#,status from v$log;
    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 INACTIVE
         4 INACTIVE
         5 INACTIVE
         6 CURRENT
6 rows selected.
--删除原联机日志
SQL> alter database drop logfile group 1;
Database altered.
SQL> alter database drop logfile group 2;
Database altered.
SQL> alter database drop logfile group 3;
Database altered.
--查看修改后状态
SQL>  select name from v$datafile
  2      union
  3      select member from v$logfile
  4      union
  5      select name from v$controlfile
  6      union
  7      select name from v$tempfile;
NAME
--------------------------------------------------------------------------------
+DATA/tos/controlfile/current.268.754905785
+DATA/tos/datafile/example.272.754905995
+DATA/tos/datafile/sysaux.271.754905929
+DATA/tos/datafile/system.270.754905833
+DATA/tos/datafile/undotbs1.273.754906021
+DATA/tos/datafile/users.276.754906035
+DATA/tos/datafile/xff.274.754906027
+DATA/tos/datafile/xff.275.754906031
+DATA/tos/onlinelog/group_4.277.754906309
+DATA/tos/onlinelog/group_5.278.754906319
+DATA/tos/onlinelog/group_6.279.754906321
+DATA/tos/tempfile/temp.280.754906369

asm数据文件迁移(asm–>os)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:asm数据文件迁移(asm–>os)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

--查看当前情况
SQL> select count(*) from hr.a;
  COUNT(*)
----------
      1580
SQL>  select name from v$DATAFILE;
NAME
-----------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
+DG2/tasm/datafile/xff.256.754902279
6 rows selected.
--创建目录
SQL>  create directory asmsrc as '+DG2/TASM/datafile';
Directory created.
SQL>  create directory osdesc as '/u01/oradata';
Directory created.
--表空间离线
SQL> alter tablespace xff offline;
Tablespace altered.
--数据文件迁移
SQL> begin
  2      dbms_file_transfer.copy_file('ASMSRC',
  3      'xff.256.754902279',
  4      'OSDESC',
  5      'xff_new_2.dbf');
  6  END;
  7  /
PL/SQL procedure successfully completed.
--修改数据库中datafile路径
SQL> alter database rename file
  2             '+DG2/tasm/datafile/xff.256.754902279'
  3             to '/u01/oradata/xff_new_2.dbf';
Database altered.
--表空间在线
SQL> alter tablespace xff online;
Tablespace altered.
--测试迁移结果
SQL> select name from v$DATAFILE;
NAME
-------------------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
/u01/oradata/xff_new_2.dbf
6 rows selected.
SQL> select count(*) from hr.a;
  COUNT(*)
----------
      1580
--删除asm中文件
ASMCMD> rm XFF.256.754902279
ORA-15032: not all alterations performed
ORA-15028: ASM file '+dg2/tasm/datafile/XFF.256.754902279' not dropped;
currently being accessed (DBD ERROR: OCIStmtExecute)
--不能直接删除,关闭数据库后可以删除(应该是bug)

asm数据文件迁移(asm–>asm)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:asm数据文件迁移(asm–>asm)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

rman迁移操作

[oracle@localhost oradata]$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Mon Jun 27 05:50:03 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: TASM (DBID=3032096031)
RMAN> sql ‘alter tablespace xff offline’;
using target database control file instead of recovery catalog
sql statement: alter tablespace xff offline
RMAN> backup device type disk as copy datafile 6 format '+DG2';
Starting backup at 27-JUN-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=159 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006 name=+DATA/tasm/xff01.dbf
output filename=+DG2/tasm/datafile/xff.256.754899605 tag=TAG20110627T062003 recid=4 stamp=754899608
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 27-JUN-11
RMAN> switch tablepspace xff  to copy;
datafile 6 switched to datafile copy "+DG2/tasm/datafile/xff.256.754899605"
RMAN> sql 'alter tablespace xff online';
sql statement: alter tablespace xff online

sql验证操作

SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
+DG2/tasm/datafile/xff.256.754899605
6 rows selected.
SQL> select count(*) from hr.a;
  COUNT(*)
----------
      1580

asm数据文件迁移(os–>asm)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:asm数据文件迁移(os–>asm)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

--添加测试表空间
SQL> create tablespace xff datafile '/u01/oradata/xifenfei.dbf' size 10m autoextend on maxsize 100m;
Tablespace created.
--查看数据文件位置
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
/u01/oradata/xifenfei.dbf
6 rows selected.
--创建测试表
SQL> create table hr.a tablespace xff
  2  as
  3  select * from dba_tables;
Table created.
SQL> select count(*) from hr.a;
  COUNT(*)
----------
      1580
--转移数据文件位置
[oracle@localhost oradata]$ rman target /
Recovery Manager: Release 10.2.0.3.0 - Production on Mon Jun 27 04:30:22 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: TASM (DBID=3032096031)
RMAN> sql 'alter tablespace xff offline';
using target database control file instead of recovery catalog
sql statement: alter tablespace xff offline
RMAN> backup as copy tablespace xff format '+DATA';
Starting backup at 27-JUN-11
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=132 devtype=DISK
channel ORA_DISK_1: starting datafile copy
input datafile fno=00006 name=/u01/oradata/xifenfei.dbf
output filename=+DATA/tasm/datafile/xff.269.754893121 tag=TAG20110627T043200 recid=2 stamp=754893123
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 27-JUN-11
RMAN> switch tablespace xff to copy;
datafile 6 switched to datafile copy "+DATA/tasm/datafile/xff.269.754893121"
RMAN> sql 'alter tablespace xff online';
sql statement: alter tablespace xff online
--查看转移后的数据文件位置
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
+DATA/tasm/datafile/xff.269.754893121
6 rows selected.
--测试其中数据是否存在
SQL> select count(*) from hr.a;
  COUNT(*)
----------
      1580
--创建asm中文件别名
ASMCMD> mkalias  +DATA/tasm/datafile/xff.269.754893121 +DATA/tasm/xff01.dbf
--文件重命名
SQL> alter tablespace xff offline;
Tablespace altered.
SQL> alter database rename file '+DATA/tasm/datafile/xff.269.754893121' to '+DATA/tasm/xff01.dbf';
Database altered.
SQL> alter tablespace xff online;
Tablespace altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
+DATA/tasm/system01.dbf
+DATA/tasm/undotbs01.dbf
+DATA/tasm/sysaux01.dbf
+DATA/tasm/users01.dbf
+DATA/tasm/example01.dbf
+DATA/tasm/xff01.dbf
6 rows selected.
--手工删除原来数据
[oracle@localhost oradata]$ rm xifenfei.dbf 

说明:可以在rman移植数据文件位置的时候,同时处理好别名,然后对表空间重命名,实现只需要表空间离线一次

使用rman备份做Data Guard

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:使用rman备份做Data Guard

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

前两天公司的一套oracle dg因为维护人员的疏忽到值出现gap,无法恢复,只能重做,因为该库每天都有rman的增量备份,所以选择最近的一次全部进行重做dg
1、主库
ALTER DATABASE CREATE STANDBY CONTROLFILE AS ‘/tmp/control01.ctl’;
alter system archive log current;
2、修改pfile文件(因为我是重做,所以不需要做)
11g data guard(PHYSICAL STANDBY)配置
3、拷贝控制文件/rman文件到备库的相同位置
备份全备的内容(/opt/ORBS/data /tmp/control01.ctl)
4、复制数据库做dg
启动到nomount状态
rman target sys/srtsysdb@zjch_Action auxiliary /
duplicate target database for standby dorecover nofilenamecheck;
出现以下错误
RMAN-06025: no backup of log thread 1 seq 675 lowscn 1096519 found to restore
RMAN-06025: no backup of log thread 1 seq 674 lowscn 1095666 found to restore
RMAN-06025: no backup of log thread 1 seq 673 lowscn 1095663 found to restore
RMAN-06025: no backup of log thread 1 seq 672 lowscn 1095656 found to restore
RMAN-06025: no backup of log thread 1 seq 671 lowscn 1095081 found to restore
RMAN-06025: no backup of log thread 1 seq 670 lowscn 1092545 found to restore
RMAN-06025: no backup of log thread 1 seq 669 lowscn 1090351 found to restore
RMAN-06025: no backup of log thread 1 seq 668 lowscn 1088837 found to restore
RMAN-06025: no backup of log thread 1 seq 667 lowscn 1088834 found to restore
RMAN-06025: no backup of log thread 1 seq 666 lowscn 1088721 found to restore
原因:因为控制文件和备份文件中有时间间隔,所以rman要恢复,但是归档日志没有传输过来,所以不能恢复。
–到主库的归档目录查看这些日志是否存在
ls -l(如果存在,下面的操作恢复日志的操作可以忽略)
–查看这些日志是否存在
list backup of archivelog from sequence 666 until sequence 675;
–如果存在rman备份中,使用rman进行恢复
restore archivelog from sequence 666 until sequence 675;
如果存在相关联机日志就不需要添加
–添加redo log
alter database add logfile group 1 (‘/opt/oracle/oradata/zjch/redo01.log’) size 50m;
alter database add logfile group 2 (‘/opt/oracle/oradata/zjch/redo02.log’) size 50m;
alter database add logfile group 3 (‘/opt/oracle/oradata/zjch/redo03.log’) size 50m;
–添加sandby log
ALTER DATABASE ADD STANDBY LOGFILE (‘/opt/oracle/oradata/zjch/std_redo04.log’) SIZE 50M reuse;
ALTER DATABASE ADD STANDBY LOGFILE (‘/opt/oracle/oradata/zjch/std_redo05.log’) SIZE 50M reuse;
ALTER DATABASE ADD STANDBY LOGFILE (‘/opt/oracle/oradata/zjch/std_redo06.log’) SIZE 50M reuse;
ALTER DATABASE ADD STANDBY LOGFILE (‘/opt/oracle/oradata/zjch/std_redo07.log’) SIZE 50M reuse;
5、开启日志应用
–开启实时应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
–开启应用(根据配置和需求)
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
到这一步会如果主机端有所需的归档日志,会自动传输过来,并进行恢复,不用人工干预。
–查看alter文件,查询日志传输是否正常
–查看日志是否传输完成
select thread#, low_sequence#, high_sequence# from v$archive_gap;
–主库切换日志
alter system switch logfile;
–查询最大sequence
select max(sequence#) from v$archived_log;
–备库查看alert文件
tail -100 alert.log
Media Recovery Log /opt/oracle/oradata/zjch/archive/stdarch/1_46544_681145105.dbf
Media Recovery Log /opt/oracle/oradata/zjch/archive/stdarch/1_46545_681145105.dbf 有类似内容
–查询最大sequence
select max(sequence#) from v$archived_log;
–主库建立一个测试表
create table SCOTT.t_test(id number,name varchar2(10));
insert into SCOTT.t_test values(1,’aaaa’);
commit;
alter system switch logfile;
–查询最大sequence
select max(sequence#) from v$archived_log;
–备库检查
–查询最大sequence
select max(sequence#) from v$archived_log;
–取消日志应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE cancel;
–只读模式打开数据库
alter database open read only;
–查询刚刚建的表和插入数据是否通报不成功
select * from SCOTT.t_test;
–重启备库,设置为日志应用模式
shutdown immediate;
startup mount;
–开启实时应用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
–开启应用(根据配置和需求)
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
–主库删除测试表
drop table SCOTT.t_test;

Rman备份恢复命令

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:Rman备份恢复命令

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一、backup操作
备机集
1.设置备份标记
backup database tag=’full_bak1′;
注:每个标记必须唯一,相同的标记可以用于多个备份只还原最新的备份。
2.设置备份集大小(一次备份的所有结果为一个备份集,要注意备份集大小)
backup database maxsetsize=100m tag=’datafile1′;
注:maxsetsize限定备份集的大小。所以必须大于数据库总数据文件的大小,否则会报错。
RMAN-06183: datafile or datafile copy larger than MAXSETSIZE: file# 1 /data/oradata/system01.dbf
3.设置备份片大小(磁带或文件系统限制)
run {
allocate channel c1 type disk maxpicecsize 100m format ‘/data/backup/full_0_%U_%T’;
backup database tag=’full_0′;
release channel c1;
}
可以在allocate子句中设定每个备份片的大小,以达到磁带或系统限制。
也可以在configure中设置备份片大小。
Configure channel device type disk maxpiecesize 100 m;
configure channel device type disk clear;
4.备份集的保存策略
backup database keep forever; –永久保留备份文件
backup database keep until time=’sysdate+30′; –保存备份30天
5.重写configure exclude命令
backup databas noexclude keep forever tag=’test backup’;
6.检查数据库错误
backup validate database;
使用RMAN来扫描数据库的物理/逻辑错误,并不执行实际备份。
7.跳过脱机,不可存取或只读文件
backup database skip readonly;
backup database skip offline;
backup database skip inaccessible;
backup database ship readonly skip offline ship inaccessible;
8.强制备份
backup database force;
9.基于上次备份时间备份数据文件
1>只备份添加的新数据文件
backup database not backed up;
2>备份”在限定时间周期内”没有被备份的数据文件
backup database not backed up since time=’sysdate-2′;
10.备份操作期间检查逻辑错误
backup check logical database;
backup validate check logical database;
11.生成备份副本
backup database copies=2;
12.备份控制文件
backup database device type disk includ current controlfile;
建立映像副本
1、建立数据文件映像副本
RMAN>backup as copy format=’c:\df_5.dbf’ datafile 5; 或者
RMAN>copy datafile 5 to ‘c:\df_5.dbf’ ;
2、建立控制文件映像副本
RMAN>backup as copy format=’c:\demo.ctl’ current controlfile; 或者
RMAN>copy current controlfile to ‘c:\demo.ctl’;
3、建立归档日志映像副本
RMAN>backup as copy format=’c:\arc10.log’ archivelog sequence 10; 或者
RMAN>copy archivelog ‘c:\demo\archive\arc00020_012345.001’ to ‘c:\arc20.log’;
4、并行化建立映像副本
RMAN>configure device type disk parallelism 3;
RMAN>backup as copy format =’c:\df_%f.dbf’ datafile 5,6,7 ;
RMAN>configure device type disk clear;
5、指定映像副本标记
RMAN>backup as copy format=’c:\df_%f.dbf’ datafile 5 tag=df_5; 或者
RMAN>copy datafile 5 to ‘c:\df_%f.dbf’ tag=df_5;
二、RMAN恢复操作
RMAN完全恢复
1、恢复数据库
1)、所有数据文件被删除
c:\rman target sys/oracel@test nocatalog
RMAN>startup force mount
RMAN> run {
restore databse ;
recover database;
sql ‘alter database open’ ;
}
2)、数据文件所在磁盘出现硬件故障
RMAN> run {
startup force mount;
set newname for datafile 1 to ‘c:\demo\system01.dbf’;
set newname for datafile 2 to ‘c:\demo\dundotbs01.dbf’;
set newname for datafile 3 to ‘c:\demo\sysaux01.dbf’;
set newname for datafile 4 to ‘c:\demo\users01.dbf’;
set newname for datafile 5 to ‘c:\demo\example01.dbf’;
set newname for datafile 6 to ‘c:\demo\test0.dbf’;
restore database;
switch datafile all;
recover database;
sql ‘alter database open ‘;
}
2、恢复SYSTEM表空间的数据文件
1)、SYSTEM表空间的数据文件被误删除
RMAN>run {
startup force mount;
restore datafile 1;
recover datafile 1;
sql ‘alter database open’ ;
}
2)、SYSTEM表空间数据文件所在的磁盘出现故障
RMAN> run {
startup force mount;
set newname for datafile 1 to ‘c:\demo\system01.dbf’;
restore datafile 1;
switch datafile 1;
recover datafile 1;
sql ‘alter database open’;
}
3、在OPEN状态下恢复关闭后意外丢失数据文件
1)、数据文件被删除
RMAN>run {
startup force mount;
sql ‘alter database datafile 4 offline’;
sql ‘alter database open ‘;
restore datafile 4;
recover datafile 4;
sql ‘alter database datafile 4 online’;
}
2)、数据文件所在的磁盘出现损坏
RMAN>run {
startup force mount;
sql ‘alter database datafile 4 offline’;
sql ‘alter database open ‘;
set newname for datafile 4 to ‘c:\demo\user01.dbf’;
restore datafile 4;
switch datafile 4;
recover datafile 4;
sql ‘alter database datafile 4 online’;
}
4、在OPEN状态下恢复打开时意外丢失的数据文件
1)、数据文件被误删除
RMAN>run {
sql ‘alter database datafile 4 offline’;
restore datafile 4;
recover datafile 4;
sql ‘alter database datafile 4 online’;
}
2)、数据文件所在磁盘出现故障
RMAN>run {
sql ‘alter database datafile 4 offline’;
set newname for datafile 4 to ‘c:\demo\user01.dbf’;
restore datafile 4;
switch datafile 4 ;
recover datafile 4;
sql ‘alter database datafile 4 online’;
}
5、在OPEN状态下恢复未备份的数据文件(创造新数据文件后没有进行过备份)
1)、数据文件被误
RMAN>run {
startup force mount;
sql ‘alter database datafile 7 offline ‘;
sql ‘alter database open’;
restore datafile 7;
recover datafile 7;
sql ‘alter database datafile 7 online’;
}
2)、数据文件所在磁盘出现故障
RMAN>run {
startup force mount;
sql ‘alter database datafile 7 offline ‘;
sql ‘alter database open’;
set newname for datafile 7 to ‘c:\demo\user04.dbf’;
restore datafile 7;
switch datafile 7;
recover datafile 7;
sql ‘alter database datafile 7 online’;
}
6、恢复表空间
1)、表空间被删除
RMAN>run {
sql ‘alter tablespace users offline for recover’;
restore tablespace users;
recover tablespace users;
sql ‘alter tablespace users online’;
}
2)、表空间的数据文件所在磁盘出现故障
RMAN>run {
sql ‘alter tablespace users offline for recover’;
set newname for datafile 4 to ‘c:\demo\user01.dbf’;
restore tablespace users;
switch tablespace users;
recover tablespace users;
sql ‘alter tablespace users online’;
}
7、数据块介质恢复
RMAN>blockrecover device type disk datafile 5 block 20,21,100 ;
RMAN不完全恢复
1、基本时间恢复
c:\set nls_date_format=yyyy-dd-mm hh24:mi:ss
c:\rman target sys/dddddd@train nocatalog
RMAN>run{
startup force mount;
set until time=’2010-09-09 13:00:00′;
restore database;
recover database;
sql ‘alter database open resetlogs’;
}
2、基于SCN恢复
RMAN>run {
startup force mount;
set until scn=123456;
restore database;
recover database;
sql ‘alter database open resetlogs’;
}
3、基于日志序列号恢复
RMAN>run {
startup force mount;
set until sequence=58;
restore database;
recover database;
sql ‘alter database open resetlogs’;
}
4、基于备份控制文件恢复
c:\set nls_date_format=yyyy-dd-mm hh24:mi:ss
c:\rman target sys/oracle@test nocatalog
RMAN>startup force nomount;
RMAN>set dbid=1113606269;
RMAN>restore controlfile from autobackup maxseq 6;
RMAN>alter database mount;
RMAN>run {
set until time=’2010-09-5 12:00:08′;
restore database;
recover database;
sql ‘alter database open resetlogs;
}
当执行了上述4种不完全恢复之后,建议删除早期的所有备份,并重新备份数据库
RMAN>run {
delete noprompt backup;
delete noprompt copy;
backup database format=’c:\backup\%d_%s.bak’;
sql ‘alter system archive log current’;
}

Rman管理命令

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:Rman管理命令

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一、相关查询命令
1.List 当前RMAN所备份的数据库
RMAN> list incarnation;
汇总查询:–如果备份文件多的话多用这两个list命令可以对备份文件有个总体了解。
1.1. list backup summary; –概述可用的备份
B 表示backup
A 表示Archivelog、 F 表示full backup、 0,1,2 表示incremental level备份
A 表示可用AVALIABLE、 X 表示EXPIRED
这个命令可以派生出很多类似命令,例如
list backup of database summary
list backup of archivelog all summary
list backup of tablespace users summary;
list backup of datafile n,n,n summary
这些命令可以让我们对已有的备份文件有一个整体,直观的了解。
1.2.list backup by file;–按照文件类型分别列出
分别为:数据文件列表、归档日志列表、控制文件列表、SPFILE列表
1.3.list backup;
这个命令列出已有备份集的详细信息。
1.4.list expired backup;
列出过期的备份文件
1.5.list copy;
列出copy文件
list copy of database;
list copy of controlfile;
list copy of tablespace users;
list copy of datafile n,n,n;
list copy of archivelog all;
list copy of archivelog from scn 10000;
list copy of archivelog until sequence 12;
2. List 相关文件的信息
list backup of {archivelog, controlfile, database, datafile, spfile, tablespace};
list backup of database; –full,incremental,tablespace,datafile
2.1服务器参数文件:
list backup of spfile;
2.2 控制文件:
list backup of controlfile;
2.3 数据文件:
list backup of datafle n,n,n,n;
2.4表空间:
list backup of tablespace tablespace_name;–表空间对应的backup
2.5归档日志:
list backup of archivelog {all, from, high, like, logseq, low, scn, sequence, time, until};
list backup of archivelog all;
list backup of archivelog until time ‘sysdate-1’;
list backup of archivelog from sequence 10;
list backup of archivelog until sequence 10;
list backup of archivelog from scn 10000;
list backup of archivelog until scn 200000;
list archivelog from scn 1000;
list archivelog until scn 2000;
list archivelog from sequence 10;
list archivelog until sequence 12;
二、RMAN常用检查命令
1、report常用命令总结备忘
report用于判断数据库当前可恢复状态、以及数据库已有备份的信息。最常使用的是report obsolete; report schema;
report {device, need, obsolete, schema, unrecoverable}
report schema;
report obsolete;
report unrecoverable;
report need backup;
report need backup days=3; –报告最近3天内没有备份的文件
report need backup redundancy=3; –报告冗余次数小于3的数据文件。
report need backup recovery window of 2 days;
1.1.report schema;
报告数据库模式
1.2.report obsolete;
报告已丢弃的备份集(配置了保留策略)。
1.3.report unrecoverable;
报告当前数据库中不可恢复的数据文件(即没有这个数据文件的备份、或者该数据文件的备份已经过期)
1.4.report need backup;
报告需要备份的数据文件(根据条件不同)
report need backup days=3;
–最近三天没有备份的数据文件(如果出问题的话,这些数据文件将需要最近3天的归档日志才能恢复)
report need backup incremental=3;
–需要多少个增量备份文件才能恢复的数据文件。(如果出问题,这些数据文件将需要3个增量备份才能恢复)
report need backup redundancy=3;
–报告出冗余次数小于3的数据文件
–例如数据文件中包含2个数据文件system01.dbf和users01.dbf.
–在3次或都3次以上备份中都包含system01.dbf这个数据文件,而users01.dbf则小于3次
–那么,报告出来的数据文件就是users01.dbf
–即,报告出数据库中冗余次数小于 n 的数据文件
report need backup recovery window of 2 days;
–报告出恢复需要2天归档日志的数据文件
2、crosscheck 命令
2.1 备份集有两种状态A(Available,RMAN认为该项存在于备份介质上)X(Expired,备份存在于控制文件或恢复目录中,但是并没有物理存在于备份介质上)
   
2.2 crosscheck 的目的是检查RMAN 的目录以及物理文件,如果物理文件不存在于介质上,将标记为Expired。如果物理文件存在,将维持Available。如果原先标记为Expired的备份集再次存在于备份介质上(如恢复了损坏的磁盘驱动器后),crosscheck将把状态重新从Expired标记回Available。
  
2.3 crosscheck 输出分两部分。第一部分列出确定存在于备份介质上的所有备份集片,第二部分列出不存在于备份介质上的备份集片,并将其标记为Expired。当设置备份保存策略后,一个备份过期,crosscheck之后标记为丢弃的备份状态依旧为availabel,要删除丢弃备份delete obsolete。
  
2.4 示例:
   crosscheck backup
   crosscheck backup of datafile 1;
   crosscheck backup of tablespace users;
   crosscheck backup of controfile;
   crosscheck backup of controlfile;
   crosscheck backup tag=’SAT_BACKUP’;
   crosscheck backup completed after ‘sysdate – 2’
   crosscheck backup completed between ‘sysdate – 5’ and ‘sysdate -2 ‘
   crosscheck backup device type sbt;
   crosscheck archivelog all;
   crosscheck archivelog like ‘%ARC00012.001’
   crosscheck archivelog from sequence 12;
   crosscheck archivelog until sequence 522;
3、validate 命令
3.1 validate 命令验证备份集片是否能够被还原 
3.2 list backup summary; 得到了备份集得主键ID如40,然后validate backupset 40;
三、备份保存策略以及change ,delete命令
0.带delete参数的change 命令删除备份集,从备份介质,并且从控制文件和恢复目录中删除。
   change backupset 117,118 delete;
   change backuppiece 1304 delete;
   change archivelog until logseq =544 delete;
  
1.两类策略:恢复窗口备份保存策略(recovery windows backup retension policy) 基于时间
      备份冗余备份保存策略(backup redundancy backup retension policy) 基于备份的数量
两类策略互相排斥
   
2.即使使用了备份保存策略,备份到期并不删除,只是在RMAN目录中标记为丢弃,看到的状态依旧为available;要查看标记为丢弃的备份 report obsolete,只有使用delete obsolete才真正物理删除。
  
3.configure retension policy to recovery window of 7 days;configure retension policy to redundancy 3;显示结果 show all;
   
4.查看到期丢弃的备份时,可能需要手工保存一些备份,可以使用change 命令带keep 参数,使用这个命令后,那些被修改的备份将被认为是个long-term backup,不在受保存策略影响也就是说delete obsolete 也不删除。
  
5.要使备份时候不受保存策略影响 ,使用带keep参数的backup 命令
   backup database keep forever;
   backup database keep 5 days;
  
6.change 命令功能
   可以修改备份为永久保存并将以及该备份的相关的日志保存下来,保证总能将备份恢复到当前时间点
   change backupset 31 keep forever logs;
   可以设置备份丢弃的新日期 ,将备份在多保存7 天,7 天后将删除
   change backupset 32 keep until time ‘sysdata + 7’ logs;
   change 可以将备份集设置为unavailable
   change backupset 33 unavailable;
   标记为unavailable状态的备份集并不参与crosscheck;
四、CONFIGURE常用命令总结备忘
4.1 显示当前的配置信息
4.1.1 RMAN> show all;
RMAN 配置参数为:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F’; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM ‘AES128’; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘D:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\SNCFDBA.ORA’; # default
4.1.2 查询RMAN设置中非默认值:
SQL> select name,value from v$rman_configuration;
4.2. 常用的configure选项
4.2.1 保存策略 (retention policy)
configure retention policy to recovery window of 7 days;
configure retention policy to redundancy 5;
configure retention policy clear;
CONFIGURE RETENTION POLICY TO NONE;
第一种recover window是保持所有足够的备份,可以将数据库系统恢复到最近七天内的任意时刻。任何超过最近七天的数据库备份将被标记为obsolete。
第二种redundancy 是为了保持可以恢复的最新的5份数据库备份,任何超过最新5份的备份都将被标记为redundancy。它的默认值是1份。
第三四:NONE 可以把使备份保持策略失效,Clear 将恢复默认的保持策略
4.2.2 备份优化 backup optimization
configure backup optimization on;
configure backup optimization off;
configure backup optimization clear;
–默认值为关闭,如果打开,rman将对备份的数据文件及归档等文件进行一种优化的算法。
4.2.3 默认设备 default device type
configure default device type to disk;
configure default device type to stb;
configure default device type clear;
–是指定所有I/O操作的设备类型是硬盘或者磁带,默认值是硬盘,磁带的设置是CONFIGURE DEFAULT DEVICE TYPE TO SBT;
4.3.4 控制文件 controlfile
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to ‘/cfs01/backup/conf/conf_%F’;
configure controlfile autobackup clear;
configrue controlfile autobackup format for device type disk clear;
configrue snapshot controlfile name to ‘/cfs01/backup/snapcf/scontrofile.snp’;
–是配置控制文件的快照文件的存放路径和文件名,这个快照文件是在备份期间产生的,用于控制文件的读一致性。
configrue snapshot controlfile name clear;
–强制数据库在备份文件或者执行改变数据库结构的命令之后将控制文件自动备份,默认值为关闭。这样可以避免控制文件和catalog丢失后,控制文件仍然可以恢复。
4.3.5 并行数(通道数) device type disk|stb pallelism n;
configure device type disk|stb parallelism 2;
configure device type disk|stb clear; –用于清除上面的信道配置
configure channel device type disk format ‘e/:rmanback_%U’;
configure channel device type disk maxpiecesize 100m
configure channel device type disk rate 1200K
configure channel 1 device type disk format ‘e/:rmanback_%U’;
configure channel 2 device type disk format ‘e/:rmanback_%U’;
configure channel 1 device type disk maxpiecesize 100m
–配置数据库设备类型的并行度。
4.3.6 生成备份副本 datafile|archivelog backup copies
configure datafile backup copies for device type disk|stb to 3;
configure archivelog backup copies for device type disk|stb to 3;
–是设置数据库的归档日志的存放设备类型
configure datafile|archivelog backup copies for device type disk|stb clear
BACKUP DEVICE TYPE DISK DATABASE FORMAT ‘/disk1/backup/%U’, ‘/disk2/backup/%U’, ‘/disk3/backup/%U’;
–是配置数据库的每次备份的copy数量,oracle的每一次备份都可以有多份完全相同的拷贝。
4.3.7 排除选项 exclude
configure exclude for tablespace ‘users’;
configrue exclude clear;
–此命令用于将指定的表空间不备份到备份集中, 此命令对只读表空间是非常有用的。
4.3.8 备份集大小 maxsetsize
configure maxsetsize to 1G|1000M|1000000K|unlimited;
configure maxsetsize clear;
4.3.9 其它选项 auxiliary
CONFIGURE AUXNAME FOR DATAFILE 1 TO ‘/oracle/auxfiles/aux_1.f’;
CONFIGURE AUXNAME FOR DATAFILE 2 TO ‘/oracle/auxfiles/aux_2.f’;
CONFIGURE AUXNAME FOR DATAFILE 3 TO ‘/oracle/auxfiles/aux_3.f’;
CONFIGURE AUXNAME FOR DATAFILE 4 TO ‘/oracle/auxfiles/aux_4.f’;
CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 2 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 3 CLEAR;
CONFIGURE AUXNAME FOR DATAFILE 4 CLEAR;

oracle之rman增量备份

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:oracle之rman增量备份

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、差异性增量备份
backup incremental level 0 database format ‘c:\rman\L0_%U.bak’;
backup incremental level 1 database format ‘c:\rman\L1C_%U.bak’;
2、累积性增量备份
backup incremental level 0 database format ‘c:\rman\L0_%U.bak’;
backup incremental level 1 cumulative database format ‘c:\rman\L1C_%U.bak’;
Note:差异性备份是同一级别不备份,而累积性备份是同一级别的也备份
备份的级别可以为0、1、2、3、4
3、启用/关闭oracle块更改跟踪
开启
alter database enable block change tracking using file
‘c:\oracle\product\10.2.0\admin\orcl\bdump\block_trace.txt‘
关闭
alter database disable block change tracking;

oracle之rman(2)

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:oracle之rman(2)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、设置并发执行rman备份
1)手工配置
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup database format ‘c:\rman\d_%U_%p.bak’
tag=’xifenfei’;
}
2)参数中配置
configure device type disk parallelism 3 backup type to backupset;
backup database format ‘c:\rman\d_%U.bak’ tag=’xifenfei’;
2、设置备份文件大小
run{ allocate channel c1 type disk maxpiecesize 100m;
backup database format ‘c:\rman\test_%U_%p.bak’ filesperset 2 maxsetsize 500m;}
note:maxpiecesize–单个备份文件大小
filesperset–一个backset中含有的datafile的数量
maxsetsize–backset的大小
3、备份控制文件
1)配置自动备份
configure controlfile autobackup on;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR
DEVICE TYPE DISK TO ‘c:\rman\cl_%F.ctl’;
2)备份时顺带备份
backup datafile 5 format ‘c:\rman\d_%U.bak’
include current controlfile;
4、一次备份多份(最多四份)
1)直接指定
backup copies 2 datafile 5 format
‘c:\rman\%U.bak’,’c:\temp\%U.bak’;
2)配置文件中指定
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;
backup datafile 5 format ‘c:\temp\t_%U.bak’,’c:\rman\t_%U.bak’;

oracle 之rman备份数据库

联系:手机/微信(+86 17813235971) QQ(107644445)

标题:oracle 之rman备份数据库

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

1、备份整个数据库
backup database format ‘c:\rman\all_%U.bak’;
2、备份表空间
backup tablespace abc format ‘c:\rman\t_%U.bak’;
3、备份数据文件
1)backup datafile 5 format ‘c:\rman\d_%U.bak’;
2)backup datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ABC.DBF’
format ‘c:\rman\d_%U.bak’;
4、备份控制文件
backup current controlfile format ‘c:\rman\ctr_%U.ctl’;
5、备份数据文件同时备份控制文件
backup datafile 5 format ‘c:\rman\d_c_%U.bak’
include current controlfile;
6、备份spfile文件
backup spfile format ‘c:\rman\sp_%U.sp’;
7、备份日志文件
backup archivelog sequence between 38 and 41 format ‘c:\rman\ar_%U.log’
delete all input(可选项,表示备份日志文件后,删除原来日志文件);
8、备份数据库和日志文件
backup database plus archivelog format ‘c:\rman \d_ar_%U.d_a’;
9、copy功能(相当于用户管理备份)
backup as copy database format ‘c:\rman\%U.cy’;
copy datafile 5 to ‘c:\rman\d_%U.cy’;
note:backup as copy可以备份整个数据库
copy只能备份current controlfile、datafile、tablespace等,这个数据库不支持