RMAN and rman backup

Source: Internet
Author: User

RMAN and rman backup

Original script, zombie

Http://blog.csdn.net/ashic/article/details/46311573

-H: View help information

[Oracle @ gc1 ~] $ Sh backup. sh-h
The following information teach you how to use this script
Backup. sh -- full
Backup. sh -- incr0 <RMAN_HOME>
Backup. sh -- incr1 <RMAN_HOME>
THE <RMAN_HOME> is the place where you want to store the backup
After you set the RMAN_HOME, The script will create the following directory:
-- 2015_06_01
| -- Archlog -- This directory store your archivelog backup
| -- Ctlfile -- This directory store your controlfile bakcup
| -- Data -- This directory store your backup
| -- Incr0 -- This is your incr0 backupset
-- Log -- This is your backup log directory
| -- Dbbak. log -- This log records the backup start and finish time points
| -- Incr0_2015-06-01.log -- This your backup log records the rman output information
Backup. sh -- help
Usage:
Backup. sh -- full <rman full backup>
Backup. sh -- incr0 <incremental 0 bakcup>
Backup. sh -- incr1 <incremental 1 backup>
Backup. sh -- help



#! /Bin/bash

Cmd = $1
Script_name = 'basename $0'
RMAN_HOME = $2/'date + % Y _ % m _ % d'


Print_usage (){
Echo "Usage :"
Echo "$ script_name -- full <rman full backup>"
Echo "$ script_name -- incr0 <incremental 0 bakcup>"
Echo "$ script_name -- incr1 <incremental 1 backup>"
Echo "$ script_name -- help }


Print_help (){
Echo "The script was written by FAN"
Echo "The following information teach you how to use this script"
Echo "$ script_name -- full"
Echo "$ script_name -- incr0 <RMAN_HOME>"
Echo "$ script_name -- incr1 <RMAN_HOME>"
Echo "THE <RMAN_HOME> is the place where you want to store the backup"
Echo "After you set the RMAN_HOME, The script will create the following directory :"
Echo "-- 2015_06_01"
Echo "| -- archlog -- This directory store your archivelog backup"
Echo "| -- ctlfile -- This directory store your controlfile bakcup"
Echo "| -- data -- This directory store your backup"
Echo "| -- incr0 -- This is your incr0 backupset"
Echo "-- log -- This is your backup log directory"
Echo "| -- dbbak. log -- This log records the backup start and finish time points"
Echo "| -- incr0_2015-06-01.log -- This your backup log records the rman output information"
Echo "$ script_name -- help"
Print_usage
}


Full (){
# ----------------------- Script env -----------------------


Local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. log


Local LOGDATE = 'date + % Y-% m-% d'
Local RMANLOG = $ RMAN_HOME/$ datedir/log/full _ $ {LOGDATE}. log


If [! -D $ {RMAN_HOME}];
Then mkdir-p $ RMAN_HOME
Mkdir $ RMAN_HOME/archlog
Mkdir $ RMAN_HOME/ctlfile
Mkdir $ RMAN_HOME/data
Mkdir $ RMAN_HOME/log
Mkdir $ RMAN_HOME/data/full
Fi


If [! -F $ {LOGFILE}];
Then touch $ {LOGFILE}
Fi


If [! -F $ {RMANLOG}];
Then touch $ {RMANLOG}
Fi
# ------------- Start backup -----------------


Echo "--------------------------- Rman full backup -------------------------" >$ {LOGFILE}
Echo "backup_full start time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "---------------------- Rman Database backup_full ------------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG}


$ ORACLE_HOME/bin/rman target/<EOF >$ {RMANLOG}
Run
{
Delete noprompt obsolete;
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
Allocate channel c1 type disk MAXPIECESIZE 5g;
Allocate channel c2 type disk MAXPIECESIZE 5g;
Allocate channel c3 type disk MAXPIECESIZE 5g;
Allocate channel c4 type disk MAXPIECESIZE 5g;
Allocate channel c5 type disk MAXPIECESIZE 5g;
Backup as compressed backupset database tag 'fullbackup 'filesperset 3 format' $ RMAN_HOME/data/full/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile;
Backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input;
Backup current controlfile format '$ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck ';
Crosscheck backup;
Delete noprompt expired backup;
Release channel c1;
Release channel c2;
Release channel c3;
Release channel c4;
Release channel c5;
}
Exit;
EOF


Echo "backup_full finish! Check in: "$ {RMANLOG }>> {LOGFILE}
Echo "backup_full end time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "--------------------------------- full_end -----------------------------------" >$ {LOGFILE}
# End of file
Echo "Full backup complete, your backup are in $ RMAN_HOME"
}




Incr0 (){
# ----------------------- Script env -----------------------



Local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. log


Local LOGDATE = 'date + % Y-% m-% d'
Local RMANLOG = $ RMAN_HOME/$ datedir/log/incr0 _ $ {LOGDATE}. log


If [! -D $ {RMAN_HOME}];
Then mkdir-p $ RMAN_HOME
Mkdir $ RMAN_HOME/archlog
Mkdir $ RMAN_HOME/ctlfile
Mkdir $ RMAN_HOME/data
Mkdir $ RMAN_HOME/data/incr0
Mkdir $ RMAN_HOME/log
Fi


If [! -F $ {LOGFILE}];
Then touch $ {LOGFILE}
Fi


If [! -F $ {RMANLOG}];
Then touch $ {RMANLOG}
Fi
# ------------- Start incr0 backup -----------------


Echo "------------------------- Rman incr0 backup -------------------------" >$ {LOGFILE}
Echo "backup_incr0 start time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "---------------------- Rman Database backup_incr0 ------------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG}


$ ORACLE_HOME/bin/rman target/<EOF >$ {RMANLOG}
Run
{
Delete noprompt obsolete;
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
Allocate channel c1 type disk MAXPIECESIZE 5g;
Allocate channel c2 type disk MAXPIECESIZE 5g;
Allocate channel c3 type disk MAXPIECESIZE 5g;
Allocate channel c4 type disk MAXPIECESIZE 5g;
Allocate channel c5 type disk MAXPIECESIZE 5g;
Backup as compressed backupset incremental level 0 database tag 'encr0backup' filesperset 3 format' $ RMAN_HOME/data/incr0/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile;
Backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input;
Backup current controlfile format '$ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck ';
Crosscheck backup;
Delete noprompt expired backup;
Release channel c1;
Release channel c2;
Release channel c3;
Release channel c4;
Release channel c5;
}
Exit;
EOF


Echo "backup_incr0 finish! Check in: "$ {RMANLOG }>> {LOGFILE}
Echo "backup_incr0 end time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "--------------------------------- incr0_end -----------------------------------" >$ {LOGFILE}
# End of file
Echo "Incremental 0 backup complete, your backup are in $ RMAN_HOME"
}




Incr1 (){
# ----------------------- Script env -----------------------






Local LOGFILE = $ RMAN_HOME/$ datedir/log/dbbak. log


Local LOGDATE = 'date + % Y-% m-% d'
Local RMANLOG = $ RMAN_HOME/$ datedir/log/incr1 _ $ {LOGDATE}. log


If [! -D $ {RMAN_HOME}];
Then mkdir-p $ RMAN_HOME
Mkdir $ RMAN_HOME/archlog
Mkdir $ RMAN_HOME/ctlfile
Mkdir $ RMAN_HOME/data
Mkdir $ RMAN_HOME/data/incr1
Mkdir $ RMAN_HOME/log
Fi


If [! -F $ {LOGFILE}];
Then touch $ {LOGFILE}
Fi


If [! -F $ {RMANLOG}];
Then touch $ {RMANLOG}
Fi
# ------------- Start incr1 backup -----------------


Echo "------------------------- Rman incr1 backup -------------------------" >$ {LOGFILE}
Echo "backup_incr1 start time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "---------------------- Rman Database backup_incr1 ------------" 'date + % Y-% m-% d _ % H: % M: % s' >$ {RMANLOG}


$ ORACLE_HOME/bin/rman target/<EOF >$ {RMANLOG}
Run
{
Delete noprompt obsolete;
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
Allocate channel c1 type disk MAXPIECESIZE 5g;
Allocate channel c2 type disk MAXPIECESIZE 5g;
Allocate channel c3 type disk MAXPIECESIZE 5g;
Allocate channel c4 type disk MAXPIECESIZE 5g;
Allocate channel c5 type disk MAXPIECESIZE 5g;
Backup as compressed backupset incremental level 1 database tag 'encr1backup' filesperset 3 format' $ RMAN_HOME/data/incr1/db_full _ % T _ % d _ % t _ % s _ % p. rbck 'include current controlfile;
Backup as compressed backupset format' $ RMAN_HOME/archlog/arch_full _ % T _ % d _ % t _ % s _ % p. rbck 'archivelog all delete input;
Backup current controlfile format '$ RMAN_HOME/ctlfile/ctl _ % d _ % T _ % s _ % p _ % t. rbck ';
Crosscheck backup;
Delete noprompt expired backup;
Release channel c1;
Release channel c2;
Release channel c3;
Release channel c4;
Release channel c5;
}
Exit;
EOF


Echo "backup_incr1 finish! Check in: "$ {RMANLOG }>> {LOGFILE}
Echo "backup_incr1 end time:" 'date + % Y-% m-% d _ % H: % M: % s' >>$ {LOGFILE}
Echo "--------------------------------- incr1_end -----------------------------------" >$ {LOGFILE}
# End of file
Echo "Incremental 1 backup complete, your backup are in $ RMAN_HOME"
}


Case "$ cmd" in
-- Help)
Print_help
;;
-H)
Print_help
;;
-- H)
Print_help
;;
-- Full)
Full
;;
-- Incr0)
Incr0
;;
-- Incr1)
Incr1
;;
Esac

Related Article

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.