Showing posts with label Oracle RMAN. Show all posts
Showing posts with label Oracle RMAN. Show all posts

Wednesday, January 14, 2009

RMAN blockrecover

http://www.dbasupport.com/forums/showthread.php?referrerid=15940&t=56629

RMAN> backup validate check logical database

and then post the result.

if it reports any corruption try looking into the following view

select * from v$database_block_corruption;

if rman reports corruption you can try

rman>blockrecover corruption list;


another method check corruption is runing dbverify on the datafile.

Sunday, January 11, 2009

Cataloging Backup Pieces

http://www.oracle-base.com/articles/10g/RMANEnhancements10g.php

Cataloging Backup Pieces
It is now possible to manually catalog a backup piece using the CATALOG commands in RMAN. This allows backup files to be moved to alternate locations or manually archived to tape and brought back for restore operations. In Oracle 9i this functionality was only availabale for controlfile copies, archivelog copies and datafile copies. In addition, there are some shortcuts to allow multiple files to be cataloged using a single command. The following examples give the general idea:
# Catalog specific backup piece.
CATALOG BACKUPPIECE '/backup/MYSID/01dmsbj4_1_1.bcp';

# Catalog all files and the contents of directories which
# begin with the pattern "/backup/MYSID/arch".
CATALOG START WITH '/backup/MYSID/arch';

# Catalog all files in the current recovery area.
CATALOG RECOVERY AREA NOPROMPT;

# Catalog all files in the current recovery area.
# This is an exact synonym of the previous command.
CATALOG DB_RECOVERY_FILE_DEST NOPROMPT;
The NOPROMPT clause supresses user confirmation for all matching files.

应对RMAN-06026错误,使用dbms_backup_restore进行恢复

应对RMAN-06026错误,使用dbms_backup_restore进行恢复
http://www.eygle.com/archives/2005/06/oorman06026iioe.html

昨天做一个实验,结果把数据库搞坏了,当试图进行恢复时居然报了RMAN-06026错误。 回想一下,原来在尝试恢复中使用了_allow_resetlogs_corruption参数,resetlogs之后,Oracle使用当前的控制文件不允许从这个历史备份集中进行恢复。
由于我没有使用catalog,所以尝试使用dbms_backup_restore进行恢复。
1.错误信息
我们看到虽然list backup可以显示备份集,但是无法进行恢复,错误为RMAN-06026,RMAN-06026。

[oracle@jumper oradata]$ rman target /

Recovery Manager: Release 9.2.0.4.0 - Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: CONNER (DBID=3152029224)

RMAN> restore database;

Starting restore at 11-JUN-05

using target database controlfile instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=11 devtype=DISK
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 06/11/2005 01:19:01
RMAN-06026: some targets not found - aborting restore
RMAN-06023: no backup or copy of datafile 3 found to restore
RMAN-06023: no backup or copy of datafile 2 found to restore
RMAN-06023: no backup or copy of datafile 1 found to restore

RMAN> list backup;


List of Backup Sets
===================

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
13 Full 1G DISK 00:03:20 09-JUN-05
BP Key: 13 Status: AVAILABLE Tag: TAG20050609T173346
Piece Name: /opt/oracle/product/9.2.0/dbs/0ggmiabq_1_1
SPFILE Included: Modification time: 08-JUN-05
List of Datafiles in backup set 13
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 240560269 09-JUN-05 /opt/oracle/oradata/conner/system01.dbf
2 Full 240560269 09-JUN-05 /opt/oracle/oradata/conner/undotbs01.dbf
3 Full 240560269 09-JUN-05 /opt/oracle/oradata/conner/users01.dbf

RMAN> exit


Recovery Manager complete.


2.使用dbms_backup_restore进行恢复
dbms_backup_restore是一个非常强大的package,可以在数据库nomount下使用,用于从备份集中读取各类文件。
本例使用如下脚本:

DECLARE
devtype varchar2(256);
done boolean;
BEGIN
devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');
sys.dbms_backup_restore.restoreSetDatafile;
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>01,toname=>'/opt/oracle/oradata/conner/system01.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>02,toname=>'/opt/oracle/oradata/conner/undotbs01.dbf');
sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>03,toname=>'/opt/oracle/oradata/conner/users01.dbf');
sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/opt/oracle/product/9.2.0/dbs/0ggmiabq_1_1', params=>null);
sys.dbms_backup_restore.deviceDeallocate;
END;
/


3.执行恢复

[oracle@jumper conner]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Sat Jun 11 01:24:34 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 101782828 bytes
Fixed Size 451884 bytes
Variable Size 37748736 bytes
Database Buffers 62914560 bytes
Redo Buffers 667648 bytes

SQL> DECLARE
2 devtype varchar2(256);
3 done boolean;
4 BEGIN
5 devtype:=sys.dbms_backup_restore.deviceAllocate (type=>'',ident=>'t1');
6 sys.dbms_backup_restore.restoreSetDatafile;
7 sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>01,toname=>'/opt/oracle/oradata/conner/system01.dbf');
8 sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>02,toname=>'/opt/oracle/oradata/conner/undotbs01.dbf');
9 sys.dbms_backup_restore.restoreDatafileTo(dfnumber=>03,toname=>'/opt/oracle/oradata/conner/users01.dbf');
10 sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'/opt/oracle/product/9.2.0/dbs/0ggmiabq_1_1',

params=>null);
11 sys.dbms_backup_restore.deviceDeallocate;
12 END;
13 /

PL/SQL procedure successfully completed.

SQL>


至此,从备份集中读取文件完毕。
4.恢复控制文件
由于大意,也没有备份控制文件,所以只好重建控制文件。

SQL> alter database mount;

Database altered.

SQL> alter database backup controlfile to trace;

Database altered.


找到trace文件,编辑、执行重建控制文件需要部分:

[oracle@jumper oracle]$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Sat Jun 11 01:30:50 2005

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production


SQL> shutdown immediate;
ORA-01109: database not open


Database dismounted.
ORACLE instance shut down.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 101782828 bytes
Fixed Size 451884 bytes
Variable Size 37748736 bytes
Database Buffers 62914560 bytes
Redo Buffers 667648 bytes
SQL> set echo on
SQL> @ctl
SQL>
SQL> CREATE CONTROLFILE REUSE DATABASE "CONNER" RESETLOGS ARCHIVELOG
2 -- SET STANDBY TO MAXIMIZE PERFORMANCE
3 MAXLOGFILES 5
4 MAXLOGMEMBERS 3
5 MAXDATAFILES 100
6 MAXINSTANCES 1
7 MAXLOGHISTORY 1361
8 LOGFILE
9 GROUP 1 '/opt/oracle/oradata/conner/redo01.log' SIZE 10M,
10 GROUP 2 '/opt/oracle/oradata/conner/redo02.log' SIZE 10M,
11 GROUP 3 '/opt/oracle/oradata/conner/redo03.log' SIZE 10M
12 -- STANDBY LOGFILE
13 DATAFILE
14 '/opt/oracle/oradata/conner/system01.dbf',
15 '/opt/oracle/oradata/conner/undotbs01.dbf',
16 '/opt/oracle/oradata/conner/users01.dbf'
17 CHARACTER SET ZHS16GBK
18 ;

Control file created.


5.执行恢复

SQL> recover database;
ORA-00283: recovery session canceled due to errors
ORA-01610: recovery using the BACKUP CONTROLFILE option must be done


SQL> recover database using backup controlfile until cancel;
ORA-00279: change 240560269 generated at 06/09/2005 17:33:48 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/conner/archive/1_7.dbf
ORA-00280: change 240560269 for thread 1 is in sequence #7


Specify log: {=suggested | filename | AUTO | CANCEL}

auto
ORA-00279: change 240600632 generated at 06/10/2005 10:42:26 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/conner/archive/1_8.dbf
ORA-00280: change 240600632 for thread 1 is in sequence #8
ORA-00278: log file '/opt/oracle/oradata/conner/archive/1_7.dbf' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00279: change 240620884 generated at 06/10/2005 10:45:42 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/conner/archive/1_9.dbf
ORA-00280: change 240620884 for thread 1 is in sequence #9
ORA-00278: log file '/opt/oracle/oradata/conner/archive/1_8.dbf' no longer needed for this recovery


ORA-00283: recovery session canceled due to errors
ORA-00600: internal error code, arguments: [3020], [4242465], [1], [9], [314], [272], [], []
ORA-10567: Redo is inconsistent with data block (file# 1, block# 48161)
ORA-10564: tablespace SYSTEM
ORA-01110: data file 1: '/opt/oracle/oradata/conner/system01.dbf'
ORA-10560: block type 'DATA SEGMENT HEADER - UNLIMITED'


ORA-01112: media recovery not started

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 240620949 generated at 06/10/2005 10:45:44 needed for thread 1
ORA-00289: suggestion : /opt/oracle/oradata/conner/archive/1_9.dbf
ORA-00280: change 240620949 for thread 1 is in sequence #9


Specify log: {=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs;

Database altered.

SQL> select name from v$datafile;

NAME
------------------------------------------------------------
/opt/oracle/oradata/conner/system01.dbf
/opt/oracle/oradata/conner/undotbs01.dbf
/opt/oracle/oradata/conner/users01.dbf

SQL>

Saturday, January 10, 2009

利用dbms_backup_restore包手工进行数据库恢复收藏

利用dbms_backup_restore包手工进行数据库恢复收藏
http://blog.csdn.net/withhl/archive/2004/10/11/131946.aspx
新一篇: RSS实际应用 | 旧一篇: recovery window理解

情景描述:
数据运行在归档模式下,用RMAN备份数据,除最后一次RMAN FULL全备份外(全备份包含控制文件备份,但不是Controlfile Autobackup),所有数据文件、控制文件全部丢失,数据库无法启动。
恢复情况:
dbms_backup_restore包是Oracle服务器和操作系统之间IO操作接口,正常情况下有RMAN直接调用进行数据恢复。由此可见我们可以在操作系统级直接调用这个包来进行数据恢复。
在次用到的procedure介绍,具体详细情况可以参考$oracle_home/rdbms/admin/dbmsbkrs.sql和prvtbkrs.plb脚本注释说明
FUNCTION  deviceAllocate(
       type IN varchar2 default NULL
      ,name IN varchar2 default NULL
      ,ident IN varchar2 default NULL
      ,noio IN boolean default FALSE
      ,params IN varchar2 default NULL )
RETURN varchar2;

-- Describe the device to be used for sequential I/O. For device types where
-- only one process at a time can use a device, this call allocates a device
-- for exclusive use by this session. The device remains allocated until
-- deviceDeallocate is called or session termination. The device can be used
-- both for creating and restoring backups.
--
-- Specifying a device allocates a context that exists until the session
-- terminates or deviceDeallocate is called. Only one device can be specified
-- at a time for a particular session. Thus deviceDeallocate must be called
-- before a different device can be specified. This is not a limitation since
-- a session can only read or write one backup at a time.
--
-- The other major effect of allocating a device is to specify the name space
-- for the backup handles (file names). The handle for a sequential file does
-- not necessarily define the type of device used to write the file. Thus it
-- is necessary to specify the device type in order to interpret the file
-- handle. The NULL device type is defined for all systems. It is the file
-- system supplied by the operating system. The sequential file handles are
-- thus normal file names.
--
-- A device can be specified either by name or by type.
-- If the type is specified but not the name, the system picks an
-- available device of that type.
-- If the name is specified but not the type, the type is determined
-- from the device.
-- If neither the type or the name is given, the backups are files in
-- the operating system file system.

-- Note that some types of devices, optical disks for example, can be shared
-- by many processes, and thus do not really require allocation of the device
-- itself. However we do need to allocate the context for accessing the
-- device, and we do need to know the device type for proper interpretation
-- of the file handle. Thus it is always necessary to make the device
-- allocation call before making most other calls in this package.
--
-- Input parameters:
-- type
-- If specified, this gives the type of device to use for sequential
-- I/O. The allowed types are port specific. For example a port may
-- support the type "TAPE" which is implemented via the Oracle tape
-- API. If no type is specified, it may be implied by specifying a
-- particular device name to allocate. The type should be allowed to
-- default to NULL if operating system files are to be used.
--
-- name
-- If specified, this names a particular piece of hardware to use for
-- accessing sequential files. If not specified, any available
-- device of the correct type will be allocated. If the device cannot
-- be shared, it is allocated to this session for exclusive use.
-- The name should be allowed to default to NULL if operating system
-- files are to be used.
--
-- ident
-- This is the users identifier that he uses to name this device. It
-- is only used to report the status of this session via
-- dbms_application_info. This value will be placed in the CLIENT_INFO
-- column of the V$SESSION table, in the row corresponding to the
-- session in which the device was allocated. This value can also
-- be queried with the dbms_application_info.read_client_info procedure.
--
-- noio
-- If TRUE, the device will not be used for doing any I/O. This allows
-- the specification of a device type for deleting sequential files
-- without actually allocating a piece of hardware. An allocation for
-- noio can also be used for issuing device commands. Note that some
-- commands may actually require a physical device and thus will get
-- an error if the allocate was done with noio set to TRUE.
--
-- params
-- This string is simply passed to the device allocate OSD. It is
-- completely port and device specific.
--
-- Returns:
-- It returns a valid device type. This is the type that should be
-- allocated to access the same sequential files at a later date. Note
-- that this might not be exactly the same value as the input string.
-- The allocate OSD may do some translation of the type passed in. The
-- return value is NULL when using operating system files.


PROCEDURE restoreControlfileTo(cfname IN varchar2);

-- This copies the controlfile from the backup set to an operating system
-- file. If the database is mounted, the name must NOT match any of the
-- current controlfiles.
--
-- Input parameters:
-- cfname
-- Name of file to create or overwrite with the controlfile from the
-- backup set.

PROCEDURE restoreDataFileTo( dfnumber IN binary_integer
,toname IN varchar2 default NULL);
--
-- restoreDataFileTo creates the output file from a complete backup in the
-- backup set.
具体操作情况如下:
1、手工恢复控制文件
SQL> startup nomount;
ORACLE 例程已经启动。
SQL> declare
2 devtype varchar2(256);
3 done boolean;
4 begin
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
6 sys.dbms_backup_restore.restoresetdatafile;
7 sys.dbms_backup_restore.restorecontrolfileto(cfname=>'c:\oracle\oradata\tes
tdb\control01.ctf');
8 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'d:\databak\A
CT_TESTDB_13G292QT_35',params=>null);
9 sys.dbms_backup_restore.devicedeallocate;
10 end;
11 /

PL/SQL 过程已成功完成。

SQL> alter database mount;

数据库已更改。
2、手工恢复数据文件
SQL> declare
2 devtype varchar2(256);
3 done boolean;
4 begin
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
6 sys.dbms_backup_restore.restoresetdatafile;
7 sys.dbms_backup_restore.restoredatafileto(dfnumber=>01,toname=>'C:\ORACLE\O
RADATA\TESTDB\SYSTEM01.DBF');
8 sys.dbms_backup_restore.restoredatafileto(dfnumber=>02,toname=>'C:\ORACLE\O
RADATA\TESTDB\UNDOTBS01.DBF');
9 sys.dbms_backup_restore.restoredatafileto(dfnumber=>03,toname=>'C:\ORACLE\O
RADATA\TESTDB\INDX01.DBF');
10 sys.dbms_backup_restore.restoredatafileto(dfnumber=>05,toname=>'C:\ORACLE\O
RADATA\TESTDB\USERS01.DBF');
11 sys.dbms_backup_restore.restoredatafileto(dfnumber=>04,toname=>'C:\ORACLE\O
RADATA\TESTDB\TOOLS01.DBF');
12 sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'d:\databak\A
CT_TESTDB_13G292QT_35',params=>null);
13 sys.dbms_backup_restore.devicedeallocate;
14 end;
15 /

PL/SQL 过程已成功完成。

3、手工恢复归档日志文件
SQL> DECLARE
2 devtype varchar2(256);
3 done boolean;
4 BEGIN
5 devtype:=sys.dbms_backup_restore.deviceAllocate(type=>'',ident=>'T1');
6 sys.dbms_backup_restore.restoreSetArchivedLog;
7 sys.dbms_backup_restore.restoreArchivedLogRange;
8 sys.dbms_backup_restore.restoreBackupPiece(done=>done,handle=>'D:\DATABAK\
LOG_T539265984_S36_P1', params=>null);
9 sys.dbms_backup_restore.deviceDeallocate;
10 end;
11 /

PL/SQL 过程已成功完成。

SQL> recover database until time '2004-10-11 12:04:45' using backup controlfile
ORA-00279: 更改 77996 (在 10/11/2004 12:04:45 生成) 对于线程 1 是必需的


指定日志: {=suggested | filename | AUTO | CANCEL}
C:\oracle\arch\1_1.DBF
已应用的日志。
完成介质恢复。
SQL> ALTER DATABASE OPEN RESETLOGS;

数据库已更改。

oracle rman备份命令-备份恢复

oracle rman备份命令-备份恢复
http://www.stuchina.net/hy/ce/200811/129361.html
文章来源:转载 点击数:44 更新时间:2008-11-11 3:36:23 

  RMAN简单使用

  目标机A:

  create tablespace RMAN datafile '$ORACLE_HOME/oradata/FILENAME.DBF' size 20M;

  RMAN简单使用

  目标机A:

create tablespace RMAN datafile '$ORACLE_HOME/oradata/FILENAME.DBF' size 20M;
create username RMAN identified by RMAN default tablespace rman temporary tablespace temp quota unlimited on RMAN;
  
grant recovery_catalog_owner to rman ;
rman catalog rman/rman
create catalog tablespace 'RMAN';

  Rman主机B:

  rman target /

  connect catalog rman/rman@$A_SID

  注册数据库

  register database;

  注销数据库

sqlplus rman/rman
select * from db;
EXECUTE dbms_rcvcat.unregisterdatabase(db_key, db_id);

  ///////////非归档模式使用RMAN备份///////////////////////

  备份目标数据库:

  rman target /

  connect catalog rman/rman@$A_SID

  定义通道

  allocate channel c1 type disk;

  撤消通道

  release channel c1;

  备份整个数据库

run {
allocate channel c1 type disk;
backup full tag full_db_backup
format '/export/home/oracle/oradata/bak_db/db_%d' database
include current controlfile;
release channel c1;
}

  备份表空间

run {
allocate channel d1 type disk;
backup tag tbs_users_read_only
format '/export/home/oracle/oradata/bak_tab/block_t%t_s%s' (tablespace "BLOCK");
release channel c1;
}
  
run {
allocate channel d1 type disk;
backup tablespace "BLOCK" filesperset 3 format '/export/home/oracle/oradata/bak_tab/aatst_%d%t%s.%p'
include current controlfile;
release channel c1;
}

  备份单独数据文件

run {
allocate channel c1 type disk;
backup format '/export/home/oracle/oradata/bak_tab/%d_%u'
(datafile '/export/home/oracle/oradata/ECOM/block01.dbf');
release channel c1;
}

  复制目标数据库数据文件:

run {
allocate channel c1 type disk;
copy datafile '/export/home/oracle/oradata/ECOM/block02.dbf' to '/export/home/oracle/oradata/bak_tab/block02.dbf' tag=u1215;
release channel c1;
}

  备份控制文件:

run {
allocate channel c1 type disk;
backup format '/export/home/oracle/oradata/bak_cont/cf_t%t_s%s_p%p'
tag cf_monday_night (current controlfile);
release channel c1;
}
  
run {
allocate channel d1 type disk;
backup current controlfile format '/export/home/oracle/oradata/bak_tab/%d%t%s.ctl';
}
run {
allocate channel d1 type disk;
copy current controlfile to '/export/home/oracle/oradata/bak_tab/%d%t%s.ctl';
}

  /////////////////////归档模式使用RMAN备份//////////////////////

  归档日志备份:

run {
allocate channel c1 type disk;
backup format '/export/home/oracle/oradata/bak_log/log_t%t_s%s_p%p'
(archivelog all);
release channel c1;
}

  下面的脚本归档日志从# 90 to 100:

run {
allocate channel c1 typye disk;
backup format '/export/home/oracle/oradata/bak_log/log_t%t_s%s_p%p'
(archivelog from logseq=90 until logseq=100 thread 1);
release channel c1;
}

  下面的脚本备份在24小时内产生的归档日志,在备份完成后会自动删除归档日志。如果备份失败,归档日志不会被删除。

run {
allocate channel c1 type disk;
backup format '/export/home/oracle/oradata/bak_log/log_t%t_s%s_p%p'
(archivelog from time 'sysdate-1' all delete input);
release channel c1;
}
  
run {
allocate channel c1 type disk;
backup archivelog low logseq 1143 high logseq 1147 thread 1 format 'aaarc%t.%s';
}

  使用下面的命令显示恢复目录中的归档日志

  list backupset of archivelog all;

  备份联机日志

run {
allocate channel c1 type disk;
sql "alter system archive log current";
backup format '/export/home/oracle/oradata/bak_log/onlog_t%t_s%s_p%p'
(archivelog from time 'sysdate-1' all delete input);
release channel c1;
}

  备份spfile

run {
allocate channel c1 type disk;
backup spfile tag 'ECOM_spfile' format '/export/home/oracle/oradata/bak_conf/spfile_%t.ora';
release channel c1;
}

  清除联机日志备份

  delete copy;

  /* 如果物理文件被删除,用CROSSCHECK修复 */

  crosscheck archivelog all;

  delete noprompt obsolete;

  列出对应物

  list incarnation;

  概述可用的备份

  list backup summary;

  按备份类型列出备份

  list backup by file;

  列出详细备份

  list backup;

  列出过期备份

  list expired backup;

  列出表空间和数据文件备份

  list backup of tablespace ;

  list backup of datafile;

  列出归档日志备份

  list archivelog all;

  list backup of archivelog all;

  列出控制文件和服务器参数文件

  list backup of controfile;

  list backup of spfile;

  检查备份

crosscheck backup;
crosscheck backup of database;
crosscheck backup of tablespace system;
crosscheck backup of controlfile;
crosscheck backup of spfile;

  删除备份

allocate channel for delete type disk;
change backupset BS Key delete;
delete obsolete; 删除陈旧备份
delete expired backup;
delete backupset id;
delete backup; -- 删除所有备份 网管下载dl.bitscn.com

  改变备份集的状态

  change backupset id unavailable; -- available

  改为长期备份

change backupset id keep forever logs;
change backupset id keep until time 'sysdate+60' logs;
change backupset id nokeep;

  网管u家bitscn.net

  报告丢弃的备份

  report obsolete;

  删除丢弃状态的备份

  delete obsolete;

  RMAN的crosscheck 命令

  1 备份集有两种状态A(Available,RMAN认为该项存在于备份介质上)X(Expired,备份存在于控制文件或恢复目录中,但是并没有物理存在于备份介质上)

  2 crosscheck 的目的是检查RMAN 的目录以及物理文件,如果物理文件不存在于介质上,将标记为Expired。如果物理文件存在,将维持Available。如果原先标记为Expired 的备份集再次存在于备份介质上(如恢复了损坏的磁盘驱动器后),crosscheck将把状态重新从Expired标记回Available。

  3 crosscheck 输出分两部分。第一部分列出确定存在于备份介质上的所有备份集片,第二部分列出不存在于备份介质上的备份集片,并将其标记为Expired。当设置备份保存策略后,一个备份过期,crosscheck之后标记为丢弃的备份状态依旧为availabel,要删除丢弃备份delete obsolete。

  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;

  概述可用的备份

  list backup summary;

  得到了备份集得主键ID如40

  validate backupset 40;

  命令删除备份集

change backupset ID1,ID2,ID3 delete;
change backuppiece ID1 delete;
change archivelog until logseq=ID1 delete;

  要查看标记为丢弃的备份

  report obsolete;

  只有使用

  delete obsolete才真正物理删除。

  手工同步恢复目录

  resync catalog;

  --查看RMAN的信息

  list backup

  --列出过期备份

  report obsolete;

  --删除过期的备份

  allocate channel for maintenance type disk;

  --allocate channel for delete type disk;

  change datafilecopy 44 delete;

  release channel;

  --如果目标数据库物理对象发生了变化,如添加了一个数据文件,需要用如下命令同步

  resync catalog;

  --如果目标数据库reset了数据库,需要用如下命令同步

  reset database;

  --当手工删除了数据库的归档文件后,要执行以下脚本同步

  allocate channel for maintenance type disk;

  --allocate channel for delete type disk;

  change archivelog all crosscheck;

  release channel;

  --当手工删除了数据库的RMAN备份后,要执行以下脚本来同步

allocate channel for maintenance type disk;
crosscheck backup;
delete expire backup;
release channel;

  /////////////////增量备份//////////////

  Level 0 是增量备份策略的基础

run {
allocate channel c1 type disk;
backup incremental level 0 filesperset 4 format '/export/home/oracle/oradata/bak_db/sunday_level0_%t'
(database);
release channel c1;
}

  ==================Recovery 恢复==================

  0.恢复控制文件(以前必须有过控制文件的备份)

  startup nomount

  rman target/

  connect catalog rman/rman

  (数据库在nomount的时候才能set DBID)

  set DBID=3287725908 

  1.Datafile recovery 数据文件恢复

run {
allocate channel c1 type disk;
sql "alter tablespace TB_name offline immediate";
restore datafile 4;
recover datafile 4;
sql "alter tablespace TB_name online";
release channel c1;
}

  2.Tablespace recovery 表空间恢复

run {
allocate channel c1 type disk;
sql "alter tablespace TB_name offline immediate";
restore tablespace TB_name;
recover tablespace TB_name;
sql "alter tablespace TB_name online";
release channel c1;
}

  如果还原系统表空间文件,数据库必须关闭,因为系统表空间不可以脱机

  =======完全还原(丢失联机日志)并且前滚 - 数据库关闭=======

run {
allocate channel c1 type disk;
set until logseq=105 thread=1;
restore controlfile to '/export/home/oracle/oradata/ECOM/control01.ctl'
replicate controlfile from '/export/home/oracle/oradata/bak_cont/ctrltargdb.ctl' ;
restore database;
sql "alter database mount";
recover database;
sql "alter database open resetlogs";
release channel c1;
}

  'set until' 命令指明恢复到指定的日志文件。这一点在数据文件恢复时很重要,否则RMAN将试图恢复最近的数据文件,该数据文件可能在指定的日志以前。

  'replicate controlfile' 复制还原的控制文件到INIT.ORA指定的控制文件。

  如果数据库使用WITH RESETLOGS打开,则需要使用RESET DATABASE命令注册改变后的数据库。在使用RESETLOGS命令打开数据库后强烈建议做一个完全的数据库备份。

  还原数据文件的子集,完全恢复

run {
allocate channel c1 type disk;
sql "alter database mount";
restore datafile 2;
restore datafile 3;
restore archivelog all;
recover database;
sql "alter database open";
release channel c1;
}

  恢复表空间

  startup mount

  run { allocate channel c1 type disk ; restore tablespace 'TB_NAME';recover tablespace 'TB_NAME';}

  或者

run { allocate channel c1 type disk ; restore database ;recover database ;}
sqlplus /nolog
alter database open;

  脚本

create script alloc_disk {
Allocates one disk
allocate channel c1 type disk;
setlimit channel c1 kbytes 2097150 maxopenfiles 32 readrate 200;
}
replace script rel_disk {
releases disk
release channel c1;
}
replace script backup_db_full {
execute script alloc_disk;
backup
.....
execute script rel_disk;
}

  前两个脚本分别用来分配和回收通道。

  alloc_disk 脚本还额外指定了备份片的最大兆字节数,备份时可以同时打开的输入文件的最大数目,以及每秒钟读每个输入文件的数据缓冲区的最大数目。

  第三个脚本调用先前存储的两个脚本进行数据库备份。

  运行存储脚本的示范:

run {
execute script backup_db_full;
}

  查看备份及复制的信息

  list backup;

  list copy;

  在备份是设置相关参数

  format --文件输出格式,

%d--database name, (SID)
%t--tablespace name,
%s--backup sets sequence number,
%p--backup pieces sequence number

  脚本

create script alloc_disk {
Allocates one disk
allocate channel c1 type disk;
setlimit channel c1 kbytes 2097150 maxopenfiles 32 readrate 200;
}
replace script rel_disk {
releases disk
release channel c1;
}
replace script backup_db_full {
execute script alloc_disk;
backup
.....
execute script rel_disk;
}

  前两个脚本分别用来分配和回收通道。

  alloc_disk 脚本还额外指定了备份片的最大兆字节数,备份时可以同时打开的输入文件的最大数目,以及每秒钟读每个输入文件的数据缓冲区的最大数目。

  第三个脚本调用先前存储的两个脚本进行数据库备份。

  运行存储脚本的示范:

run {
execute script backup_db_full;
}

Wednesday, January 7, 2009

RMANでArchivelogの削除

http://www.ostl.net/2007/02/post_16.html

アーカイブログモードだとたまりすぎるとDBが停止する。
アーカイブログが多くなりすぎてバックアップとれなーいというときにRMANにて実行する。

rman target / nocatalog

七日前までを削除
delete archivelog until time 'sysdate-7';
(RMANで実行)

全削除
delete archivelog all ;
(RMANで実行)

アーカイブログのスレッド番号がわかっている場合
delete archivelog until sequence 100 thread 2;

スレット番号の確認する場合
list backup of archivelog all;
(RMANで実行)

参考 制御ファイルの番号を確認する。
SQL> select thread#,sequence#,name from v$archived_log order by thread#,sequence#


さらに困った場合
rmで消しちゃった場合
change archivelog all crosscheck;

データベース全体でやめる場合とはじめる場合
(9までは停止が必要だったようだ。 確認中)
alter system archive log stop;
alter system archive log start;

日付指定で削除する。
RMAN> delete archivelog until time 'sysdate-7';

チャネル: ORA_DISK_1がリリースされました
チャネル: ORA_DISK_1が割り当てられました
チャネルORA_DISK_1: SID=490 インスタンス=oracle devtype=DISK

アーカイブ・ログ・コピーのリスト
Key Thrd Seq S Low時間 Name
------- ---- ------- - -------- ----
1148 1 765 A 07-01-23 +DG2/oracle/1_765_600370988.dbf
ずらずらずら、、、、、、
1228 2 381 A 07-01-27 +DG2/oracle/2_381_600370988.dbf

このオブジェクトを削除しますか(YESまたはNOを入力してください)。 yes
アーカイブ・ログを削除しました
アーカイブ・ログ・ファイル名=+DG2/oracle/1_765_600370988.dbf レコードID=1148 スタンプ=612619531
アーカイブ・ログを削除しました
アーカイブ・ログ・ファイル名=+DG2/oracle/1_766_600370988.dbf レコードID=1149 スタンプ=612630137
アーカイブ・ログを削除しました
---ずらずらずら----------------
81オブジェクトを削除しました

Tuesday, August 12, 2008

Simplest RMAN Backup and Recovery


CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
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 CHANNEL DEVICE TYPE DISK FORMAT 'C:\oracle\orabackup\orcl10\%d_%u_%s_%p';
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 'C:\ORACLE\PRODUCT\10.2.0\DB_1\DATABASE\SNCFORCL10.ORA'; # default


backup database plus archivelog delete input;

sql 'shutdown immediate';
sql 'startup nomount';
restore database;
recover database;
sql 'alter database';
# sql 'alter database open resetlogs';