show all;
显示rman的默认设置
列出数据库还有那些数据文件需要做备份:
report need backup;
1.已废弃的备份和副本报表(也就是没有用的备份集,是根据rman的冗余来显示的)
report obsolete;
2.显示备份集列表
list backup;
删除过期的备份集
delete backupset n;
如果操作系统中的文件已经删了,而备份信息还在,那么先做crosscheck,然后再delete expired 就可以清除这些不正确的备份信息
crosscheck backuppiece 8;
然后delete backuppiece 8;
物理删除了归档日志,在使用rman 进行备份归档日志的时候出现归档日志不存在
change archivelog all crosscheck;
crosscheck archivelog all;
delete expired archivelog all;
3.恢复spfile
restore spfile to pfile 'e:\rmanbk\pfile.ora' from autobackup;
4.恢复控制文件:
RMAN> restore controlfile from 'e:\rmanbk\CF_ORA9_20_1_573229179_20051101';
RMAN> run {
2> restore controlfile to 'e:\rmanbk\controlfilebak.ora' from autobackup;(因为是恢复的是控制文件,所以必须要指定从备份的控制文件中恢复)
3> replicate controlfile from 'e:\rmanbk\controlfilebak.ora';
4> }
5.rman备份的命令格式:
1).分配通道(allocate channel c1 type disk)
2).backup 备份和备份的类型(incremental level=0,1,2,3,4)
3).tag 可以增加个性化的标签
4).format 备份集的路径和命令格式
5).备份的内容(database...),(tablespace tools,system....),(archivelog all delete input)
6.对数据库做一次全备份:
run {
allocate channel c1 type disk;
backup incremental level=0
format 'e:\rmanbk\%d_%p_%t'
(database);
}
run {
allocate channel c1 type disk;
backup full
format 'e:\rmanbk\%d_%p_%t'
(database);
}
7.备份归档日志:
run {
allocate channel c1 type disk;
backup format 'e:\rmanbk\archlog_%d_%p_%t'
(archivelog all);
}
7.备份归档日志(备份之后删除归档日志):
run {
allocate channel c1 type disk;
backup
tag 'ora9_archivelog_2004_11_16'
format 'e:\rmanbk\archlog_%d_%p_%t'
(archivelog all delete input);
}
查询那些数据库文件需要进行恢复(在恢复数据文件的时候需要)
select * from v$revocer_file;
select a.name,b.error from v$dbfile a,v$recover_file b where a.file#=b.file#;
恢复整个数据库(也可以使用它恢复数据库中需要恢复的文件)
run {
allocate channel c1 type disk;
restore database;
recover database;
}
恢复某个丢失的数据文件:
run {
allocate channel c1 type disk;
restore datafile 10;
recover datafile 10;
sql "alter database datafile 10 online";
}
恢复某个丢失的数据表空间:
run {
allocate channel c1 type disk;
restore tablespace test;
recover tablespace test;
sql "alter tablespace test online";
}
不完全恢复包括基于时间点、基于SCN、基于Log Sequence的恢复
基于系统变更号的不完全恢复
run {
allocate channel c1 type disk;
set until scn 123456;
restore database;
recover database;
sql "alter database open resetlogs";
}
基于时间不完全恢复
run {
allocate channel c1 type disk;
set until time "TO_DATE('2004-11-22 16:10:54','yyyy-mm-dd hh24:mi:ss')";
restore database;
recover database;
sql "alter database open resetlogs";
}
做基于时间点的恢复
RMAN> run
2> {allocate channel d1 type disk;
3> restore database until time '2005-03-30 16:13:54';
4> recover database;
5> release channel d1;
6> }
基于日志序列的不完全恢复
run {
allocate channel c1 type disk;
set until logseq=4 thread=1;
restore database;
recover database;
sql "alter database open resetlogs";
}
recover database until cancel
recover database until time '2004-03-21:22:59:04'
recover database until change 123456
Rem 对数据文件和表空间的不完全恢复属于Tablespace point-in-time recovery需要auxiliary database
recover datafile 'filename' until cancel
recover datafile 'filename' until time '2004-03-21:22:59:04'
recover datafile 'filename' until change 123456
recover tablespace ts_name until cancel
recover tablespace ts_name until time '2004-03-21:22:59:04'
recover tablespace ts_name until change 123456
recover database using backup controlfile
Rem 设置默认的rman备份的备份集和备份文件的路径:
rman>configure channel device type disk format “e:rman%t%U.bak”;
rman>backup database plus archivelog;(备份整个数据库和归档日志)
RMAN>restore controlfile from autobackup;(从自动控制文件备份中恢复控制文件)
Rem 备份数据库的SUN unix下的脚本
#!/bin/ksh
#This is the Solaris version
ORACLE_HOME=/export/home/oracle/OraHome
export ORACLE_HOME
PATH=$PATH:$HOME/bin
export PATH=$PATH:/usr/ccs/bin:/usr/bin:/etc/:/usr/sbin:/usr/ucb:/usr/local/bin:$ORACLE_HOME/bin:/usr/bin/X11:/sbin
$ORACLE_HOME/bin/rman target sys/password@sxit<<EOF
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag 'dbfull' format '/data/RmanAutoBak/FullBak/full_%U' database include current controlfile;
sql 'alter system archive log current';
release channel c1;
release channel c2;
release channel c3;
}
exit;
EOF
$ORACLE_HOME/bin/rman <<EOF
connect target /
delete noprompt obsolete;
exit;
EOF
Rem 删除废弃的备份(包括rman备备份文件和恢复不需要的归档日志文件
b. To report and remove obsolete backups based on the configured retention policy
a. report obsolete;
b. delete obsolete; # requires confirmation to delete backups
c. delete noprompt obsolete; # noprompt removes the obsolete backups without confirmation
d. report schema; # to view the current target database schema
B、删除所有备份。
RMAN> delete backup;
A、做0级备份
run
{allocate channel d1 type disk maxpiecesize=128m;
backup incremental level 0 database
format 'e:\rmanbk\db_%d_%s_%p_%t_%T';
release channel d1;
}
B、查看已经归档的日志
RMAN> list archivelog all;
C、删除归档日志
RMAN> delete archivelog all;
不完全恢复(在日志不够的情况下进行不完全恢复)
recover database until cancel;(控制文件是最新的)
recover database using backup controlfile;
Rem 备份归档日志
run {
allocate channel c1 type disk;
backup format 'e:\rmanbk\archlog_%d_%p_%t'
(archivelog all delete input);
}
Rem 恢复归档日志
set archivelog destination to 'E:\oracle\ora81\RDBMS';
allocate channel c1 type disk;
restore archivelog all;
release channel c1;
Rem 一致备份记录与实际的 备份
CROSSCHECK BACKUP;
CROSSCHECK COPY;
Oracle9i开始Rman提供plus archivelog选项,极大的简化了Rman备份的操作。
当你定义plus archivelog语句时,RMAN执行如下步骤的操作:
1。运行一个ALTER SYSTEM ARCHIVELOG CURRENT命令
2。运行BACKUP ARCHIVELOG ALL命令。注意如果备份优化被启用,RMAN只会备份未备份过的日志
3。备份BACKUP命令中定义的文件
4。运行ALTER SYSTEM ARCHIVELOG CURRENT命令
5。备份所有的剩下的归档日志
测试备份脚本:
backup database
format '/opt/oracle/orabak/full_%d_%T_%s'
plus archivelog
format '/opt/oracle/orabak/arch_%d_%T_%s'
delete all input;
通过plus archivelog,简化了备份操作,同时确保需要的日志都被备份
RMAN> run {
2> backup database
3> format '/opt/oracle/orabak/full_%d_%T_%s'
4> plus archivelog
5> format '/opt/oracle/orabak/arch_%d_%T_%s'
6> delete all input; }
用RMAN怎么恢复指定时间的archivelog
D:\oracle\ora92\bin>rman catalog rman/rman@ncdb target /
Recovery Manager: Release 9.2.0.6.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: MARKET (DBID=4036286469)
connected to recovery catalog database
RMAN> list backup of archivelog time between "to_date('2005-05-09 02:10:29','yyyy-mm-dd hh24:mi:ss
')" and "to_date('2005-05-09 02:12:12','yyyy-mm-dd hh24:mi:ss')";
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ -------------------
12977 399M DISK 00:08:54 2005-05-10 02:15:45
List of Archived Logs in backup set 12977
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- ------------------- ---------- ---------
1 2225 182640056 2005-05-09 02:10:29 182644489 2005-05-09 02:11:08
1 2226 182644489 2005-05-09 02:11:08 182648353 2005-05-09 02:11:40
1 2227 182648353 2005-05-09 02:11:40 182651753 2005-05-09 02:12:12
1 2228 182651753 2005-05-09 02:12:12 182655195 2005-05-09 02:12:46
Backup Set Copy #1 of backup set 12977
Device Type Elapsed Time Completion Time Tag
----------- ------------ ------------------- ---
DISK 00:08:54 2005-05-10 02:15:45 TAG20050510T020649
List of Backup Pieces for backup set 12977 Copy #1
BP Key Pc# Status Piece Name
------- --- ----------- ----------
12978 1 AVAILABLE F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_1_1
12979 2 AVAILABLE F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_2_1
12980 3 AVAILABLE F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_3_1
12981 4 AVAILABLE F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_4_1
RMAN> run
2> {set archivelog destination to 'e:\temp';
3> restore archivelog time between "to_date('2005-05-09 02:10:29','yyyy-mm-dd hh24:mi:ss')"
4> and "to_date('2005-05-09 02:12:12','yyyy-mm-dd hh24:mi:ss')";
5> }
executing command: SET ARCHIVELOG DESTINATION
Starting restore at 2005-05-12 15:20:41
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=17 devtype=DISK
channel ORA_DISK_1: starting archive log restore to user-specified destination
archive log destination=e:\temp
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2225
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2226
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2227
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2228
channel ORA_DISK_1: restored backup piece 1
piece handle=F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_1_1 tag=TAG20050510T020649 params=NUL
L
channel ORA_DISK_1: restored backup piece 2
piece handle=F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_2_1 tag=TAG20050510T020649 params=NUL
L
channel ORA_DISK_1: restored backup piece 3
piece handle=F:\RMANBACK\LOG\DB_MARKET_LOG_20050510_8LGK1GPR_3_1 tag=TAG20050510T020649 params=NUL
L
channel ORA_DISK_1: restore complete
Finished restore at 2005-05-12 15:23:09
RMAN>
RMAN> list copy of archivelog all;
List of Archived Log Copies
Key Thrd Seq S Low Time Name
------- ---- ------- - ------------------- ----
13290 1 2225 A 2005-05-09 02:10:29 E:\TEMP\ARC02225.001
13291 1 2226 A 2005-05-09 02:11:08 E:\TEMP\ARC02226.001
13292 1 2227 A 2005-05-09 02:11:40 E:\TEMP\ARC02227.001
13293 1 2228 A 2005-05-09 02:12:12 E:\TEMP\ARC02228.001
13052 1 2231 A 2005-05-10 02:06:44 E:\ORACLE\ORADATA\LOG\ARC02231.001
13074 1 2232 A 2005-05-10 02:16:14 E:\ORACLE\ORADATA\LOG\ARC02232.001
13075 1 2233 A 2005-05-10 02:20:39 E:\ORACLE\ORADATA\LOG\ARC02233.001
13076 1 2234 A 2005-05-10 02:21:48 E:\ORACLE\ORADATA\LOG\ARC02234.001
RMAN可以让你直接测试备份文件的好坏而不用另外生成模拟库的
C:WUTemp>rman target sys/tuning
Recovery Manager: Release 9.2.0.1.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: DEMO (DBID=3272375326)
run {
allocate channel C1 type disk;
backup full tag 'FullBackup' format 'e:\rmanbk\%d_%u_%s_%p.dbf' database include current controlfile;
sql ' alter system archive log current';
release channel C1;
}
1、---做个全库备份,备份完之后再次备份控制文件
D:\ORACLE\BIN>rman target /
Recovery Manager: Release 9.2.0.5.0 - Production
Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
connected to target database: ENCORE (DBID=3146513770)
run
{allocate channel d1 type disk;
backup full database
format 'E:\rmanbk\db_%d_%s_%p_%t_%T';
sql 'alter system archive log current';
backup current controlfile
format 'E:\rmanbk\cf_%d_%s_%p_%t_%T';
release channel d1;
}
recover database noredo
restore database;
recover database until cancel;
alter database open resetlogs;
oracle会根据控制文件自动生产联机日志
应该是HWM以下的数据块。
Rman备份的时候是先备份数据文件头的,然后再备份数据文件块。
并且在备份块的时候会去比较block header 和block tail,假如二者不一致的话,
它会继续读,直到读到一致的块为止。
这是因为Rman备份时,是通过Server Process(Oracle内部进程)进行Copy数据块的。
run {
set until sequence 11 thread 1;
restore database;
recover database;
}
备份数据到不同的设备,就是duplex
run
{
allocate channel dev1 type disk;
allocate channel dev2 type disk;
sql 'alter system archive log current';
SET BACKUP COPIES 2;
backup
format '/opt/ora9/oradata/ora9i/archive/log_t%t_s%s_p%p','/home/oracle/log_t%t_s
%s_p%p'
archivelog all delete all input;
release channel dev1;
release channel dev2;
}
RMAN命令使用方法
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
handle processing
Hander processing failed; nested exception is java.lang.NoClassDefFoundError; javax/servlet/jsp/jstl/core/Config【问题描述】 今天我将之前调试过的一个 web project 直接复制到另一个文件夹里面,原工程是没有问题的(至少可以正常运行)。然后,我将新路径下的
handle processing Java Springweb project NoClassDefFoundError javaxservletjspjstlc