(shell) Rman backup script

Source: Internet
Author: User

1. Fully prepared (including control documents)

[Oracle@centos6 scripts]$ cat rman_backup.sh
source/home/oracle/.bash_profile
Rman target/log=/home/oracle /backup/backupall_rman.log<<eof
Run
{
allocate channel CH1 device type disk;  #分配通道
Allocate channel CH2 device type disk;
SQL ' alter system archive log current '; #归档当前日志
Backup Database format '/home/oracle/backup/db_%d_%t_%u ';
SQL ' alter system archive log current ';
Backup Archivelog all format '/home/oracle/backup/arch_%t_%s ' deletes all input;
Backup format '/home/oracle/backup/con_%s_%p ' current controlfile;
Crosscheck backup;
Crosscheck Archivelog all;
Delete noprompt expired backup;
Delete noprompt obsolete;
Delete noprompt backup of database completed before ' sysdate-15 ';
Delete noprompt Archivelog all;
Delete noprompt backup of Archivelog all completed before ' sysdate-15 ';
Release channel CH1;
Release channel CH2;
}
Eof

2. Support for full-library and incremental backups

[Oracle@centos6 scripts]$ cat db_back_rman.sh ##=========================================================== # # Db_ Bak_rman.sh # Created by Robinson # 2011/11/07 # usage:db_bak_rman.sh < $ORACLE _SID&G T  < $BACKUP _level> # backup_level: # # F:full BACKUP # # 0:level 0 # # 1: Level 1 ##============================================================ #!/bin/bash # User Spec 
IFIC environment and startup programs if [-f ~/.bash_profile]; Then.                              ~/.bash_profile fi oracle_sid=${1};                              Export Oracle_sid rman_level=${2};                 Export Rman_level timestamp= ' date +%y%m%d%h%m ';                          Export TIMESTAMP date= ' DATE +%y%m%d ';   Export DATE Rman_dir=/u02/database/${oracle_sid}/backup/rman;                Export Rman_dir rman_data=${rman_dir}/${date}; Export Rman_data #RMAN_LOG =$Rman_data/log; Export Rman_log rman_log=/u02/database/${oracle_sid}/backup/rman/log Export Rman_log # Check RMAN level #========
============================================================== if ["$RMAN _level" = = "F"]; Then unset incr_lvl backup_type=full Else incr_lvl= "incremental level ${rman_level}" backup_type=lev${r       Man_level} fi Rman_file=${rman_data}/${oracle_sid}_${backup_type}_${timestamp};      Export Rman_file Ssh_log=${rman_log}/${oracle_sid}_${backup_type}_${timestamp}.log;                                                Export Ssh_log maxpiecesize=4g; Export maxpiecesize #Check RMAN Backup Path #======================================================================= = = if!  Test-d ${rman_data} then mkdir-p ${rman_data} fi echo "---------------------------------" >>${ssh_log} echo "" >>${ssh_log} echo "Rman begin to Working ..." >>${ssh_log} Echo Begin time at: "' Date '--' date +%y%m% D%h%m ' >>${ssh_log} #Startup Rman to backup #==================================================================== ========= $ORACLE _home/bin/rman log=${rman_file}.log <<eof connect target/run {CONFIGURE RETENTION POLICY to Reco
VERY WINDOW of 3 days;
CONFIGURE BACKUP optimization on;
CONFIGURE Controlfile autobackup on;
CONFIGURE controlfile autobackup FORMAT for DEVICE TYPE DISK to ' ${rman_file}_%f ';
ALLOCATE CHANNEL ' ch1 ' TYPE DISK maxpiecesize=${maxpiecesize};
ALLOCATE CHANNEL ' CH2 ' TYPE DISK maxpiecesize=${maxpiecesize};
Set limit channel CH1 readrate=10240;
Set limit channel CH1 kbytes=4096000;
Set limit channel CH2 readrate=10240;
Set limit channel CH2 kbytes=4096000;
Crosscheck Archivelog All;
DELETE noprompt expired Archivelog all; BACKUP #AS compressed Backupset ${incr_lvl} DATABASE FORMAT ' ${rman_file}_%u ' TAG ' ${oracle_sid}_${backup_type}_${times
Tamp} ';
SQL ' ALTER SYSTEM ARCHIVE LOG current '; BACKUP archivelog all FORMAT ' ${rman_file}_arc_%u ' TAG ' ${oracle_sid}_arc_${timestamp} ' DELETE INPUT;
DELETE noprompt OBSOLETE;
Release CHANNEL Ch1;
Release CHANNEL CH2;
SQL "ALTER DATABASE backup Controlfile to ' ${rman_data}/cntl_${backup_type}.bak '";
Exit

EOF rc=$?  Cat ${rman_file}.log >>${ssh_log} echo "RMAN Stop working @ time:" ' Date ' date +%y%m%d%h%m ' >>${ssh_log} Echo >>${ssh_log} echo "------------------------" >>${ssh_log} echo "------Disk space------" >>${ssh_log Df-h >>${ssh_log} Echo >>${ssh_log} If [$RC-ne "0"]; then echo "------error------" >>${ssh_log} else echo "------no error found during RMAN backup peroid----- -">>${ssh_log} rm-rf ${rman_file}.log fi #Remove old backup than 3 days #====================================   ======================================== rmdir=${rman_dir}/'/bin/date +%y%m%d-d ' 3 days ago ';  Export RMDIR echo >>${ssh_log} echo-e "------Remove old backup than 3 days------\ n" >>${ssh_log} if test-d ${rmdir} tHen rm-rf ${rmdir} rc=$? fi echo >>${ssh_log} If [$RC-ne "0"]; Then echo-e "------Remove old Backup exception------\ n" >>${ssh_log} else echo-e "------No error found During remove old backup set peroid------\ n ">>${ssh_log} fi exit


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.