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
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
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
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
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
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
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
Post a Comment