Oracle ‐ More Scripts - shaysalomon12/Data-Engineer GitHub Wiki

RMAN Scripts

  • Backup script that will be activated from crontab
#!/bin/bash

##############################################################################
# Shell script to take incremental level 0 backup
#
# usage: c:\> <script_name> <oracle_sid> <oracle_home>
#
# Backup file names:
# %d - Database name
# %T - 8-character name constituted by compressed representations of the backup
#      set or image copy number and the time the backup set or image copy was
#      created.
# %p - Piece number within backup set
# %s - Backup set number
# %t - Backup set time stamp,
# %U - A system-generated unique filename (default).
###############################################################################

ORACLE_SID=$1
ORACLE_HOME=$2

scripts_dir=/home/oracle
backup_dir=/home/oracle/rman_backup/$1


echo '$backup_dir - ' $backup_dir
echo 'RMAN logs:    ' $scripts_dir/rman_incremental_level_0.log

# Daily incremental_commulative_level_1
$ORACLE_HOME/bin/rman target / cmdfile=$scripts_dir/rman_incremental_commulative_level_1.cmd log=$scripts_dir/rman_incremental_commulative_level_1.log

# Weekly incremental_level_0
$ORACLE_HOME/bin/rman target / cmdfile=$scripts_dir/rman_incremental_level_0.cmd log=$scripts_dir/rman_incremental_level_0.log
  • RMAN incremental level 0 (Weekly Backup)
# rman_incremental_level_0.cmd (Weekly)
# =====================================
run {
#backup Database
report schema;
show all;
sql 'alter database backup controlfile to trace';
 
# Crosscheck
crosscheck archivelog all;
crosscheck backup;
crosscheck backup of controlfile;
 
backup as compressed backupset tag 'DB_LEVEL0' format '/home/oracle/rman_backup/XE/database_L0_%d_%T_%s_%p' incremental level 0 database plus archivelog format '/home/oracle/rman_backup/XE/archivelog_%d_%T_%s_%p';
backup as compressed backupset tag 'controlfile' format '/home/oracle/rman_backup/XE/controlfile_%d_%T_%s_%p' current controlfile;
backup as compressed backupset tag 'spfile'  format '/home/oracle/rman_backup/XE/spfile_%d_%T_%s_%p' spfile;
 
# Check if Backup Set is Valid
# restore database validate;
 
# Delete Old Files
delete force noprompt obsolete;
delete force noprompt expired backup;
delete noprompt archivelog until time 'sysdate-30' backed up 1 times to device type disk;
 
# Configure Defaults
configure controlfile autobackup format for device type disk to '/home/oracle/rman_backup/XE/controlfile_%F';
configure retention policy to recovery window of 30 days;
configure ARCHIVELOG DELETION POLICY to none;
}
  • RMAN incremental commulative level 1 (Daily Backup)
# rman_incremental_commulative_level_1.cmd (Daily)
# ================================================
run {
#backup Database
report schema;
show all;
sql 'alter database backup controlfile to trace';
 
# Crosscheck
crosscheck archivelog all;
crosscheck backup;
crosscheck backup of controlfile;
 
backup as compressed backupset tag 'DB_LEVEL1' format 'E:\oracle\rman\database_L1_%d_%T_%s_%p' INCREMENTAL LEVEL 1 CUMULATIVE  database plus archivelog format 'E:\oracle\rman\archivelog_%d_%T_%s_%p';
backup as compressed backupset tag 'controlfile' format 'E:\oracle\rman\controlfile_%d_%T_%s_%p' current controlfile;
backup as compressed backupset tag 'spfile' format 'E:\oracle\rman\spfile_%d_%T_%s_%p' spfile;
 
# Check if Backup Set is Valid
# restore database validate;
 
# Delete Old Files
delete force noprompt obsolete;
delete force noprompt expired backup;
delete noprompt archivelog until time 'sysdate-30' backed up 1 times to device type disk;
 
# Configure Defaults
configure controlfile autobackup format for device type disk to '/home/oracle/rman_backup/XE/controlfile_%F';
configure retention policy to recovery window of 30 days;
configure ARCHIVELOG DELETION POLICY to none;
}
⚠️ **GitHub.com Fallback** ⚠️