RMAN
connect target sys/test
configure default device type to disk
show default device type;
//设置并行度,同时启动3个server process
configure device type disk parallelism 3;
show device type;
configure channel device type disk format 'd:/backup/rman/%U';
configure channel device type disk maxpiecesize 50M;
configure channel device type disk format 'd:/backup/rman/%U'
2> maxpiecesize 50M;
show channel;
show all;
v$instance v$database
v$datafile v$controlfile
v$logfile dba_data_files
v$backup
如果热备失败(如在备份时instance failure)
Query v$backup to check backup status
Issue the alter database command to change
the status and unfreeze the header
alter database datafile '<filename>' end backup;
or use this command in oracle9i
alter database end backup;
join
select t.name,d.file#,d.name
from v$tablespace t join v$datafile d using (ts#);
//binary image
alter database backup controlfile to 'control1.bkp';
//text trace file
alter database backup controlfile to trace;
backup sets 逻辑概念
每一个备份集中一定要是相同的BLOCKSIZE
backup piece 一个文件,物理文件
RUN{
ALLOCATE CHANNEL t1 TYPE 'SBT'
MAXPIECESIZE = 4G
BACKUP
FORMAT 'df_%t_%s_%p' FILESPERSET 3
{tablespace users};}
'SBT' 磁带机
MAXPIECESIZE = 4G 每个piece最大4G
FORMAT 'df_%t_%s_%p'
%t 时间戳 %s 备份集 %p 备份片
FILESPERSET
每个备份集(backup set) 包含 多少个数据文件
FILESPERSET 3
datafiles per set
每个备份集(backup set) 三个数据文件
如6个数据文件那么就2个backup set
如7个数据文件那么就3个backup set
rman>backup
format '/backup/df_%d_%s_%p.bus'
database filesperset = 2;
将差不多大小的文件放在一个backup set中备份
这样可以更好的支持流
select * from v$archived_log where deleted = 'NO';
IMAGE COPY
rman>copy datafile '' to '';
rman>copy archivelog '' to '';
backup archivelog all delete all input;
要在有设置的情况下
Making Incremental Backups
1.Full backups contain all datafile blocks
2.Differential incremental backups contain only
modified blocks from level n or lower
备份包含自上一次n 级或更低级别备份以来变化的数据
<=n 做的基础是<=n 如2那么前面只要是<=2,就是差异增量备份的基础
3.Cumulative incremental backups contain only
modified blocks from level n-1 or lower.
累计增量备份包含n-1 级或更低级别备份以来改变的数据块
<n 做的基础是<n 如2那么前面只要是<2,如0,1就是累积增量份的基础,而2不是累积增量备份的基础
增量的级别是0-4
自动备份控制文件
configure controlfile autoback = on
(server parameter file 也能够自动备份)
.Explicitly backed up with backup spfile
RMAN>backup copies 2 device type sbt spfile;
把参数文件备份两个镜像,并把它备份到磁带机上.S
v$archived_log 被归档,删除,存在的归档文件
v$backup_corruption 备份集备份时找到的怀块
v$copy_corruption image备份时找到的怀块
v$database_block_corruption
v$backup_datafile
v$backup_redolog
v$backup_set
v$backup_piece
监控RMAN备份
在RMAN备份中使用SET COMMAND ID命令以便于更好地确认进程
在V$PROCESS和V$SESSION视图中确认属于RMAN备份的会话
检查V$SESSION_LOGOPS视图,监控RMAN备份的进度
rman>show controlfile autobackup; 查看控制文件自动备份的状态
CONFIGURE CONTROLFILE AUTOBACKUP OFF; #default
rman>configure controlfile autobackup on;
Media Recovery
Recovery Steps
1.Restored datafiles
2.Redo applied
3.Database containing committed and uncommitted transactions
4.Undo applied
5.Recovered database
Determining which files need recovery
v$recover_file which datafiles need recovery
v$recovery_log A list of all archived redo log
files required for recovery.
v$archived_log
recover a mounted database
recover database/recover datafile ''/n;
recover an open database
recover tablespace users/recover datafile ''/n;
User-Managed Procedures for Restoring Datafiles to a New Location
1. Use operating system commands to restore the file to the new location.
Note: In the UNIX environment, the files must exist in the new location before you issue the ALTER DATABASE RENAME command. This is not the case in a Windows environment.
2. Start up the instance and mount the database.
3. Use the ALTER DATABASE command to update the control file with the new file name or location:
SQL> ALTER DATABASE RENAME FILE
2> '/ORADATA/u03/users01.dbf'
3> TO '/ORADATA/u04/users01.dbf';
recover database using backup controlfile;
要恢复数据库,但不用在线的redolog文件
Re-Creating Lost Datafiles Without Backup
Description of missing datafile is still in data
dictionary and control file.
sql>alter database create datafile 'filename';
Re-create the datafile with a different filename
sql>alter database create datafile 'filename'
as 'new file name';
Recovery without a Backup: Example
Datafile 4 (on disk 1) is lost. When restoring the datafile from tape, you receive an error indicating that the file was not backed up. You locate the DBA who created the TABLE_DATA tablespace two days ago and find that it contains important user data, but it was never included in the backup strategy. Because datafile 4 is not a system or rollback segment datafile, and you have all archived logs for the past two days, you can proceed as follows:
1. If the database is closed, then mount the database, take the datafile (with no backup) offline, and open the database. This allows users who do not need the TABLE_DATA tablespace to work on the system. If the database is open, take the datafile or the tablespace offline.
Note: If the database is open, the immediate option must be included, to avoid the database writer trying to write to a file that does not exist:
SQL> ALTER TABLESPACE table_data OFFLINE IMMEDIATE;
Tablespace altered.
Recovery without a Backup Example (continued)
You confirm the recovery status by querying V$RECOVER_FILE to check the status of a backup:
SQL> SELECT * FROM v$recover_file;
FILE# ONLINE ONLINE_STATUS ERROR CHANGE# TIME
----- ------- ------------- -------------- ------- ----
4 OFFLINE OFFLINE FILE NOT FOUND 0
2. You issue the following command to re-create the file:
SQL> ALTER DATABASE create datafile ‘/disk2/DATA/df4.dbf’
2> as ‘/disk1/DATA/df4.dbf‘;
Database altered.
SQL> SELECT * FROM v$recover_file;
FILE# ONLINE ERROR CHANGE# TIME
----- ------- ------------------ ---------- ------
4 OFFLINE 248621 01-DEC-97
3. Use the RECOVER or ALTER DATABASE RECOVER commands to start applying the archived and online redo log files to the re-created datafile:
SQL> RECOVER TABLESPACE table_data;
To bring the datafile to the point of failure, all needed archived logs and redo logs are applied. All datafiles are now synchronized.
4. When recovery is finished, bring the tablespace online:
SQL> ALTER TABLESPACE table_data ONLINE;
All data is now recovered. Include the file in the backup strategy and notify users that the tablespace is ready to be used again.