Disclaimer

Thursday 26 May 2022

RMAN backup scripts

############# RMAN BACKUP SCRIPT ###########################

00 1,3,5,7,9,11,13,15,17,19,21,23 * * * sh /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_ARCH.sh
00 04 * * 0,1,2,4,5,6 sh /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_INCR.sh
00 04 * * 3 sh /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_FULL.sh
#######Delete Obsolete ORCL########
00 23 *  * 0,1,2,3,4,5,6 /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_DELETE.sh

#Oracle Primary and Standby Database Sync Check Script
0 1,3,5,7,9,11,13,15,17,19,21,23 * * * sh /home/oracle/Scripts/dataguard_script/dg_ORCL.sh > /dev/null

====Archive log backup script========

[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_ARCH.sh
export ORACLE_BASE=/applications/oracle/d19.3.0/oracle_base
export ORACLE_HOME=/applications/oracle/d19.3.0/oracle_home
export PATH=$PATH:/$ORACLE_HOME/bin
export ORACLE_SID=ORCL1
export LIB_PATH=$ORACLE_HOME/lib
TS=$(/bin/date +"%Y-%m-%d_%H:%M:%S")
export TS
rman target / catalog rman/rman@RMANCAT @/mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_ARCH.rcv  >> /mnt/nfs/rman_dir/ORCL/backup_logs/rman_ORCL_ARCH$TS.log
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_ARCH.rcv
run
{
backup validate filesperset = 5 format '/mnt/nfs/rman_dir/ORCL/backup/%d_%T_%s_%p_ARCH' archivelog all not backed up 2 times delete input;
backup filesperset = 5 format '/mnt/nfs/rman_dir/ORCL/backup/%d_%T_%s_%p_ARCH' archivelog all not backed up 2 times delete input;
}
[oracle@amasag01p Scripts]$

=======INCREMENTAL Backup Script============

[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_INCR.sh
export ORACLE_BASE=/applications/oracle/d19.3.0/oracle_base
export ORACLE_HOME=/applications/oracle/d19.3.0/oracle_home
export PATH=$PATH:/$ORACLE_HOME/bin
export ORACLE_SID=ORCL1
export LIB_PATH=$ORACLE_HOME/lib
TS=$(/bin/date +"%Y-%m-%d_%H:%M:%S")
export TS
rman target / catalog rman/rman@RMANCAT @/mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_INCR.rcv >> /mnt/nfs/rman_dir/ORCL/backup_logs/rman_ORCL_INCR$TS.log
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_INCR.rcv
run
{
backup INCREMENTAL LEVEL 1 database include current controlfile format '/mnt/nfs/rman_dir/ORCL/backup/INCR_%d_%s_%U';
}

=========RMAN Full Backup Script==========

[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_FULL.sh
export ORACLE_BASE=/applications/oracle/d19.3.0/oracle_base
export ORACLE_HOME=/applications/oracle/d19.3.0/oracle_home
export PATH=$PATH:/$ORACLE_HOME/bin
export ORACLE_SID=ORCL1
export LIB_PATH=$ORACLE_HOME/lib
TS=$(/bin/date +"%Y-%m-%d_%H:%M:%S")
export TS
rman target / catalog rman/rman@RMANCAT @/mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_FULL.rcv >> /mnt/nfs/rman_dir/ORCL/backup_logs/rman_ORCL_FULL$TS.log
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_FULL.rcv
run
{
backup INCREMENTAL LEVEL 0 database include current controlfile format '/mnt/nfs/rman_dir/ORCL/backup/FULL_%d_%s_%U';
}

===============Delete Obsolete Backup Script=============== 
[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_DELETE.sh
export PATH
export ORACLE_BASE=/applications/oracle/d19.3.0/oracle_base
export ORACLE_HOME=/applications/oracle/d19.3.0/oracle_home
export PATH=$PATH:/$ORACLE_HOME/bin
export ORACLE_SID=ORCL1
export LIB_PATH=$ORACLE_HOME/lib
TS=$(/bin/date +"%Y-%m-%d_%H:%M:%S")
export TS
rman target / catalog rman/rman@RMANCAT  @/mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_DELETE.rcv >> /mnt/nfs/rman_dir/ORCL/delete_obsolete/rman_ORCL_DELETE$TS.log
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$
[oracle@amasag01p Scripts]$ cat /mnt/nfs/rman_dir/ORCL/backup_scripts/rman_ORCL_DELETE.rcv
run
{
delete obsolete;
}

========Standby Archive Log Deletion Script=======================


[oracle@amasag01p ~]$ crontab -l
###Standby Archivelog Deletion##
00 22 * * 2,4,6 /home/oracle/stdby_archive_deletion_script/ORCLDG_stdby_archive_deletion.sh
[oracle@amasag01p ~]$
[oracle@amasag01p ~]$
[oracle@amasag01p ~]$
[oracle@amasag01p ~]$
[oracle@amasag01p ~]$ cat /home/oracle/stdby_archive_deletion_script/ORCLDG_stdby_archive_deletion.sh
#!/bin/ksh
#
#
# Remove applied archivelog;
#
#
#export DATE=$(date +%m%d%y_%H%M%S)
ORACLE_SID=ORCLDG; export ORACLE_SID
ORACLE_BASE=/applications/oracle/d19.3.0/oracle_base; export ORACLE_BASE
ORACLE_HOME=/applications/oracle/d19.3.0/oracle_home; export ORACLE_HOME

logfile=/home/oracle/stdby_archive_deletion_script/ORCLDG_Max_sequence.txt
logfile1=/home/oracle/stdby_archive_deletion_script/ORCLDG_GAP.txt
logfile2=/home/oracle/stdby_archive_deletion_script/ORCLDG_Diskdrp_space.txt
rmanfile=/home/oracle/stdby_archive_deletion_script/ORCLDG_rman.cmd
$ORACLE_HOME/bin/sqlplus -S /nolog <<EOF > $logfile
connect / as sysdba
set head off
set pages 0
select max(sequence#) from v\$archived_log where applied = 'YES';
exit
EOF
strin=`awk '{print $1 = $1 - 100}' $logfile`
strin2=`echo $strin | cut -d" " -f1`
#echo $strin2
echo "delete noprompt archivelog until time 'sysdate- 2';" > $rmanfile
$ORACLE_HOME/bin/rman target / <<EOF
@$rmanfile
exit
EOF
$ORACLE_HOME/bin/sqlplus -S /nolog <<EOF > $logfile1
connect / as sysdba
SELECT ARCH.THREAD# "Thread",
       ARCH.SEQUENCE# "Last Sequence Received",
       APPL.SEQUENCE# "Last Sequence Applied",
       (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"
FROM
(SELECT THREAD# ,SEQUENCE# FROM V\$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V\$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,
(SELECT THREAD# ,SEQUENCE# FROM V\$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V\$LOG_HISTORY GROUP BY THREAD#)) APPL
WHERE ARCH.THREAD# = APPL.THREAD#;
exit
EOF
$ORACLE_HOME/bin/sqlplus -S /nolog <<EOF > $logfile2
connect / as sysdba
set lines 200
set pages 200
SELECT G.NAME,
sum(b.total_mb) total_mb,
sum((b.total_mb - b.free_mb)) used_mb,
sum(B.FREE_MB)   free_mb,
decode(sum(b.total_mb),0,0,(ROUND((1- (sum(b.free_mb) / sum(b.total_mb)))*100, 2))) pct_used,
decode(sum(b.total_mb),0,0,(ROUND(((sum(b.free_mb) / sum(b.total_mb)))*100, 2))) pct_free
FROM v\$asm_disk b,v\$asm_diskgroup g
where b.group_number = g.group_number (+)
group by g.name;
exit
EOF
===================================================================




No comments:

Post a Comment

100 Oracle DBA Interview Questions and Answers

  Here are 100 tricky interview questions tailored for a Senior Oracle DBA role. These questions span a wide range of topics, including perf...