This is the 19th day of my participation in the August More Text Challenge

1. Create a directory for rman backup

The directory name can be customized and the disk space of the directory is sufficient.

Su - oracle mkdir rmanbackup mkdir scripts/log -pCopy the code

2. Write the Rman backup script

Change the path and database instance name based on the actual environment.

Full backup script rmanBackup0.sh

#! / bin/sh DATE = ` DATE + % Y - % m % d ` export ORACLE_HOME = / u01 / app/oracle/product / 11.2.0 / dbhome_1 export ORACLE_BASE=/u01/app/oracle export ORACLE_SID=orcl $ORACLE_HOME/bin/rman cmdfile /home/oracle/scripts/backup0.rcv log=/home/oracle/scripts/log/rman_full_$DATE.logCopy the code

Incremental backup script rmanBackup1.sh

#! / bin/sh DATE = ` DATE + % Y - % m % d ` export ORACLE_HOME = / u01 / app/oracle/product / 11.2.0 / dbhome_1 export ORACLE_BASE=/u01/app/oracle export ORACLE_SID=orcl $ORACLE_HOME/bin/rman cmdfile /home/oracle/scripts/backup1.rcv log=/home/oracle/scripts/log/rman_inc_$DATE.logCopy the code

backup0.rcv

connect target  /
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 0 format '/rmanbackup/orcl_full_%U' database include current controlfile;
delete noprompt obsolete device type disk;
sql 'alter system archive log current';
backup  format '/rmanbackup/orcl_arch_full_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
Copy the code

backup1.rcv

connect target  /
run
{
allocate channel d1 type disk;
allocate channel d2 type disk;
allocate channel d3 type disk;
allocate channel d4 type disk;
backup incremental level 1 format '/rmanbackup/orcl_inc_%U' database;
delete noprompt obsolete device type disk; 
sql 'alter system archive log current';
backup format '/rmanbackup/orcl_arch_inc_%U' archivelog all not backed up delete input;
crosscheck backup;
delete noprompt expired backup;
release channel d1;
release channel d2;
release channel d3;
release channel d4;
}
Copy the code

3. Modify the backup retention policy

The rman backup retention policy was changed to full backup twice (full backup once by default)

rman target /
configure retention policy to redundancy 2;
show all;
Copy the code

4. Create a scheduled task

The backup policy is full backup every Saturday, incremental backup every other day, and full backup for two times.

Grant the script execution permission to the Oracle user

chmod u+x /home/oracle/scripts/rmanbackup1.sh
chmod u+x /home/oracle/scripts/rmanbackup0.sh
Copy the code

Adding a Timing Plan

Crontab -e Add the following information: 23 * * 0 6 / home/oracle/scripts/rmanbackup0. 23 * * sh 0 0,1,2,3,4,5 / home/oracle/scripts/rmanbackup1 sh crontab - lCopy the code

5. Rman backup monitoring

Run the following command to check the rMAN backup status of the database

Crontab -e Add the following information: 23 * * 0 6 / home/oracle/scripts/rmanbackup0. 23 * * sh 0 0,1,2,3,4,5 / home/oracle/scripts/rmanbackup1 sh crontab - lCopy the code

If COMPLETED is displayed in the Status column, the backup is successful.

If the backup status is different, you can query the rMAN backup logs of the current day and view the backup exception cause: