Automatic Oracle Database Backup in Linux

Source: Internet
Author: User

Backup policy:

Sunday level 0
Monday, second, fourth, fifth, sixth, Grade 2
Level 1 on Wednesday


-- Create a local management path

Mkdir-p/dinglp/ora_managed/backup
Mkdir-p/dinglp/ora_managed/backup
Mkdir-p/dinglp/ora_managed/backup/export
Mkdir-p/dinglp/ora_managed/backup/log
Mkdir-p/dinglp/ora_managed/backup/rman_backup
Mkdir-p/dinglp/ora_managed/scripts

-- Create rman tablespace and rman user

Create tablespace rman_tbs datafile '/oradata/luke/rman_tbs01.dbf' size 1024 M;
Create user rman_dlp identified by dlp default tablespace rman_tbs temporary tablespace temp;
Grant connect, resource, recovery_catalog_owner to rman;

-- Register the catalog Database

Rman catalog rman_dlp/dlp
Create catalog tablespace rman_tbs;
Connect target sys/dg @ priamry
Register database;
Report schema;

-- Set backup Parameters

Configure retention policy to redundancy 2;
Configure retention policy to recovery window of 7 days;

-- The following is a backup script (you can edit it through vi)
Dlp-> touch exp_rman.par
Dlp-> touch exp_rman.sh
Dlp-> touch rman_bk_LEVEL0.rcv (Database Backup level 0)
Dlp-> touch rman_bk_LEVEL0.sh
Dlp-> touch rman_bk_LEVEL1.rcv (Database Level 1 backup)
Dlp-> touch rman_bk_LEVEL1.sh
Dlp-> touch rman_bk_LEVEL2.rcv (Database Level 2 backup www.bkjia.com)
Dlp-> touch rman_bk_LEVEL2.sh

-- Returns the RMAN user data script exp_rman.par.
######################################## ##########
### Exp_rman.par ###
######################################## ##########
Userid = rman_dlp/dlp
File =/dinglp/ora_managed/backup/export/rman. dmp
Log =/dinglp/ora_managed/backup/log/rman. log

-- Reverse the RMAN data SHELL script exp_rman.sh
######################################## ##########
### Exp_rman.sh ###
######################################## ##########
#! /Bin/bash
Source/home/Oracle/. bash_profile
Cd/dinglp/ora_managed/scripts
Exp parfile = exp_rman.par

-- Zero-level backup RMAN script rman_bk_LEVEL0.rcv
Connect catalog rman_dlp/dlp
Connect target sys/dg @ primary
Run {
Allocate channel d1 type disk;
Allocate channel d2 type disk;
Backup incremental level 0 database format'/dinglp/ora_managed/backup/rman_backup/level0 _ % d _ % s _ % p _ % u. bak'
Tag = 'level 0' include current controlfile;
SQL 'alter system archive log current ';
Backup archivelog all format'/dinglp/ora_managed/backup/rman_backup/log _ % d _ % s _ % p _ % u. bak 'delete all input;
Release channel d2;
Release channel d1;
}
Crosscheck backup;
Delete noprompt expired backup;
Delete noprompt obsolete;
Resync catalog;
Exit;

-- Rman_bk_LEVEL0.sh of the zero-level backup SHELL script
######################################## #############################
### Rman_bk_LEVEL0.sh ###
######################################## #############################
#! /Bin/bash
Source/home/oracle/. bash_profile
Cd/dinglp/ora_managed/scripts
Rman synchronized file = rman_bk_LEVEL0.rcv msglog = $ HOME/backup/log/rman_bk_LEVEL0.log
./Dinglp/ora_managed/script/exp_rman.sh

-- Level 1 differential Incremental Backup RMAN script rman_bk_LEVEL1.rcv
Connect catalog rman_dlp/dlp
Connect target sys/dg @ primary
Run {
Allocate channel d1 type disk;
Backup incremental level 1 format'/dinglp/ora_managed/backup/rman_backup/level1 _ % d _ % s _ % p _ % u. bak 'tag = 'Level 1' database;
SQL 'alter system archive log current ';
Backup archivelog all format'/dinglp/ora_managed/backup/rman_backup/log _ % d _ % s _ % p _ % u. bak 'delete all input;
Release channel d1;
}
Crosscheck backup;
Delete noprompt expired backup;
Delete noprompt obsolete;
Resync catalog;
Exit;

-- Level 1 differential Incremental Backup SHELL script rman_bk_LEVEL1.sh
######################################## #############################
### Rman_bk_LEVEL1.sh ###
######################################## #############################
#! /Bin/bash
Source/home/oracle/. bash_profile
Cd/dinglp/ora_managed/scripts
Rman synchronized file = rman_bk_LEVEL1.rcv msglog =/dinglp/ora_managed/backup/log/rman_bk_LEVEL1.log
./Dinglp/ora_managed/scripts/exp_rman.sh

-- Level 2 Differential Incremental Backup RMAN script rman_bk_LEVEL2.rcv
Connect catalog rman_dlp/dlp
Connect target sys/dg @ primary
Run {
Allocate channel d1 type disk;
Backup incremental level 2 format'/dinglp/ora_managed/backup/rman_backup/level2 _ % d _ % s _ % p _ % u. bak 'tag = 'Level 2' database;
SQL 'alter system archive log current ';
Backup archivelog all format'/dinglp/ora_managed/backup/rman_backup/log _ % d _ % s _ % p _ % u. bak 'delete all input;
Release channel d1;
}
Crosscheck backup;
Delete noprompt expired backup;
Delete noprompt obsolete;
Resync catalog;
Exit;

-- Level 2 Differential Incremental Backup SHELL script rman_bk_LEVEL2.sh
######################################## #############################
### Rman_bk_LEVEL2.sh ###
######################################## #############################
#! /Bin/bash
Source/home/oracle/. bash_profile
Cd/dinglp/ora_managed/scripts
Rman audit file = rman_bk_LEVEL2.rcv msglog =/dinglp/ora_managed/backup/log/rman_bk_LEVEL2.log
./Dinglp/ora_managed/scripts/exp_rman.sh

-- Improve RMAN Incremental backup performance

Alter database enable block change tracking using file '/u01/app/oracle/admin/devdb/bdump/luke. log ';

Desc v $ block_change_tracking;

-- RMAN Dynamic View
V $ ARCHIVED_LOG displays the archive files that have been created, backed up, or cleared in the database.
V $ backup_partition uption shows the damaged blocks found during backup of the Backup set.
V $ copy_uption: shows the damaged blocks found during image copying.
V $ BACKUP_DATAFILE is used to create a backup set of the same size by determining the number of blocks in each data file. You can also find the number of corrupted blocks in the data file. V $ BACKUP_REDOLOG displays the archived logs stored in the backup set.
V $ BACKUP_SET: displays the created backup set.
V $ BACKUP_PIECE displays the backup slices created for the backup set.

-- How to monitor replication processes
Use the set command id command to associate a server session with a channel.
Query V $ PROCESS and V $ SESSION to determine which RMAN channels the SESSION corresponds.
Query V $ SESSION_LONGOPS to monitor the backup and replication progress.

-- Automatically run the backup script in linux
Crontab format Overview
1st columns minute 1 ~ 59
2nd columns hour 1 ~ 23 (0 indicates midnight)
1-3rd ~ 31
4th columns Month 1 ~ 12
5th columns in a week 0 ~ 6 (0 indicates Sunday)
6th columns of commands to run

[Root @ dlp ~] # Vi/etc/crontab

SHELL =/bin/bash
PATH =/sbin:/bin:/usr/sbin:/usr/bin
MAILTO = root
HOME =/

# Run-parts
01 *** root run-parts/etc/cron. hourly
02 4 *** root run-parts/etc/cron. daily
22 4 ** 0 root run-parts/etc/cron. weekly
42 4 1 ** root run-parts/etc/cron. monthly
00 22 ** 0 root/dinglp/ora_managed/scripts/rman_bk_LEVEL0.sh
00 22 ** 3 root/dinglp/ora_managed/scripts/rman_bk_LEVEL1.sh
00 22 ** 1, 2, 4, 5, 6 root/dinglp/ora_managed/scripts/rman_bk_LEVEL2.sh

-- Completed, RYOHEI, 2010-08-04.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.