Oracle_rman backup configuration reference document under Linux

Today, I published an oracle database rman backup configuration document under Linux for reference. At present, in many environments, I use this document for backup. If there is something wrong, please correct me. I will make corrections in the production environment.

1. Directory Settings

1.1. Rman backup instructions

 Backup level description
1. Level 0 full backup is the basis of each incremental backup;
2. Incremental backup is divided into two situations, incremental and cumulitive. The former backs up to the same level or lower than yourself, the latter only backs up lower than their level;
3, with the incremental backup Description: a change in the level1 backup since level1 or level0, once level2 or level1 changes level2 backup or since level0;
4, cumulitive backup instructions: a change in the level1 backup since level0 , Level2 backs up the changes since the last level1 or level0.
 Relevant notes:
1. When the amount of data is relatively small or the performance of the database server is very strong, you can perform a full backup once a day;
2. If you need to store the backup file on Alibaba Cloud's OSS storage after backup, due to OSS storage There is a 4GB size limit, you need to modify the following three rman configurations to limit the size of the RMAN backup piece

1、level0_backup.rman文件
allocate channel C2 type disk ;                        --修改前
allocate channel C2 type disk maxpiecesize = 3500M ;  --修改后
2、level1_backup.rman文件
allocate channel C3 type disk ;                        --修改前
allocate channel C3 type disk maxpiecesize = 3500M ;  --修改后
3、level2_backup.rman文件
allocate channel C4 type disk ;                        --修改前
allocate channel C4 type disk maxpiecesize = 3500M ;  --修改后

3. Configure crontab timing tasks, avoid busy business hours.
4. Use oracle users to configure timing tasks. If you need to use root users to configure timing tasks, pay attention to modifying environment variables and executing scripts in the script section of scheduled tasks. The path has read and write execution permissions.

1.2. Directory description

Daemon library backup script path: /backup/rman/scripts/
Archive file backup by date: /backup/arch/date +%Y%m%d
Control file backup: /backup/rman/controlfile
Database file backup by date: /backup /rman/data/date +%Y%m%d
Generate backup logs by date: /backup/rman/logs/date +%Y%m%d
RMAN backup script: /backup/rman/scripts
Please complete all directories above Remote backup.

2. rman backup

2.1. Backup Strategy

 Retain the last 5 backup data:
 Delete redundant and invalid backups at 04:45 a.m. every day;
 Back up archive logs at 12 and 20 o'clock
every day ;  Perform level 0 full backup of the database at 03:20 every day;

2.2. Backup plan

The daily equipment used here can be added according to actual needs, from Monday to Saturday, and fully prepared on Sunday.
Time Monday to Sunday
12:00 Log backup
20:00 Log backup
03:20 Full backup
Add the script to the crontab of the oracle user, let it run automatically according to the strategy, and adjust the scheduled tasks according to actual needs.

$ crontab -e
20 03 * * * /backup/rman/scripts/level0_backup.sh
45 04 * * * /backup/rman/scripts/delobsolete.sh
00 12 * * * /backup/rman/scripts/arch.sh
00 20 * * * /backup/rman/scripts/arch.sh

2.3. Preparation

Put the oracle database in the "installation module" to enable log archiving mode, and the archived logs are stored in the quick recovery area

mkdir -p /backup/arch
mkdir -p /backup/rman/controlfile
mkdir /backup/rman/data
mkdir /backup/rman/logs
mkdir /backup/rman/scripts
chown -R oracle:oinstall /backup

Set the connection SID before the following database connection

$ export ORACLE_SID=daemon
$ sqlplus / as sysdba
SQL> SELECT log_mode from v$database;


The output result is ARCHIVELOG, which means that the archive has been turned on. The
output result is NOARCHIVELOG which means that the archive is not turned on.

(1) The operation opens the archive log.

$ sqlplus / as sysdba
SQL> shutdown immediate;
startup mount;
alter database archivelog;
alter database open;

(2) Enable the change tracking function to record the location of data blocks that have changed since the last backup to improve the performance of incremental backups. The change tracking file is saved in the quick recovery area by default (block change tracking is started when RMAN incremental backup is used to shorten the time of RMAN backup).

$ sqlplus / as sysdba
SQL> shutdown immediate;
startup mount
alter system set db_create_file_dest='/u01/oracle/fast_recovery_area';
alter database enable block change tracking;
alter database open;

(3) View and modify the size of the flashback area (the size is modified according to the actual situation)

SQL> show parameter db_recovery_file_dest;
alter system set db_recovery_file_dest_size=40G scope=both;
shutdown immediate;
startup;

2.4. rman configuration

$ rman target /
CONFIGURE RETENTION POLICY TO REDUNDANCY 5;
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 5 DAYS;

The above two sentences can only use one condition, save 5 copies or 5 days of recovery window (recommendation to use recovery window), please adjust as needed

CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/rman/controlfile/%F';
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/backup/rman/controlfile/snapcf_daemon.f';

2.5. rman script

1) delobsolete.rman

cd /backup/rman/scripts
$ vi delobsolete.rman
run {
  crosscheck backup;
  delete noprompt obsolete;
  delete noprompt expired backup;
}
exit

2) arch.rman

$ vi arch.rman
sql 'alter system archive log current' ;
run {
allocate channel C1 type disk FORMAT '/backup/arch/' ;
backup 
skip inaccessible
tag arch_daemon
filesperset 10 format '/backup/arch/%T/arch_%T_%d_%t_%s_%p' archivelog all delete input;
release channel C1;
}
exit

3) level0_backup.rman

$ vi level0_backup.rman
sql 'PURGE DBA_RECYCLEBIN';
sql 'alter system archive log current' ;
run {
allocate channel C2 type disk ;
backup 
incremental level 0 
skip inaccessible 
tag full0_daemon
DATABASE 
filesperset 5 format '/backup/rman/data/%T/db_0_%T_%d_%t_%s_%p';
release channel C2;
}
exit

4) level1_backup.rman

$ vi level1_backup.rman
sql 'PURGE RECYCLEBIN';
sql 'alter system archive log current' ;
run {
allocate channel C3 type disk ;
backup 
incremental level 1
skip inaccessible 
tag level1_daemon
DATABASE 
filesperset 5 format '/backup/rman/data/%T/db_1_%T_%d_%t_%s_%p_inc' ;
release channel C3;
}
exit

5) level2_backup.rman

$ vi level2_backup.rman
sql 'PURGE RECYCLEBIN';
sql 'alter system archive log current' ;
run {
allocate channel C4 type disk ;
backup 
incremental level 2
skip inaccessible 
tag level2_daemon
DATABASE 
filesperset 5 format '/backup/rman/data/%T/db_2_%T_%d_%t_%s_%p_inc' ;
release channel C4;
}
exit

2.6. Scheduled task script

1) delobsolete.sh

$ vi delobsolete.sh
#!/bin/sh
#export LANG=en_US
source /home/oracle/.bash_profile
export ORACLE_SID=daemon
mkdir /backup/rman/logs/`date +%Y%m%d`
rman target / cmdfile=/backup/rman/scripts/delobsolete.rman msglog=/backup/rman/logs/`date +%Y%m%d`/`date +%Y%m%d_%H%M_obsolete.log`
exit

2) arch.sh

$ vi arch.sh
#!/bin/sh
#export LANG=en_US
source /home/oracle/.bash_profile
export ORACLE_SID=daemon
mkdir /backup/arch/`date +%Y%m%d`
mkdir /backup/rman/logs/`date +%Y%m%d`
rman target / cmdfile=/backup/rman/scripts/arch.rman msglog=/backup/rman/logs/`date +%Y%m%d`/`date +%Y%m%d_%H%M_arch.log`
exit

3) level0_backup.sh

$ vi level0_backup.sh
#!/bin/sh
#export LANG=en_US
source /home/oracle/.bash_profile
export ORACLE_SID=daemon
mkdir /backup/rman/data/`date +%Y%m%d`
mkdir /backup/rman/logs/`date +%Y%m%d`
rman target / cmdfile=/backup/rman/scripts/level0_backup.rman msglog=/backup/rman/logs/`date +%Y%m%d`/`date +%Y%m%d_%H%M_0.log`
exit

4) level1_backup.sh

$ vi level1_backup.sh
#!/bin/sh
#export LANG=en_US
source /home/oracle/.bash_profile
export ORACLE_SID=daemon
mkdir /backup/rman/data/`date +%Y%m%d`
mkdir /backup/rman/logs/`date +%Y%m%d`
rman target / cmdfile=/backup/rman/scripts/level1_backup.rman msglog=/backup/rman/logs/`date +%Y%m%d`/`date +%Y%m%d_%H%M_1.log`
exit

5) level2_backup.sh

$ vi level2_backup.sh
#!/bin/sh
#export LANG=en_US
source /home/oracle/.bash_profile
export ORACLE_SID=daemon
mkdir /backup/rman/data/`date +%Y%m%d`
mkdir /backup/rman/logs/`date +%Y%m%d`
rman target / cmdfile=/backup/rman/scripts/level2_backup.rman msglog=/backup/rman/logs/`date +%Y%m%d`/`date +%Y%m%d_%H%M_2.log`
exit

3. End

Guess you like

Origin blog.51cto.com/8355320/2590393