Wednesday, October 30, 2019

RMAN Scripts


Take a RMAN Full backup :


rman target /
sql 'alter system archive log current';
sql "alter session set nls_date_format=''dd.mm.yyyy hh24:mi:ss''";
RUN
{
configure controlfile autobackup on;
ALLOCATE CHANNEL c1 DEVICE TYPE disk;
ALLOCATE CHANNEL c2 DEVICE TYPE disk;
ALLOCATE CHANNEL c3 DEVICE TYPE disk;
ALLOCATE CHANNEL c4 DEVICE TYPE disk;
ALLOCATE CHANNEL c5 DEVICE TYPE disk;
ALLOCATE CHANNEL c6 DEVICE TYPE disk;
backup AS COMPRESSED BACKUPSET full database tag FULL_DB_BKP format '/u04/backup/%d_%T_%s_%p_FULL' ;
sql 'alter system archive log current';
backup tag DB_ARCH format '/u04/backup/%d_%T_%s_%p_ARCHIVE' archivelog all delete all input ;
backup tag DB_CTL current controlfile format '/u04/backup/%d_%T_%s_%p_CONTROL';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
}

Another Script we might use depending on requirement :

run {
allocate channel t1 TYPE DISK FORMAT '/backup/RMAN//%d_%t_%p_%s_%c_%u.bkp';
allocate channel t2 TYPE DISK FORMAT '/backup/RMAN/%d_%t_%p_%s_%c_%u.bkp';
allocate channel t3 TYPE DISK FORMAT '/backup/RMAN/%d_%t_%p_%s_%c_%u.bkp';
crosscheck archivelog all;
backup current controlfile FORMAT '/backup/RMAN/%d_%t_%p_%s_%c_%u.bkp';
delete NOPROMPT archivelog until time 'SYSDATE-1' ;
sql 'alter system archive log current';
DELETE ARCHIVELOG ALL COMPLETED BEFORE ‘sysdate-1’;
backup archivelog all delete input
backup archivelog from time 'SYSDATE-2';
crosscheck backup;
crosscheck archivelog all;
delete NOPROMPT archivelog until time 'SYSDATE-2' ;
delete noprompt obsolete device type disk;
release channel t1;
release channel t2;
release channel t3;
}

Take a RMAN cold backup :

shutdown immediate ;
startup mount ;    - Only one instance if RAC

rman 
connect target /


Rman> Spool log to '/u04/backup/DB_COLD_BKP.log'

Rman > run { allocate channel c1 device type disk ;
             allocate channel c2 device type disk ;
             allocate channel c3 device type disk ;
             allocate channel c4 device type disk ;
             backup database tag='COLD_BKP' format '/u04/backup/DB_COLD_s%s_p%p-t%T.bck';
             backup tag='COLD_BKP' format '/u04/backup/%d_cfile_s%s_p%p_open.bck' current controlfile;
             backup spfile format '/u04/backup/%d_spfile_s%s_p%p_%T_dbid%I.rman';
             sql 'alter database backup controlfile to TRACE';
             release channel c1;  
             release channel c2;
             release channel c3;
             release channel c4;
             }

Take a RMAN Level 0 backup :

connect target /
connect catalog rcat/********@rcat
run {
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup filesperset 10 INCREMENTAL LEVEL 0 CUMULATIVE database tag
'LEVEL_0' format
'/u04/backup/rman/PROD_dbf-level-0_s%s_p%p-t%T.bck'
plus archivelog tag 'LEVEL_0' format
'/u04/backup/rman/PROD_arch-level-0_s%s_p%p-t%T.bck';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}


To see backup status :

SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
       ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%'
  AND OPNAME NOT LIKE '%aggregate%'
  AND TOTALWORK != 0
  AND SOFAR  != TOTALWORK
;

No comments:

Post a Comment