Oracle Technology Blog

OraTech Blog provides tips,tricks,scripts and how-to type answers for Oracle related technologies. I use these commands very often, so I thought it would be useful to share with everybody. Please feel free to include your comments/corrections/questions.

Wednesday, May 31, 2006

RMAN Archivelog Backup and Recovery Script

Backup

To Tape

$rman catalog rman_user/rman_password@rcat target /
RMAN> run {
# Archivelog backup
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
sql 'alter system archive log current';
backup
filesperset 20
skip inaccessible
format 'al_%s_%p_%t'
(archivelog all
delete input);
}

To Disk

run {
crosscheck archivelog all;
crosscheck backup of archivelog all;
delete expired archivelog all;
backup
format '/u12/backup/archive/%d_arch_%T_%U'
FILESPERSET 20
ARCHIVELOG ALL;
}

To Tape using stored script

We can store the above script in RMAN catalog as shown below.

RMAN> create script hot_archive_backup_level0 {
# Archivelog backup
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
sql 'alter system archive log current';
backup
filesperset 20
skip inaccessible
format 'al_%s_%p_%t'
(archivelog all
delete input);
}

This can be executed as
RMAN > run { hot_archive_backup_level0; }

Restore

From Tape

$rman catalog rman_user/rman_password@rcat target /
RMAN>run {
allocate channel t1 type 'SBT_TAPE';
allocate channel t2 type 'SBT_TAPE';
SET ARCHIVELOG DESTINATION TO '/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 1041 UNTIL SEQUENCE 1042;
}

From Disk

$rman catalog rman_user/rman_password@rcat target /
RMAN>run {
allocate channel d1 type disk format '/u12/backup/archive/%d_arch_%T_%U';
SET ARCHIVELOG DESTINATION TO '/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 71222UNTIL SEQUENCE 71223;
}

output:

$ rman catalog rmanuser/rmanpass@catdb target /

Recovery Manager: Release 9.2.0.6.0 - 64bit Production

Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.

connected to target database: MYDB (DBID=177653166)
connected to recovery catalog database

RMAN> run {
allocate channel d1 type disk format '/u12/backup/archive/%d_arch_%T_%U';
SET ARCHIVELOG DESTINATION TO '/tmp';
RESTORE ARCHIVELOG FROM SEQUENCE 71222UNTIL SEQUENCE 71223;
}2> 3> 4> 5>

allocated channel: d1
channel d1: sid=35 devtype=DISK

executing command: SET ARCHIVELOG DESTINATION

Starting restore at 15-JUN-06

channel d1: starting archive log restore to user-specified destination
archive log destination=/tmp
channel d1: restoring archive log
archive log thread=1 sequence=71222
channel d1: restoring archive log
archive log thread=1 sequence=71223
channel d1: restored backup piece 1
piece handle=/u12/backup/archive/MYDB_arch_20060615_i9hllscs_1_1 tag=TAG20060615T072352 params=NULL
channel d1: restore complete
Finished restore at 15-JUN-06
released channel: d1

RMAN> exit

Recovery Manager complete.


$ ls -ltr *.ARC
-rw-r----- 1 oracle dba 604672 Jun 15 12:42 T0001S0000071223.ARC
-rw-r----- 1 oracle dba 597504 Jun 15 12:42 T0001S0000071222.ARC

0 Comments:

Post a Comment

<< Home