Rman backup command
1: to back the controlfile using rman
Backup Control File
Run {
Allocate channel dev1 type disk format 'C: backup % U ';
Backup current controlfile;
}
2: to check the backup of controlfile using rman:
Check the backup control file
List backup of controlfile;
3: to recover using backup controlfile (startup nomount)
Restore Control File
Run {
Allocate channel dev1 type disk;
Restore controlfile;
Alter database mount;
Restore database;
Recover database;
SQL "ALTER DATABASE OPEN RESETLOGS"
}
4: backup all datafile and controlfile using rman:
Back up all data files and Control Files
Run {
Allocate channel dev1 type disk;
Backup full tag = 'fullbackup' database include current controlfile format = 'C: backupdb_t % t_s % s_p % P ';
Release channel dev1;
}
5: check all backup of datafiles using rman:
Check all data files and Control Files
List backupset;
6: to restore because of missing file (first mount the database and run RMAN)
Repair due to file loss
Run {
Allocate channel dev1 type disk;
Restore database;
Recover database;
}
7: restore until time
Restore to a certain time point
The 'set UNTIL time' must match with the variable NLS_DATE_FORMAT.
Prior logging on RMAN set the NLS_DATE_FORMAT in the desired format.
For example:
If unix ==> export NLS_DATE_FORMAT = 'yyyy-MM-DD: HH24: MI: ss ';
If on windows nt ==> set this vaiable in the registery.
Run {
Set until time 'may 1 2000 08:00:00 ';
Allocate channel dev1 type disk;
Shutdown abort;
Startup nomount;
Restore controlfile;
Alter database mount;
Restore database;
Recover database;
SQL 'alter database open resetlogs ';
}
8: to purge obsolete backups:
Clear old backup
Report obsolete redundancy 3 device type disk; # reports any backup with more than 3 COPIES
Report obsolete orphan; # USE THIS REPORT TO FILL IN THE XXXXX BELOW
Run {
Allocate channel for maintenance type disk;
Allocate channel for delete type disk;
Change backuppiece 'C: backupxx' delete;
Release channel;
Run {
Allocate channel for maintenance type disk;
Allocate channel for delete type disk;
Change datafilecopy 'C: backupxx' delete;
Release channel;
9: to backup all archive logs
Back up all archived logs
Run {
Allocate channel dev1 type disk format 'C: backup % U ';
Backup archivelog all;
}
10: to remove all archive log files alter backup update to this line
Backup archivelog all delete input;
11: skip an archive log file that can not be read or manualy deleted update to this line
Backup archivelog skip inaccessible/inaccessible
12: to remove one archive log that you manualy deleted and now get an rman-6089 <= 8.0
Allocate channel for delete type disk; or 'sbt _ TAPE ';
Change archivelog 'path/filename' delete;
And/or
Resync catalog;
13: to remove one archive log that you manualy deleted and now get an rman-6089 <= 8.1
Allocate channel for maintenance type ....'
Change archivelog uncatalog
A Practical script, including shell scripts for backing up RAC databases and archiving logs
[Oracle @ db worksh] $ more rmanback. sh
#! /Bin/sh
# Set env
Export ORACLE_HOME =/opt/oracle/product/9.2
Export ORACLE_SID = ebiz
Export NLS_LANG = "AMERICAN_AMERICA.zhs16gbk"
Export PATH = $ PATH: $ ORACLE_HOME/bin:/sbin:/usr/sbin
Echo "------------------------------- start -----------------------------"; date
# Backup start
$ ORACLE_HOME/bin/rman <EOF
Connect target
Delete noprompt obsolete;
Backup database include current controlfile format '/rmanback/db2/% U _ % s. bak' filesperset = 2;
Run {
Allocate channel node_c1 device type disk connect 'sys/pass @ db1in1 ';
Allocate channel node_c2 device type disk connect 'sys/pass @ db2in2 ';
SQL 'alter SYSTEM ARCHIVE LOG current ';
Backup archivelog all delete input format'/rmanback/db2/% U _ % s. bak 'filesperset = 5;
}
List backup;
Exit;
EOF
Echo "------------------------------ end ------------------------------"; date
Replace script backup_db_full {
#
# Backs up the whole database into backup-sets. This backup is not part
Execute script alloc_all_tapes;
Execute script set_maxcompute upt;
Backup
Full
# Skip offline
# Skip readonly
Skip inaccessible
Tag B _db_full
Filesperset 6
Format 'df _ t % t_s % s_p % P'
Database;
Execute script rel_all_tapes;
Execute script archive_log_current;
Execute script backup_al_all;
}
Replace script backup_db_level_0 {
#
# Backs up the whole database. This backup is part of the incremental
# Strategy.
# It performs exactly the same backup as the script backup above, cannot
# The datafile backup is part of the incremental strategy (this means it
# Can have incremental backups of levels> 0 applied to it-full backups
# Cannot ).
#
# Typically, a level 0 backup wocould be done at least once a week.
#
# Modified By Reason
#961219 cd created
#
Execute script alloc_all_tapes;
Execute script set_maxcompute upt;
Backup
Incremental level 0
# Skip offline
# Skip readonly
Skip inaccessible
Tag backup_db_level_0
Filesperset 6
Format 'df _ t % t_s % s_p % P'
Database;
Execute script rel_all_tapes;
Execute script archive_log_current;
Execute script backup_al_all;
}
Replace script backup_db_level_1 {
#
# This backup will only backup blocks which have been modified since
# Last level 0 backup was completed MED. Otherwise it is exactly the same
# Backup as the level 0 above (note, the controlfile is always backed up in
# It's entirety I. e. control file backups are never compressed ).
#
# Typically, a level 1 backup wocould be done at least once in between level
#0 backups.
#
# Modified By Reason
#961219 cd created
#
Execute script alloc_all_tapes;
Execute script set_maxcompute upt;
Backup
Incremental level 1
# Skip offline
# Skip readonly
Skip inaccessible
Tag backup_db_level_1
Filesperset 6
Format 'df _ t % t_s % s_p % P'
Database;
Execute script rel_all_tapes;
Execute script archive_log_current;
Execute script backup_al_all;
}
Replace script backup_db_level_2 {
#
# This backup will only backup blocks which have been modified since
# Last level 0 or 1 backup was completed MED. Otherwise it is exactly the same
# Backup as the level 0 or 1 backups above.
#
# Typically, a level 2 backup wocould be done at least once in between level
#0 and 1 backups.
#
# Modified By Reason
#961219 cd created
#
Execute script alloc_all_tapes;
Execute script set_maxcompute upt;
Backup
Incremental level 2
# Skip offline
# Skip readonly
Skip inaccessible
Tag backup_db_level_2
Filesperset 6
Format 'df _ t % t_s % s_p % P'
Database;
Execute script rel_all_tapes;
Execute script archive_log_current;
Execute script backup_al_all;
Author: "Rman full Backup Recovery"