2008/05/08
备份&恢复之九:RMAN备份下的基于改变的恢复
测试环境:
1 操作系统:Redhat Linux 5
[oracle@mzl proc]$ cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007
2 数据库版本:Oracle10g
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
3 设置成归档模式.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Current log sequence 18
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Next log sequence to archive 18
Current log sequence 18
SQL>
4 创建表插入数据
SQL> drop table test;
Table dropped.
SQL> create table test(a int) tablespace users;
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
5 查看表test在哪个表空间
SQL> select table_name,tablespace_name from dba_tables
2 where table_name='TEST';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TEST USERS
在users表空间内
6 备份数据库
[oracle@mzl BackupDatabase]$ pwd
/home/mzl/BackupDatabase
[oracle@mzl BackupDatabase]$ vi backup.rcv
# script.:bakup.rcv
# creater:mengzhaoliang
# date:7.5.2008
# desc:backup all database datafile in archive with rman
# connect database
export ORACLE_SID=ORCL
export PATH=/u01/app/oracle/product/10.2.0/db_1/bin
rman target/ << EOF_RMAN
run{
allocate channel c1 type disk;
backup full tag 'dbfull' format '/home/mzl/BackupDatabase/full_%u_%s_%p' database
include current controlfile;
sql 'alter system archive log current';
release channel c1;
}
# end
赋予权限,执行脚本
[oracle@mzl BackupDatabase]$ chmod +x backup.rcv
[oracle@mzl BackupDatabase]$ ./backup.rcv
7 删除测试表,在删除之前,便于测试,继续插入数据并应用到归档,并获取删除前的scn号。
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
2
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> l
1* select max(ktuxescnw * power(2,32)+ktuxescnb) scn from x$ktuxe
SQL> /
SCN
----------
1174342
SQL> drop table test;
Table dropped.
8 准备恢复到SCN 1174342,先关闭数据库,然后启动到mount下
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
9 启动数据库到mount状态下
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
11 开始恢复到改变点SCN 1174342
[oracle@mzl BackupDatabase]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 8 14:40:15 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1172558471, not open)
RMAN> run{
2> allocate channel c1 type disk;
3> restore database;
4> recover database until scn 1174342;
5> sql 'alter database open resetlogs';
6> release channel c1;
7> }
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=156 devtype=DISK
Starting restore at 08-MAY-08
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/orcl/perfstat.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/orcl/risenet.dbf
channel c1: reading from backup piece /home/mzl/BackupDatabase/full_0bjfs634_11_1
channel c1: restored backup piece 1
piece handle=/home/mzl/BackupDatabase/full_0bjfs634_11_1 tag=DBFULL
channel c1: restore complete, elapsed time: 00:01:26
Finished restore at 08-MAY-08
Starting recover at 08-MAY-08
starting media recovery
archive log thread 1 sequence 12 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_12_4257lm5v_.arc
archive log thread 1 sequence 13 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_13_4257skqg_.arc
archive log thread 1 sequence 14 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_14_4257swpv_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_12_4257lm5v_.arc thread=1 sequence=12
media recovery complete, elapsed time: 00:00:02
Finished recover at 08-MAY-08
sql statement: alter database open resetlogs
released channel: c1
12 检查数据
SQL> select * from test;
A
---------------------------------------
1
2
说明:
1、RMAN也可以实现不完全恢复,方法比OS备份恢复的方法更简单可靠
2、RMAN可以基于时间,基于改变与基于日志序列的不完全恢复,基于日志序列的恢复可以指定恢复到哪个日志序列,如
run {
allocate channel ch1 type disk;
allocate channel ch2 type 'sbt_tape';
set until logseq 1234 thread 1;
restore controlfile to '$ORACLE_HOME/dbs/cf1.f' ;
replicate controlfile from '$ORACLE_HOME/dbs/cf1.f';
alter database mount;
restore database;
recover database;
sql "ALTER DATABASE OPEN RESETLOGS";
}
3、与所有的不完全恢复一样,必须在mount下,restore所有备份数据文件,需要resetlogs
4、基于改变的恢复比基于时间的恢复更可靠,但是可能也更复杂,需要知道需要恢复到哪一个改变号(SCN),在正常生产中,获取SCN的办法其实也有很多,如查询数据库字典表(V$archived_log or v$log_history),或分析归档与联机日志(logmnr)等。
参考itpub上piner的备份与恢复案例:
http://www.itpub.net/viewthread.php?tid=126320&extra=page%3D4%26amp%3Bfilter%3Ddigest
在服务器测试成功
备份&恢复之九:RMAN备份下的基于改变的恢复
测试环境:
1 操作系统:Redhat Linux 5
[oracle@mzl proc]$ cat /proc/version
Linux version 2.6.18-8.el5 (brewbuilder@ls20-bc2-14.build.redhat.com) (gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)) #1 SMP Fri Jan 26 14:15:21 EST 2007
2 数据库版本:Oracle10g
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
3 设置成归档模式.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Current log sequence 18
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 16
Next log sequence to archive 18
Current log sequence 18
SQL>
4 创建表插入数据
SQL> drop table test;
Table dropped.
SQL> create table test(a int) tablespace users;
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
5 查看表test在哪个表空间
SQL> select table_name,tablespace_name from dba_tables
2 where table_name='TEST';
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
TEST USERS
在users表空间内
6 备份数据库
[oracle@mzl BackupDatabase]$ pwd
/home/mzl/BackupDatabase
[oracle@mzl BackupDatabase]$ vi backup.rcv
# script.:bakup.rcv
# creater:mengzhaoliang
# date:7.5.2008
# desc:backup all database datafile in archive with rman
# connect database
export ORACLE_SID=ORCL
export PATH=/u01/app/oracle/product/10.2.0/db_1/bin
rman target/ << EOF_RMAN
run{
allocate channel c1 type disk;
backup full tag 'dbfull' format '/home/mzl/BackupDatabase/full_%u_%s_%p' database
include current controlfile;
sql 'alter system archive log current';
release channel c1;
}
# end
赋予权限,执行脚本
[oracle@mzl BackupDatabase]$ chmod +x backup.rcv
[oracle@mzl BackupDatabase]$ ./backup.rcv
7 删除测试表,在删除之前,便于测试,继续插入数据并应用到归档,并获取删除前的scn号。
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
A
----------
1
2
SQL> alter system switch logfile;
System altered.
SQL> alter system switch logfile;
System altered.
SQL> l
1* select max(ktuxescnw * power(2,32)+ktuxescnb) scn from x$ktuxe
SQL> /
SCN
----------
1174342
SQL> drop table test;
Table dropped.
8 准备恢复到SCN 1174342,先关闭数据库,然后启动到mount下
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
9 启动数据库到mount状态下
SQL> startup mount
ORACLE instance started.
Total System Global Area 268435456 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 7168000 bytes
Database mounted.
11 开始恢复到改变点SCN 1174342
[oracle@mzl BackupDatabase]$ rman target/
Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 8 14:40:15 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORCL (DBID=1172558471, not open)
RMAN> run{
2> allocate channel c1 type disk;
3> restore database;
4> recover database until scn 1174342;
5> sql 'alter database open resetlogs';
6> release channel c1;
7> }
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=156 devtype=DISK
Starting restore at 08-MAY-08
channel c1: starting datafile backupset restore
channel c1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /u01/app/oracle/oradata/orcl/system01.dbf
restoring datafile 00002 to /u01/app/oracle/oradata/orcl/undotbs01.dbf
restoring datafile 00003 to /u01/app/oracle/oradata/orcl/sysaux01.dbf
restoring datafile 00004 to /u01/app/oracle/oradata/orcl/users01.dbf
restoring datafile 00005 to /u01/app/oracle/oradata/orcl/example01.dbf
restoring datafile 00006 to /u01/app/oracle/oradata/orcl/perfstat.dbf
restoring datafile 00007 to /u01/app/oracle/oradata/orcl/risenet.dbf
channel c1: reading from backup piece /home/mzl/BackupDatabase/full_0bjfs634_11_1
channel c1: restored backup piece 1
piece handle=/home/mzl/BackupDatabase/full_0bjfs634_11_1 tag=DBFULL
channel c1: restore complete, elapsed time: 00:01:26
Finished restore at 08-MAY-08
Starting recover at 08-MAY-08
starting media recovery
archive log thread 1 sequence 12 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_12_4257lm5v_.arc
archive log thread 1 sequence 13 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_13_4257skqg_.arc
archive log thread 1 sequence 14 is already on disk as file /u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_14_4257swpv_.arc
archive log filename=/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2008_05_08/o1_mf_1_12_4257lm5v_.arc thread=1 sequence=12
media recovery complete, elapsed time: 00:00:02
Finished recover at 08-MAY-08
sql statement: alter database open resetlogs
released channel: c1
12 检查数据
SQL> select * from test;
A
---------------------------------------
1
2
说明:
1、RMAN也可以实现不完全恢复,方法比OS备份恢复的方法更简单可靠
2、RMAN可以基于时间,基于改变与基于日志序列的不完全恢复,基于日志序列的恢复可以指定恢复到哪个日志序列,如
run {
allocate channel ch1 type disk;
allocate channel ch2 type 'sbt_tape';
set until logseq 1234 thread 1;
restore controlfile to '$ORACLE_HOME/dbs/cf1.f' ;
replicate controlfile from '$ORACLE_HOME/dbs/cf1.f';
alter database mount;
restore database;
recover database;
sql "ALTER DATABASE OPEN RESETLOGS";
}
3、与所有的不完全恢复一样,必须在mount下,restore所有备份数据文件,需要resetlogs
4、基于改变的恢复比基于时间的恢复更可靠,但是可能也更复杂,需要知道需要恢复到哪一个改变号(SCN),在正常生产中,获取SCN的办法其实也有很多,如查询数据库字典表(V$archived_log or v$log_history),或分析归档与联机日志(logmnr)等。
参考itpub上piner的备份与恢复案例:
http://www.itpub.net/viewthread.php?tid=126320&extra=page%3D4%26amp%3Bfilter%3Ddigest
在服务器测试成功
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12778571/viewspace-263299/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12778571/viewspace-263299/