Complete RMAN Incremental Backup shell script in Linux

Source: Internet
Author: User

This backup script is organized from the network, and some comments are added. This script is clear and can be applied to the production machine with slight changes.

 1 #! /Bin/ Bash  2   ######################################## ###############################  3   #  4   # Backup policy:  5   # Grade 0 backups every Sunday morning,  6   # Perform level-1 backup every Monday or Thursday,  7   # Perform secondary backup every Tuesday, three, five, and six, 8 # 00   4 ** 0 /U01/APP/Oracle/rman_bak/scripts/rman_bak. Sh   0  9 # 00   4 ** 1 , 4 /U01/APP/Oracle/rman_bak/scripts/rman_bak. Sh   1  10 #00   4 ** 2 , 3 , 5 , 6 /U01/APP/Oracle/rman_bak/scripts/rman_bak. Sh   2  11   #  12   ######################################## ###############################  13   # Backup script:  14 # Set Env  15   # Modify environment variables based on actual conditions  16 Export oracle_base =/u01/APP/ Oracle  17 Export ORACLE_HOME = $ oracle_base/ Db10g  18 Export oracle_sid = Emar  19 Export nls_lang = American_america.zhs16gbk  20 Export Path = $ ORACLE_HOME/ Bin: $ path 21   22 Date =' Date + % W  `  23 Date_2 =' Date + % Y % m % D'  24 Backup_path =/u01/APP/Oracle/ Rman_bak  25   # Input parameters: Backup level  26 Level = $ @  27 Target_sid =Emar  28 Rman_sid = Emar. Emar  29 Bin =/u01/APP/Oracle/db10g/ Bin  30   31 # Delete the data backuped Last   Time  You can modify the value based on the backup retention time.  32 # Rm -RF $ backup_path/data/$ date /*  33   34  If [$ #! = 1]; then  35   Echo "Usage: rman_bak.sh n  36   Where N is the RMAN backup level (0, 1, 2 is permitted )."  37   Exit 1  38   Fi  39   40   If [$ @-Ne 0-A $ @-ne 1-A $ @-ne 2]; then  41   Echo "Usage: rman_bak.sh n  42  Where N is the RMAN backup level (only 0, 1, 2 is permitted )."  43   Exit 2  44   Fi  45   46   Echo "------------------------------- start -----------------------------"; Date  47   48   # Level 0 backup. Here document is used when RMAN is called.  49   If [$ level = 0]; then  50  51   $ Bin/RMAN log $ backup_path/log/level. $ target_sid. $ level. $ date_2.log <EOF  52   Connect target sys/sys202;  53   # Connect to catalog  54   Connect catalog RMAN/RMAN @ $ rman_sid;  55   Resync Catalog;  56   Run {  57  Allocate channel C1 type disk;  58   # Cross-checking archiving logs in the database  59   Crosscheck backupset of archivelog all;  60   # Back up archived logs within 7 days. The format is changed according to company specifications.  61   Backup filesperset 3 format' $ backup_path/data/$ date/arch. % d. Live. $ level. % t' (archivelog from time 'sysdate-7' all Delete input );  62   # Delete an archived log in the expired status. If noprompt is not displayed  63  Delete noprompt expired backupset of archivelog all;  64   Release Channel C1;  65   }  66   67   Run {  68   Allocate channel C2 type disk;  69   Crosscheck backupset of database;  70  Backup incremental level $ level filesperset 3 format' $ backup_path/data/$ date/data. % d. Live. $ level. % t' (database include current controlfile );  71   -- SQL 'alter system archive log current ';  72   Delete noprompt expired backupset of database;  73   Delete noprompt obsolete;  74   Release Channel C2;  75   }  76  Exit;  77   EOF  78   79   # Perform Level 1 and 2 Backup Based on the call time and input parameters  80   Else  81   $ Bin/RMAN log $ backup_path/log/level. $ target_sid. $ level. $ date_2.log <EOF  82   Connect target sys/sys202;  83   Connect catalog RMAN/RMAN @ $ rman_sid;  84  Resync Catalog;  85   Run {  86   Allocate channel C1 type disk;  87   -- SQL 'alter system archive log current ';  88   Crosscheck backupset of archivelog all;  89   Backup filesperset 3 format' $ backup_path/data/$ date/arch. % d. Live. $ level. % t' (archivelog from time 'sysdate-1' all );  90  Delete noprompt expired backupset of archivelog all;  91   Release Channel C1;  92   }  93   94   Run {  95   Allocate channel C2 type disk;  96   Crosscheck backupset of database;  97  Backup incremental level $ level filesperset 3 format' $ backup_path/data/$ date/data. % d. Live. $ level. % t' (database include current controlfile );  98   -- SQL 'alter system archive log current ';  99   Delete noprompt expired backupset of database;  100   Delete noprompt obsolete;  101   Release Channel C2;  102   }  103  104   Exit;  105   EOF  106   Fi  107   108   $ Bin/exp rman/RMAN @ $ rman_sid file = $ backup_path/data/$ date/live. RMAN. $ date_2.dmp log = $ backup_path/log/$ rman_sid.rman. $ date_2.log  109   110   Echo "------------------------------ end ------------------------------"; Date 

 

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.