Skip to main content

Oracle Database RMAN Backup Script

RMAN Backup Script
Oracle Recovery Manager (RMAN) is a comprehensive tool designed to efficiently back up and recover Oracle databases. It works closely with the server, providing block-level corruption detection during backup and restore. RMAN backups are created using the 'BACKUP' command. The primary purpose of RMAN backups is to protect your data. In the event of a media failure or disaster, you can restore your backups and recover lost changes.

For more detailed information about RMAN backup concepts, you can refer to the Oracle Help Center. Additionally, if you are interested in creating an Oracle database backup using RMAN, you can find step-by-step instructions on how to do so in the Oracle-Patches website.

archivelog_not_backed_up.sh
cat /home/oracle/.scripts/archivelog_not_backed_up.sh

#!/bin/bash
echo 'Backup start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/archivelog_not_backed_up.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL NOT BACKED UP 1 TIMES TAG 'ARCH_NOT_BACKED_UP_ARCH';
BACKUP CURRENT CONTROLFILE TAG 'ARCH_NOT_BACKED_UP_CONTROLFILE';
BACKUP SPFILE TAG 'ARCH_NOT_BACKED_UP_SPFILE';
}
exit
EOF
echo 'Backup end............................................'$(date)

archivelog_all_backup.sh
cat /home/oracle/.scripts/archivelog_all_backup.sh

#!/bin/bash
echo 'Backup start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/archivelog_all_backup.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL TAG 'ARCH_ALL_BACKUP_ARCH';
BACKUP CURRENT CONTROLFILE TAG 'ARCH_ALL_BACKUP_CONTROLFILE';
BACKUP SPFILE TAG 'ARCH_ALL_BACKUP_SPFILE';
}
exit
EOF
echo 'Backup end............................................'$(date)

differential_incremental_backup.sh
cat /home/oracle/.scripts/differential_incremental_backup.sh

#!/bin/bash
echo 'Backup start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/differential_incremental_backup.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
BACKUP INCREMENTAL LEVEL 1 DATABASE TAG 'DIFF_INC_BAK_DATABASE';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL TAG 'DIFF_INC_BAK_ARCHIVELOG';
BACKUP CURRENT CONTROLFILE TAG 'DIFF_INC_BAK_CONTROLFILE';
BACKUP SPFILE TAG 'DIFF_INC_BAK_SPFILE';
}
exit
EOF
echo 'Backup end............................................'$(date)

cumulative_incremental_backup.sh
cat /home/oracle/.scripts/cumulative_incremental_backup.sh

#!/bin/bash
echo 'Backup start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/cumulative_incremental_backup.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE TAG 'CUM_INC_BAK_DATABASE';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL TAG 'CUM_INC_BAK_ARCHIVELOG';
BACKUP CURRENT CONTROLFILE TAG 'CUM_INC_BAK_CONTROLFILE';
BACKUP SPFILE TAG 'CUM_INC_BAK_SPFILE';
}
exit
EOF
echo 'Backup end............................................'$(date)

full_backup.sh
cat /home/oracle/.scripts/full_backup.sh

#!/bin/bash
echo 'Backup start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/full_backup.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
BACKUP DATABASE TAG 'FULL_BACKUP_DATABASE';
SQL 'ALTER SYSTEM ARCHIVE LOG CURRENT';
BACKUP ARCHIVELOG ALL TAG 'FULL_BACKUP_ARCHIVELOG';
BACKUP CURRENT CONTROLFILE TAG 'FULL_BACKUP_CONTROLFILE';
BACKUP SPFILE TAG 'FULL_BACKUP_SPFILE';
}
exit
EOF
echo 'Backup end............................................'$(date)

rman_verify.sh
cat /home/oracle/.scripts/rman_verify.sh

#!/bin/bash
echo 'rman verify start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/rman_verify.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect target /
RUN
{
CROSSCHECK BACKUP;
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE NOPROMPT OBSOLETE;
#SQL 'select CORRUPTION_TYPE from v$database_block_corruption';
backup validate database;
}
exit
EOF
echo 'rman verify end............................................'$(date)

duplicate.sh
cat /home/oracle/.scripts/duplicate.sh

#!/bin/bash
echo 'Cloning start............................................'$(date)
export ORACLE_HOSTNAME=<dbserver>
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/12c/dbhome_1
export ORACLE_UNQNAME=<dbuniquename>
export DB_UNIQUE_NAME=<dbuniquename>
export ORACLE_DBNAME=<dbname>
export ORACLE_SID=<dbsid>
export BACKUP_LOG_PATH=/home/oracle/.scripts/
LOG_FILE=${BACKUP_LOG_PATH}/duplicate.log
${ORACLE_HOME}/bin/rman msglog=${LOG_FILE} << EOF
connect TARGET sys/<sys_password>@<10.10.10.10>:1521/CBSDGDB3 #10.10.10.10 = Production or Primary Database IP
connect AUXILIARY sys/<sys_password>@<20.20.20.20>:1521/<dbuniquename> #10.10.10.10 = Will be Created Database IP
RUN
{
DUPLICATE TARGET DATABASE TO <will_be_Created_DB_NAME> FROM ACTIVE DATABASE NOFILENAMECHECK;
}
exit
EOF
echo 'Cloning end............................................'$(date)


Cron Job List

#5 2 * * 5 /home/oracle/.scripts/duplicate.sh
##17 13 * * * /home/oracle/.scripts/archivelog_all_backup.sh
#*/10 5-18 * * 0,1,2,3,4,5,6 /home/oracle/.scripts/archivelog_not_backed_up.sh
##17 19 * * 0,1,2,3,6 /home/oracle/.scripts/cumulative_incremental_backup.sh
#17 19 * * 0,1,2,3,4,5,6 /home/oracle/.scripts/differential_incremental_backup.sh
#17 20 * * 4 /home/oracle/.scripts/full_backup.sh
#17 11 * * 5 /home/oracle/.scripts/rman_verify.sh

Comments

Popular posts from this blog

Upgrading Issue for RHEL 7 to 8 With Leapp

Overview The Leapp utility is a framework for updating and upgrading operating systems as well as applications. The operations of this utility consist of two phases 1. the preupgrade Phase – that chack the upgrade possibilities and 2. the actual upgrade phase – that map packages between previous and current versions of the software packages. Issue – 01: After running ‘ sudo leapp preupgrade ‘ sometimes you find the below issue in ‘ /var/log/leapp/leapp-report.txt ‘. Detail: Risk Factor: high (inhibitor) Title: Leapp detected loaded kernel drivers which have been removed in RHEL 8. Upgrade cannot proceed. Summary: Support for the following RHEL 7 device drivers has been removed in RHEL 8: – pata_acpi Key: f08a07da902958defa4f5c2699fae9ec2eb67c5b Remediation: 1. Disable detected kernel drivers in order to proceed with the upgrade process using the rmmod or modprobe -r . rmmod – Simple program to remove a module from the Linux Kernel modprobe – Add and remove modules from the Linux Ke...

Upgrading Oracle Linux 6 to 7

Overview It is possible to upgrade an Oracle Linux 6 system to Oracle Linux 7.6 under the following conditions: The system meets the minimum installation requirements for Oracle Linux 7 as described in Chapter 1, System Requirements and Limits. The Oracle Linux 6 system has been completely updated from the ol6_x86_64_latest channel or ol6_latest repository. UEK R3 or UEK R4 has been installed on the system to be upgraded and is the default boot kernel. Upgrading from UEK R2 is not supported. Note that the system is upgraded to use the UEK R5 release provided with Oracle Linux 7.6. Upgrading is supported only for systems that are installed with the Minimal Install base environment. If additional packages are installed from an alternative repository or channel, upgrade might fail or the resulting upgrade might not function as expected. reference: https://docs.oracle.com/en/operating-systems/oracle-linux/7/relnotes7.6/ol7-install.html#ol7-upgrade-ol6 Verifying the system before Upgrade: #...

Install Oracle Database 12c Release 2 On Red Hat 8

Overview According to Oracle, Oracle Database 12c is ‘the first database designed for the cloud’; the suffix ‘c’ stands for the cloud. There are many new features in this release such as multitenant architecture, pluggable database, in-memory, etc. The multitenant architecture is designed to simplify consolidation without requiring any changes to the applications. The rapid provisioning and portability capabilities are enhanced by the pluggable databases. Another new feature is in-memory makes it the first Oracle database to offer real-time analytics. This article describes the installation of Oracle Database 12c release 2 (12.2.0.1.0) 64-bit on Red Hat 8 64-bit. Lab Environment Server Machine Work Station or Client Machine OS Release Red Hat Enterprise Linux release 8.4 (Ootpa) Red Hat Enterprise Linux release 8.4 (Ootpa) Kernel 4.18.0-305.3.1.el8_4.x86_64 4.18.0-305.7.1.el8_4.x86_64 Release Oracle Database 12.1.0.2.0 Oracle SQL Developer Version 19.2.1.247 IP Address 192.168.201.116 ...