Oracle Backup & Recovery Essentials: 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 a practical backup strategy with RMAN level 0/1 scripts, retention policies, and crontab automation for production environments.
Reading font

Author: IT邦德 Original: https://jeames.blog.csdn.net/article/details/122355707
Database Failure Types
1) User process failure: handled automatically by PMON.
2) Instance failure: handled automatically by SMON.
3) User errors: require DBA intervention via backup and recovery.
4) Media failure: must be recovered using backups and logs.
Summary: Backup and recovery primarily protect data (against media, user, or application failures), retain data, and transport data.
Backup and Recovery Classification
Restore refers to restoring files; Recover refers to applying redo logs to bring the database to a consistent state.
Logical Backup and Recovery
Traditional export/import: exp/imp.
Data Pump export/import: expdp/impdp.
Logical backup captures the state of database objects at a point in time.
Cannot be used for media failure; logical backup recovery is simply restoring the backup, with no recover step.
Physical Backup and Recovery
Targets media failure.
1) Manual backup and recovery (User-Managed Backup and Recovery, UMAN): uses OS commands to copy files, then applies logs for recovery.
2) Automatic backup and recovery: uses Oracle's RMAN (Recovery Manager) to automate restore and recover.
Physical backup modes: consistent backup (cold backup) and inconsistent backup (hot backup).
A complete backup strategy should rely on physical backup as primary, with logical backup as supplementary (for critical tables).
Flashback Technology
Fast recovery technology using undo data or flashback logs.
Enables logical recovery at different levels.
Oracle 11g supports seven flashback methods.
The fast recovery area is only related to flashback database.
Complete Recovery vs Incomplete Recovery
1) Complete Recovery
Uses full or partial backups to restore datafiles.
Recovers to the last commit before the failure, with no data loss.
2) Incomplete Recovery
Requires full backup and logs to recover the database to a past point in time (or SCN).
Results in data loss.
Backup Strategy
Weekly level 0 full backup on Sunday; daily level 1 incremental backups Monday through Saturday.
Retention policy: REDUNDANCY 2.
Enable control file autobackup.
RMAN> show all;
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE CONTROLFILE AUTOBACKUP ON;Backup Scripts
Create script directory and level 0 backup script:
mkdir /home/oracle/scripts
vi /home/oracle/scripts/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 command verifies backup files on disk and tape; statuses: AVAILABLE, UNAVAILABLE, EXPIRED.
Grant execute permissions:
chmod a+x /home/oracle/scripts/rman_level0.sh
chmod a+x /home/oracle/scripts/rman_level1.shCrontab Scheduled Tasks
Test environment: full backup hourly, incremental backup 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>&1Check backup logs for normal operation and verify obsolete backups and archivelogs are deleted correctly.
Monitoring Query
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