oracle 主要的备份工具 RMAN
其中,open database backup, 不需要把数据库设置成backup状态,
RMAN reads a block until a consistent read is obtained.
看来备份比较重要的三种文件分别是, data file, control file, archivelog file.
Note : The online redo log files are not backed up when using Recovery Manage.
A closed database backup is defined as a backup of the database while it is closed(offline), This is the same as the consistent database backup. If you performing a closed backup, the target database must not be open. If you are using a recovery catalog, the recovery catalog database must be open.
An open database backup is defined as a backup of any protion of the database while it is open(online). Recovery Manager uses server processes to make copies of datafiles, control files, or archive logs. When using Recovery Manager, do not put tablespaces in backup mode using the ALTER TABLESPACE …BEGIN BACKUP command. RMAN reads a block until a consistent read is obtained.
增量备份是RMAN所独有的, 其他的都不可能实现增量备份.
看来 rman 的备份要不然就是 mount 状态 要不就是 open 状态.
RMAN 是一个客户端工具
两种方法 : 1. 镜像拷贝, image copy, 就是简单的拷贝命令, ( 不支持增量备份, 这种也可以操作系统层面上的手动copy )
2. 备份集, 里边有备份片, set 是 片( piece ) 的集合. 多个不同类型的文件可以做一个备份集. ( 支持增量备份 )
备份集还分两种: 1. Full backup, all blocks containing data for the files specifiey are backed up.
2. Incremental backup,
注: You can configure automatic control file backup so that the control file is backed up when you issue
a BACKUP or COPY command.
Incremental backup: An incremental backup is a backup of datafiles(只是针对datafile) that include only the blocks that have changed since the last incremental backup. Incremental backups require a base-level( or incremental level 0) backup, which backs up all blocks containing data for the files specified. Incremental level 0 and full backups copy all blocks in datafiles, but full backups cannot be used in an incremental backup strategy.
A backup set consists of one or more physical files stored in an RMAN-specific format, on either disk or tape.
备份集也可以被 备份, 备份集包含两种文件: datafile(data file, control file), archived log file.
注: Backup sets may need to be restored by Recovery Manager before recovery can be performed, unlike image copies
which generally are available on disks.( 备份集在在 恢复的时候,要先还原成数据库认识的格式 )
加 control file 方法: 1. Explicitly using the INCLUDE CONTROL FILE syntax
2. Implicitly by backing up file 1(the system datafile)
When a control file is included, it is written in the last datafile backup set.
看到没, 只有datafile 支持 incremental 备份
Archived redo log file backup sets cannot be incremental(they are full by default)
A backup set can be written to disk or tape. Oracle provides one tape output by default for most platforms, known as SBT_TAPE(System Backup to Tape), which writes to a tape device when you are using a media manager. (SBT_TAPE, 可见不是磁带的意思, 是一种介质的总称, 只用这种就可以了应该 )
A restore operation must extract files from a backup set before recovery. ( backup set 的格式, 是rman 特有的一种格式, 当需要使用备份的内容恢复数据库时, 需要先将备份集的这种格式转换一下 )
1个Piece 可以横跨多个 datafile.
A logical backup set usually only has one backup piece. A backup piece is a single physical file that can
contain one or more Oracle datafiles or archived logs.
backup piece 可以通过 ls 等 linux 命令直接查看了.
例如简单的快速备份, backup database format ‘/u01/app/oracle/md_%U’;
A logical backup set usually only has one backup piece. A backup piece is a single physical file that can contain one or more Oracle datafiles or archived logs.
注意:
要限制 backup piece size, 因为有可能超出物理限制( 比如操作系统最大单个文件限制 )
When using the BACKUP command, you must do the following :
filesperset = 2; 表示备份集里有 2 个备份片
You can configure parallel backups by setting the PARALLELISM option of the CONFIGURE command to greater than 1 or manually allocate multiple channels, RMAN parallelizes its operation and writes multiple backup sets in parallel. The server sessions divide the work of backing up the specified files.
备份控制文件的 4 种方法 :
1. 设置自动备份为 auto
2. backup current controlfile;
3. backup datafile include current controlfile;
4. sql “ alter database backup controlfile to ‘’/tmp/wilson.bin’’”;
一般备份 control file 和 spfile 会一起备份起来
备份归档日志文件 archivelog ( 实际上就是文件 copy )
所有的 归档文件都要一起拷贝下来.
DELETE ALL INPUT 为了避免重复( 已经备份的archivelog 就直接删除 )
backup database plus archivelog format ‘/u01/backup/db_%U’;
最多可以支持 4 份同样备份集, 多路备份.
backup copies=2
镜像拷贝不是很重要(当然, 还不如操作系统层面下直接手动备份呢.)
通过RMAN的镜像拷贝, 控制文件是知道的,而如果只是操作系统操作,那么控制文件就不知道
或者 backup as copy datafile …
full backup, whole backup 区别:
whole backup: 整个数据库备份
full backup: 可能是整个tablespace的一个全备.
When performing a fullbackup, an oracle server process reads the entire file and copies all blocks into the backup set, skipping only datafile blocks that have nerver neen used. The server session does not skip blocks when backing up archived redo logs or control files. A full backup is not a part of the incremental backup strategy. You can create and resotre full backups of datafiles, datafile copies, tablespaces, database, control files, archivelog logs and archive log copies. Note that backup sets containing archived redo logs are always full backups.
A full backup differs from a whole database backup, A whole backup is comprised of all of the datafiles and
control file of the target database, whereas a full backup may contain one or more of the datafiles, the control
file or archived redo log files.
differential incremental: 比同级或者同级更低的modified备份.
Incremental Backup
An incremental backup is a backup that includes only the blocks that have changed since a previous incremental backup. 两种类型:
下边的图, 很清晰的说明了差异备份和累积备份.
优点: 备份快.
缺点: 恢复慢.
优点: 备份慢.
缺点: 恢复快.
例如: (案例分析)
You are maintaining a 100GB database, which is continuously growing. Based on existing hardware, you determine that open backups of the entire database take 4 hours. The database is online 24 hours a day, 7 days a week and the backups are consuming too much of the system resources during this period of thime. Level 0 backups cannot be performed more than once a week, but fast recovery in case of failure is required. You therefore decide on the following backup and recovery strategy:
A level 0 backup will be performed each week on the day with the least acticity. You determine this day to be Sunday.
RMAN> BACKUP INFCREMENTAL level 0 database; -- 对整个数据库进行 level 0 全备
Incremental level 2 backups will be performed every other day, except Wednesday. In this way, (注意, 每周三做了一个累积备份), backups will be fast because only changed blocks from the previous day will be copied:
RMAN> BACKUP INCREMENTAL level 2 database; -- 差异备份
Wednesday is a day with less database activity, so all blocks changed since Sunday are copied to assist with speed of recovery. For example, if a failure occures on Friday, then only Sunday, Wednesday, and Thursday backups need to be restored(Monday and Tuesday are not required):
RMAN> BACKUP INCREMENTAL level 1 database; -- 累积备份
On Thursday, the incremental backup was replaced by a full backup. Because this does not change the backup base level, Friday’s backup copy changes since Wednesday. The backup therefore can be discarded before the next level 0. If by mistake the backup on Thusday was a level 0, then the backup on Friday copys all changed blocks since Thursday, which is the new base level. This backup must now be kept until the next level 0. ?
incremental 0 级备份可以作为 增量备份的基础, 全备不可以.
累积备份的特点是, 同一个level, 后边的备份会将前边的备份的内容, 同样备份, 这样, 当发生 recovery 时, 同一个level 的backup set, 只要执行最后一个就可以了.
例如:
RMAN> BACKUP INCREMENTAL levle 2 cumulative database;
备份策略:
0 级备份固定时间间隔
每天做一个差异备份, 灵活搭配 c 和 d ( d: different incremental backup, c: cumulative backup )
基本上不用考虑, 基本上所有的数据库都是 archivelog 模式.
另外自动备份 control file.
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE disk TO ‘controlfile_%F’;
注意: 这个格式, 默认的只是 %F, 修改格式里边必须包含 %F, 例如 control_%F.
给backup 文件起一个好一点的逻辑名字