Master Oracle Backup & Recovery: Failure Types, RMAN Scripts & Automation
This article covers Oracle database backup and recovery fundamentals, including failure types, logical vs physical backup methods, flashback technology, complete and incomplete recovery, and provides practical RMAN scripts for level 0/1 incremental backups with crontab automation and monitoring queries.
Reading font

The article opens with a real-world anecdote: a new hire is told by his manager that poor backup and recovery skills may cause him to fail probation, underscoring that data is a critical enterprise asset and mastering this skill is essential for career growth.
Database Failure Types
User process failure: handled automatically by PMON.
Instance failure: handled automatically by SMON.
User errors: require DBA intervention via backup and recovery.
Media failure: must be recovered using backups and redo logs.
Summary: backup and recovery primarily protect data against media, user, and application failures, retain data, and transport data.
Backup and Recovery Classification
Restore (重储) vs Recover (恢复). Two main categories: logical and physical.
Logical Backup and Recovery
Traditional export/import: exp/imp.
Data Pump export/import: expdp/impdp.
Object-level, captures a logical snapshot of database objects at a point in time (hot backup).
Cannot be used for media failure; logical recovery is simply restoring the backup, with no redo apply (recover) phase.
Physical Backup and Recovery
Targets media failure.
Manual backup and recovery (User-Managed, UMAN): uses OS commands to copy files, then applies logs for recovery.
Automatic backup and recovery: uses Oracle RMAN to automate restore and recover.
Physical backups can be consistent (cold backup) or inconsistent (hot backup). A complete strategy should rely on physical backups as primary, with logical backups as supplementary for critical tables.
Flashback Technology
Fast recovery using undo data or flashback logs.
Enables logical recovery at different levels (table, transaction, database, etc.).
Oracle 11g supports seven flashback variants; the fast recovery area is only related to flashback database.
Complete vs Incomplete Recovery
Complete Recovery
Uses full or partial backups to restore datafiles.
Applies all redo to the last commit before the failure, resulting in zero data loss.
Incomplete Recovery
Requires full backup and logs to restore the database to a past point in time or SCN.
Data loss occurs because redo after the target point is not applied.
Backup Strategy
Weekly level 0 full backup on Sunday; daily level 1 incremental backups Monday through Saturday.
Retention policy: redundancy 2.
Control file autobackup enabled.
RMAN configuration commands:
RMAN> show all;
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE CONTROLFILE AUTOBACKUP ON;Backup Scripts
Level 0 (full) script rman_level0.sh:
#!/bin/bash
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=PROD
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
rman target / << EOF
run{
crosscheck backup;
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup incremental level 0 database format '/u01/backup/rman/db_%U.bak'
plus archivelog format '/u01/backup/rman/ar_%U.bak';
backup current controlfile format '/u01/backup/rman/ctl_%U.bak';
report obsolete device type disk;
delete noprompt obsolete device type disk;
delete noprompt expired backup device type disk;
release channel c1;
release channel c2;
}
EOF
exitCROSSCHECK verifies backup pieces on disk/tape; statuses: AVAILABLE, UNAVAILABLE, EXPIRED.
Level 1 (incremental) script rman_level1.sh is similar but uses backup incremental level 1.
Make scripts executable:
chmod a+x /home/oracle/scripts/rman_level0.sh
chmod a+x /home/oracle/scripts/rman_level1.shCrontab Scheduling
Test environment: hourly full backup, incremental every 15 minutes.
0 * * * * /home/oracle/scripts/rman_level0.sh >> /u01/backup/rman/PROD_rman_L0_`date +\%Y\%m\%d_\%H\%M\%S`.log 2>&1
15,30,45 * * * * /home/oracle/scripts/rman_level1.sh >> /u01/backup/rman/PROD_rman_L1_`date +\%Y\%m\%d_\%H\%M\%S`.log 2>&1Monitoring and Verification
Check backup logs for success; verify obsolete and expired backups are deleted.
Query backup job details:
select a.TIME_TAKEN_DISPLAY as "用时",
a.INPUT_BYTES_DISPLAY "大小",
a.INPUT_BYTES_PER_SEC_DISPLAY as "速度",
a.INPUT_TYPE "备份类型",
to_char(start_time, 'day') day1,
to_char(start_time, 'yyyy-mm-dd hh24:mi:ss') as "开始时间",
to_char(end_time, 'yyyy-mm-dd hh24:mi:ss') "结束时间",
output_device_type,
status,
input_type
from V$RMAN_BACKUP_JOB_DETAILS aAbout this article
For attribution, corrections or content rights, contact