rman常用命令

1.从备份集恢复某个归档日志到指定的目录

run{
allocate channel ci type disk;
set archivelog destination to '/home/oracle/myarchlog';
restore archivelog sequence 299;
release channel ci;
}

 2.删除具体某个归档日志

delete force noprompt archivelog sequence 602;
delete archivelog sequence 602;

 

-------------restore archivelog的各种选项--------------------

1.restore archivelog all 恢复全部归档日志文件
RMAN> restore archivelog all;
2.只恢复 5到8这四个归档日志文件
RMAN> restore archivelog from logseq 5 until logseq 8;
3.恢复从第5个归档日志起
RMAN> restore archivelog from logseq 5;
4.恢复7天内的归档日志
RMAN> restore archivelog from time 'sysdate-7';
5. sequence between 写法
RMAN> restore archivelog sequence between 1 and 3;
6.恢复到哪个日志文件为止
RMAN> restore archivelog until logseq 3;
6.从第五个日志开始恢复
RMAN> restore archivelog low logseq 5;
7.到第5个日志为止
RMAN> restore archivelog high logseq 5;
如果想改变恢复到另外路径下 则可用下面语句
set archivelog destination to 'd:\backup';
RMAN> run
2> {allocate channel ci type disk;
3> set archivelog destination to 'd:\backup';
4> restore archivelog all;
5> release channel ci;
6> }

 

------------恢复有效性检查--------------

 

1.检查备份有效性
##完全恢复
run{
restore database preview; ##或是restore database preview summary;
}

RMAN> shutdown immediate

using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     771751936 bytes

Fixed Size                     8797536 bytes
Variable Size                566231712 bytes
Database Buffers             192937984 bytes
Redo Buffers                   3784704 bytes

RMAN> restore database preview;

Starting restore at 10-DEC-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK


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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19      Full    374.14M    DISK        00:00:39     10-DEC-19      
        BP Key: 19   Status: AVAILABLE  Compressed: YES  Tag: TAG20191210T204957
        Piece Name: /u01/rman_backup/db_fullbackup_ORA12C_26_1_20191210
  List of Datafiles in backup set 19
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  1       Full 2162720    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/system01.dbf
  3       Full 2162720    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/sysaux01.dbf
  4       Full 2162720    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/undotbs01.dbf
  7       Full 2162720    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/users01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
20      Full    165.62M    DISK        00:00:17     10-DEC-19      
        BP Key: 20   Status: AVAILABLE  Compressed: YES  Tag: TAG20191210T204957
        Piece Name: /u01/rman_backup/db_fullbackup_ORA12C_27_1_20191210
  List of Datafiles in backup set 20
  Container ID: 2, PDB Name: PDB$SEED
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  5       Full 1440734    06-DEC-19              NO    /u01/app/oracle/oradata/ora12c/pdbseed/system01.dbf
  6       Full 1440734    06-DEC-19              NO    /u01/app/oracle/oradata/ora12c/pdbseed/sysaux01.dbf
  8       Full 1440734    06-DEC-19              NO    /u01/app/oracle/oradata/ora12c/pdbseed/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22      Full    54.50M     DISK        00:00:06     10-DEC-19      
        BP Key: 22   Status: AVAILABLE  Compressed: YES  Tag: TAG20191210T204957
        Piece Name: /u01/rman_backup/db_fullbackup_ORA12C_29_1_20191210
  List of Datafiles in backup set 22
  Container ID: 3, PDB Name: ORA12CPDB1
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  9       Full 2162756    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/system01.dbf
  11      Full 2162756    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/undotbs01.dbf
  13      Full 2162756    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/TPS_DATA13.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21      Full    115.22M    DISK        00:00:14     10-DEC-19      
        BP Key: 21   Status: AVAILABLE  Compressed: YES  Tag: TAG20191210T204957
        Piece Name: /u01/rman_backup/db_fullbackup_ORA12C_28_1_20191210
  List of Datafiles in backup set 21
  Container ID: 3, PDB Name: ORA12CPDB1
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  10      Full 2162749    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/sysaux01.dbf
  12      Full 2162749    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/users01.dbf
  14      Full 2162749    10-DEC-19              NO    /u01/app/oracle/oradata/ora12c/ora12cpdb1/TPS_DATA14.dbf
using channel ORA_DISK_1

archived logs generated after SCN 2162720 not found in repository
recovery will be done up to SCN 2162720
Media recovery start SCN is 2162720
Recovery must be done beyond SCN 2162756 to clear datafile fuzziness
Finished restore at 10-DEC-19

RMAN> restore database;

Starting restore at 10-DEC-19
using channel ORA_DISK_1

skipping datafile 5; already restored to file /u01/app/oracle/oradata/ora12c/pdbseed/system01.dbf
skipping datafile 6; already restored to file /u01/app/oracle/oradata/ora12c/pdbseed/sysaux01.dbf
skipping datafile 8; already restored to file /u01/app/oracle/oradata/ora12c/pdbseed/undotbs01.dbf
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/ora12c/system01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/ora12c/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ora12c/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/ora12c/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman_backup/db_fullbackup_ORA12C_26_1_20191210
channel ORA_DISK_1: piece handle=/u01/rman_backup/db_fullbackup_ORA12C_26_1_20191210 tag=TAG20191210T204957
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00012 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/users01.dbf
channel ORA_DISK_1: restoring datafile 00014 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/TPS_DATA14.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman_backup/db_fullbackup_ORA12C_28_1_20191210
channel ORA_DISK_1: piece handle=/u01/rman_backup/db_fullbackup_ORA12C_28_1_20191210 tag=TAG20191210T204957
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/system01.dbf
channel ORA_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00013 to /u01/app/oracle/oradata/ora12c/ora12cpdb1/TPS_DATA13.dbf
channel ORA_DISK_1: reading from backup piece /u01/rman_backup/db_fullbackup_ORA12C_29_1_20191210
channel ORA_DISK_1: piece handle=/u01/rman_backup/db_fullbackup_ORA12C_29_1_20191210 tag=TAG20191210T204957
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 10-DEC-19

RMAN> recover database;

Starting recover at 10-DEC-19
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 10-DEC-19

RMAN> alter database open;

Statement processed

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 若不能恢复确实归档的话,会提示如下信息

no backup of archived log for thread 1 with sequence 20 and starting SCN of 2145559 found to restore
no backup of archived log for thread 1 with sequence 21 and starting SCN of 2164272 found to restore
no backup of archived log for thread 1 with sequence 22 and starting SCN of 2164280 found to restore
no backup of archived log for thread 1 with sequence 23 and starting SCN of 2164284 found to restore
no backup of archived log for thread 1 with sequence 24 and starting SCN of 2164287 found to restore
recovery will be done up to SCN 2162720
Media recovery start SCN is 2162720
Recovery must be done beyond SCN 2162756 to clear datafile fuzziness
Finished restore at 10-DEC-19

 

##不完全恢复
run{
set until scn 5218728;
restore database preview;
}

 

run{
set until sequence 21; ##不包含21的日志,只恢复到20的日志
restore database preview;
}

 

run{
sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"';
set until time='2019-03-09:23:00:00';
restore database preview;
}

 


2.验证备份集是否可用
run{
set until scn 5218728;
restore validate database;
}

 

校验归档日志有效性
restore validate archivelog sequence between 17 and 18;

 

posted @ 2019-01-15 09:20  slnngk  阅读(430)  评论(0编辑  收藏  举报