RMAN BACKUP SHELL SCRIPT

Bu örneğimizde veritabanımız için 3 günde bir gece 03:00 da full backup alsın hergün incremental Level -1 backup, bu arada bloack change tracking file oluşturup bu dosyayıda enable yapalım, 6 saatte birde archive loğların yedeğini alsın, şeklinde bir kurguyu script olarak hazırlamaya çalışalım.

Burada işlemci sayımıza göre uygun bir channel sayısı ayarlanmalıdır. Ben 8 channel ile 8 parallelik derecesinde backup alıyorum siz kendi sisteminize ve ihtiyacınıza göre artırıp azaltabilirsiniz.

Level 0 full backup için scriptimizi oluşturalım, daha sonra oluşturduğumuz scriptleri crontab a ekleyeceğiz.

vi /u01/scripts/rman_L0.sh
export TIME=$(date +"%Y%m%d")
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/db
export ORACLE_SID=frkdb
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
rman target / < /u01/scripts/rman_L0.scr > /u01/scripts/log/rman_full'date +\%Y\%m\%d\_%H\%M'.log

rman_L0.scr dosyamızı hazırlayalım

vi /u01/scripts/rman_L0.scr

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;
ALLOCATE CHANNEL c7 DEVICE TYPE disk;
ALLOCATE CHANNEL c8 DEVICE TYPE disk;
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 database tag FRKDB_FULL format '/data/backup/%d_%T_%s_%p_FULL' ;
sql 'alter system archive log current';
BACKUP AS COMPRESSED BACKUPSET tag FRKDB_ARCHIVE format '/data/backup/%d_%T_%s_%p_ARCHIVE' archivelog all not backed up 1 times;
BACKUP tag FRKDB_CONTROL current controlfile format '/data/backup/%d_%T_%s_%p_CONTROL';
DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 4 DAYS;
CROSSCHECK ARCHIVELOG ALL;
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}

Archive log backupları için;

vi /u01/scripts/rman_archive.sh

export TIME=$(date +"%Y%m%d")
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/db
export ORACLE_SID=frkdb
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
rman target / < /u01/scripts/rman_archive.scr > /u01/scripts/log/rman_archive'date +\%Y\%m\%d\_%H\%M'.log

rman_archive.scr dosyasını hazırlayalım

vi /u01/scripts/rman_archive.scr

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;
ALLOCATE CHANNEL c7 DEVICE TYPE disk;
ALLOCATE CHANNEL c8 DEVICE TYPE disk;
BACKUP tag FRKDB_ARCHIVE format '/data/backup/%d_%T_%s_%p_ARCHIVE' archivelog all not backed up 1 times ;
DELETE NOPROMPT ARCHIVELOG ALL completed before 'sysdate-1';
DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 4 DAYS;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}

L1 Backup ları için ;

export TIME=$(date +"%Y%m%d")
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/db
export ORACLE_SID=frkdb
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
rman target / < /u01/scripts/rman_L1.scr > /u01/scripts/log/rman_full'date +\%Y\%m\%d\_%H\%M'.log

rman_L1.scr dosyasıı hazırlayalım;

vi /u01/scripts/rman_L1.sh

export TIME=$(date +"%Y%m%d")
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/19.0.0.0/db
export ORACLE_SID=frkdb
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
rman target / < /u01/scripts/rman_L1.scr > /u01/scripts/log/rman_incr'date +\%Y\%m\%d\_%H\%M'.log

rman_L1.scr dosyasını hazırlayalım ;

vi /u01/scripts/rman_L1.src

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;
ALLOCATE CHANNEL c7 DEVICE TYPE disk;
ALLOCATE CHANNEL c8 DEVICE TYPE disk;
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1 database tag FRKDB_INCR format '/data/backup/%d_%T_%s_%p_INCR' ;
sql 'alter system archive log current';
BACKUP AS COMPRESSED BACKUPSET tag FRKDB_ARCHIVE format '/data/backup/%d_%T_%s_%p_ARCHIVE' archivelog all not backed up 1 times;
BACKUP tag FRKDB_CONTROL current controlfile format '/data/backup/%d_%T_%s_%p_CONTROL';
DELETE NOPROMPT OBSOLETE RECOVERY WINDOW OF 4 DAYS;
CROSSCHECK ARCHIVELOG ALL;
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
release channel c6;
release channel c7;
release channel c8;
}
Şimdi bu oluşturdğumuz scriptleri Linux crotab a ekleyerek backuplarımızın otomatik olarak çalışmasını sağlayalım
Crotab –e

#3 günde bir full backup için;

30 3 1,4,7,10,13,16,19,22,25,28 * * /u01/scripts/rman_L0.sh > /u01/scripts/log/rman_L0_cron.log 2>&1

# 6 saatte bir ARCHIVELOG backup

00 0,6,12,18 * * * /u01/scripts/rman_archive.sh > /u01/scripts/log/rman_archive_cron.log 2>&1

#Her gün L1 backup için 

00 00 * * * /u01/scripts/rman_L1.sh >   /u01/scripts/log/rman_L1_cron.log 2>&1
Block change tracking file ayarlaması için öncelikli olarak block change tracking durumunu kontrol edelim
SQL> select filename, status, bytes from v$block_change_tracking;

FILENAME STATUS BYTES
---------- ----------
       DISABLED
SQL> alter database enable block change tracking using file '/data/block_change_tracking.dbf';
SQL> select filename, status, bytes from $block_change_tracking;

FILENAME                         STATUS          BYTES

/data/block_change_tracking.dbf  ENABLED      11599872