首页 > 代码库 > 官方文档 恢复备份指南二 Getting Started with RMAN
官方文档 恢复备份指南二 Getting Started with RMAN
1.Overview of the RMAN Environment
2.Starting RMAN and Connecting to a Database
RMAN> CONNECT TARGET SYS@prod
RMAN> CONNECT TARGET /
connected to target database: PROD (DBID=39525561)
RMAN> STARTUP FORCE DBA;
RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP MOUNT;
RMAN> BACKUP DATABASE;或者RMAN> BACKUP AS COPY DATABASE;
RMAN> ALTER DATABASE OPEN;
Option | Description | Example |
---|---|---|
| Specifies a location and name for backup pieces and copies. You must use substitution variables to generate unique file names. The most common substitution variable is 指定备份集搁置和名称格式.默认的名称格式是%U.%d表示DB_NAME,%t表示备份时的时间戳,%s设置备份集序号,p%设置备份片序号 | BACKUP FORMAT ‘AL_%d/%t/%s/%p‘ ARCHIVELOG LIKE ‘%arc_dest%‘; |
| Specifies a user-defined string as a label for the backup. If you do not specify a tag , then RMAN assigns a default tag with the date and time. Tags are always stored in the RMAN repository in uppercase. 为本次备份设置一个别名,以便恢复时使用 | BACKUP TAG ‘weekly_full_db_bkup‘ DATABASE MAXSETSIZE 10M; |
8.Making Incremental Backups 增量备份
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
BACKUP INCREMENTAL LEVEL 1 DATABASE;
1.首先执行镜像备份,指定一个tag
BACKUP Option | Description | Example |
---|---|---|
| Use If no level 0 data file copy with the specified tag exists in either the current or parent database incarnation, then RMAN creates a level 0 data file copy with the specified tag. 指定tag,然后RMAN会自动合并镜像.如果没有执行过镜像备份,则RMAN创建镜像备份 | BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG ‘incr_update‘ DATABASE; |
| Specifies where RMAN creates the data file copy if a copy does not exist. If you add a new data file to the database, then you do not need to change your script, because RMAN automatically creates the level 0 copy required by the incremental backup routine. 备份数据文件镜像. | BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY DATAFILECOPY FORMAT ‘/disk2/df1.cpy‘ DATABASE; |
WITH TAG ‘incr_update‘;
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG ‘incr_update‘
DATABASE;
VALIDATE
验证数据文件是否存在,是否有错误.CHECK LOGICAL 命令验证数据文件是否有逻辑错误.DATABASE ARCHIVELOG ALL;
CONNECT TARGET /
BACKUP DATABASE PLUS ARCHIVELOG;
LIST BACKUP;
EXIT;
RMAN> @/my_dir/my_command_file.txt # runs specified command file
或者
% rman @/my_dir/my_command_file.txt
list backup:
Option | Example | Explanation |
---|---|---|
|
| Organizes the output by backup set. This is the default mode of presentation. |
|
| Lists the backups according to which file was backed up. |
|
| Displays summary output. |
Option | Example | Explanation |
---|---|---|
|
| Lists backups that are recorded in the RMAN repository but that were not present at the expected location on disk or tape during the last |
|
| Lists data file backups or copies that have status |
LIST COPY OF DATAFILE 1, 2;
LIST BACKUP OF ARCHIVELOG FROM SEQUENCE 10;
LIST BACKUPSET OF DATAFILE 1;
Option | Example | Explanation |
---|---|---|
|
在当前的保留策略下需要备份的文件 | Shows which files need backing up under current retention policy. Use optional |
|
报告过期的备份 | Lists backups that are obsolete under the configured backup retention policy. Use the optional |
|
| Reports the tablespaces and data files in the database at the current time (default) or a different time. |
|
| Lists all data files for which an unrecoverable operation has been performed against an object in the data file since the last backup of the data file. |
CATALOG
, CHANGE
, CROSSCHECK
, DELETE
.CROSSCHECK COPY;
RMAN 保留策略将应用于该命令
将 RMAN 保留策略设置为冗余 1
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: SID=139 设备类型=DISK
删除以下已废弃的备份和副本:
类型 关键字 完成时间 文件名/句柄
-------------------- ------ ------------------ --------------------
存档日志 5 12-5月 -14 D:\APP\WJ\PRODUCT\11.1.0\DB_1\RDBMS\ARC00059_0817241642.001
存档日志 7 12-5月 -14 D:\APP\WJ\PRODUCT\11.1.0\DB_1\RDBMS\ARC00060_0817241642.001
存档日志 9 12-5月 -14 D:\APP\WJ\PRODUCT\11.1.0\DB_1\RDBMS\ARC00061_0817241642.001
存档日志 11 12-6月 -14 D:\APP\WJ\FLASH_RECOVERY_AREA\ARC00075_0817241642.001
存档日志 12 13-6月 -14 D:\APP\WJ\FLASH_RECOVERY_AREA\ARC00076_0817241642.001
存档日志 13 13-6月 -14 D:\APP\WJ\FLASH_RECOVERY_AREA\ARC00077_0817241642.001
存档日志 14 20-6月 -14 D:\APP\WJ\FLASH_RECOVERY_AREA\ARC00078_0817241642.001
存档日志 15 23-6月 -14 D:\APP\WJ\FLASH_RECOVERY_AREA\ARC00079_0817241642.001
是否确定要删除以上对象 (输入 YES 或 NO)? no
CRITICAL
, HIGH
, or LOW
和
OPEN
or CLOSED.
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
142 HIGH OPEN 23-APR-07 One or more non-system datafiles are missing
101 HIGH OPEN 23-APR-07 Datafile 1: ‘/disk1/oradata/prod/system01.dbf‘
contains one or more corrupt blocks
RMAN>
ADVISE FAILURE;
List of Database Failures
=========================
Failure ID Priority Status Time Detected Summary
---------- -------- --------- ------------- -------
142 HIGH OPEN 23-APR-07 One or more non-system datafiles are missing
101 HIGH OPEN 23-APR-07 Datafile 1: ‘/disk1/oradata/prod/system01.dbf‘
contains one or more corrupt blocks
analyzing automatic repair options; this may take some time
using channel ORA_DISK_1
analyzing automatic repair options complete
Mandatory Manual Actions
========================
no manual actions available
Optional Manual Actions
=======================
1. If file /disk1/oradata/prod/users01.dbf was unintentionally renamed or moved, restore it
Automated Repair Options
========================
Option Repair Description
------ ------------------
1 Restore and recover datafile 28; Perform block media recovery of
block 56416 in file 1
Strategy: The repair includes complete media recovery with no data loss
Repair script: /disk1/oracle/log/diag/rdbms/prod/prod/hm/reco_660500184.hm
STARTUP MOUNT;
FLASHBACK DATABASE TO SCN 861150;
FLASHBACK DATABASE
TO RESTORE POINT BEFORE_CHANGES;
FLASHBACK DATABASE
TO TIMESTAMP TO_DATE(04-DEC-2009 03:30:00‘,‘DD-MON-YYYY HH24:MI:SS‘);
Starting restore at 21-MAY-07
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=80 device type=DISK
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
11 B F A DISK 18-MAY-07 1 2 NO TAG20070518T181114
13 B F A DISK 18-MAY-07 1 2 NO TAG20070518T181114
using channel ORA_DISK_1
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
47 1 18 A 18-MAY-07
Name: /disk1/oracle/dbs/db1r_60ffa882_1_18_0622902157.arc
Media recovery start SCN is 586534
Recovery must be done beyond SCN 587194 to clear datafile fuzziness
validation succeeded for backup piece
Finished restore at 21-MAY-07
RMAN> STARTUP FORCE MOUNT;
RMAN> RESTORE DATABASE;
RMAN> RECOVER DATABASE;
RMAN> ALTER DATABASE OPEN;
RESTORE
TABLESPACE
和
RECOVER
TABLESPACE
用来还原和恢复单个表空间,可以在数据库打开的情况下执行.首先,要把表空间脱机,然后执行restore再执行recover,再把表空间联机onlineRUN
{
SET NEWNAME FOR DATAFILE ‘/disk1/oradata/prod/users01.dbf‘
TO ‘/disk2/users01.dbf‘;
RESTORE TABLESPACE users;
SWITCH DATAFILE ALL; # update control file with new file names
RECOVER TABLESPACE users;
}
RMAN> SQL ‘ALTER TABLESPACE users ONLINE‘;
RMAN> RECOVER DATAFILE 1 BLOCK 233, 235 DATAFILE 2 BLOCK 100 TO 200;修复指定的错误块