Preparation of RMAN backup policy for the DG Environment Database
Preparation of RMAN backup policy for the DG Environment Database:
Primary database (Primary)
Full database backup
Archive backup
Delete historical folders
Standby database (Standby)
Delete Archive
References
Primary database (Primary)
$ Crontab-l
0 1 ***/usr2/backupsh/full_backup.rman
0 */2 ***/usr2/backupsh/arch_backup.rman
0 3 ***/usr2/backupsh/del_old.sh full-Database Backup
More/usr2/backupsh/full_backup.rman
#! /Bin/bash
Foldername = 'date + % Y % m % d'
Cd/usr2/BACKUP
If [-d $ foldername]
Then
Echo 'go on'
Else
Echo 'need mkdir'
Mkdir $ foldername
Fi
Export Oracle_SID = jyzhao
Export ORACLE_BASE =/opt/app
Export ORACLE_HOME =/opt/app/oracle/product/11.2.0/db_1
Export PATH = $ PATH: $ ORACLE_HOME/bin: $ HOME/bin
# Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
# Export NLS_LANG = "simplified chinese_china.ZHS16GBK"
# Export NLS_DATE_FORMAT = "YYYY-MM-DD HH24: Mi: SS"
Rman target/log =/usr2/BACKUP/$ foldername/LOG_full _ $ foldername. log <EOF
Run {
Configure retention policy to recovery window of 5 days;
Configure controlfile autobackup on;
Configure controlfile autobackup format for device type disk to '/usr2/BACKUP/$ foldername/controlfile % F ';
Configure archivelog deletion policy to applied on all standby;
Allocate channel c1 device type disk;
Allocate channel c2 device type disk;
Allocate channel c3 device type disk;
Allocate channel c4 device type disk;
# Backup database skip inaccessible
Backup incremental level = 0 database
Format '/usr2/BACKUP/$ foldername/full_BACK _ % U ';
Release channel c1;
Release channel c2;
Release channel c3;
Release channel c4;
}
Allocate channel for maintenance device type disk;
Crosscheck backupset;
Delete noprompt expired backupset;
Delete noprompt obsolete;
Exit
EOF archive backup
More/usr2/backupsh/arch_backup.rman
#! /Bin/bash
Foldername = 'date + % Y % m % d'
Cd/usr2/BACKUP
If [-d $ foldername]
Then
Echo 'go on'
Else
Echo 'need mkdir'
Mkdir $ foldername
Fi
Export ORACLE_SID = jyzhao
Export ORACLE_BASE =/opt/app
Export ORACLE_HOME =/opt/app/oracle/product/11.2.0/db_1
Export PATH = $ PATH: $ ORACLE_HOME/bin: $ HOME/bin
# Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
# Export NLS_LANG = "simplified chinese_china.ZHS16GBK"
# Export NLS_DATE_FORMAT = "YYYY-MM-DD HH24: Mi: SS"
Rman target/log =/usr2/BACKUP/$ foldername/LOG_arch _ $ foldername. log append <EOF
Run {
Configure retention policy to recovery window of 5 days;
Configure controlfile autobackup on;
Configure controlfile autobackup format for device type disk to '/usr2/BACKUP/$ foldername/controlfile % F ';
Configure archivelog deletion policy to applied on all standby;
Allocate channel c1 device type disk;
Allocate channel c2 device type disk;
Allocate channel c3 device type disk;
Allocate channel c4 device type disk;
# Backup database skip inaccessible
Backup archivelog all delete input
Format '/usr2/BACKUP/$ foldername/arch_BACK _ % U ';
Release channel c1;
Release channel c2;
Release channel c3;
Release channel c4;
}
Allocate channel for maintenance device type disk;
Crosscheck backupset;
Delete noprompt expired backupset;
Delete noprompt obsolete;
Exit
EOF Delete history folder
More/usr2/backupsh/del_old.sh
#! /Bin/bash
# Del old folders
Cd/usr2/BACKUP
Find.-mtime + 7 | xargs rm-rf Standby database (Standby)
$ Crontab-l
0 3 ***/usr2/del_arch/del_arch.sh delete an archive
More/usr2/del_arch/del_arch.sh
#! /Bin/bash
Export ORACLE_SID = jyzhao_s
Export ORACLE_HOME =/opt/app/oracle/product/11.2.0/db_1
Export ARCHIVE_DIR =/usr2/oradata/archivelog
Export LOG_FILE =/usr2/oradata/archivelog/del_archive.log
Echo "start to delete the archive log: 'date '...... ">>> $ LOG_FILE
If ['whoam '! = 'Oracle ']
Then
Echo "Error: You must be oracle to execute."> $ LOG_FILE
Exit 99
Fi
Del_seq = 'LS-tr $ ARCHIVE_DIR/| grep-v stdarch | head-1 | cut-f2-d _'
$ ORACLE_HOME/bin/sqlplus-silent "/as sysdba" <XFF> tmp. log
Set pagesize 0 feedback off verify off heading off echo off
Select max (sequence #) from v \ $ ARCHIVED_LOG where APPLIED = 'yes ';
Exit;
XFF
Max_sn = 'cat tmp. Log'
Rm tmp. log
Max_sn = $ ($ max_sn-20 ))
# I keep the last 20 archive files here. I will decide the specific situation.
While [[$ {del_seq}-lt $ {max_sn}]
Do
Echo "$ {ARCHIVE_DIR}/1 _ $ {del_seq} _ 830355509.dbf"> $ LOG_FILE
Rm ${ARCHIVE_DIR}/1 _ $ {del_seq} _ 830355509.dbf
# Here I define the format of the archive file. The key is matching the log sequence no according to the format of my archive file.
Del_seq = $ ($ del_seq + 1 ))
Done
Echo "End of deleting the archive log: 'date '...... ">>> $ LOG_FILE
# Clear information in controlfile
$ ORACLE_HOME/bin/rman target/<XIFENFEI> $ LOG_FILE
Crosscheck archivelog all;
Delete expired archivelog all;
YES
Exit;
XIFENFEI
Echo ".................................................................................................................. ..................... ">>> $ LOG_FILE
-------------------------------------- Recommended reading --------------------------------------
RMAN: Configure an archive log deletion policy
Basic Oracle tutorial-copying a database through RMAN
Reference for RMAN backup policy formulation
RMAN backup learning notes
Oracle Database Backup encryption RMAN Encryption
-------------------------------------- Split line --------------------------------------