Linux under Rman backup shell script

Source: Internet
Author: User

Rman backup is easy to use and inexpensive for Oracle database backup and recovery. For non-catalog mode, it is undoubtedly the first choice to embed Rman scripts into shell scripts and then use crontab to make small database database backups. This article provides an easy-to-use Rman backup script based on the Linux shell for reference. You can make the appropriate adjustments according to your own needs.

Rman backup related Aspects of knowledge, you can refer to:
Overview of RMAN and its architecture
RMAN configuration, monitoring and management
An explanation of RMAN backup
RMAN Restore and recovery
Creation and use of RMAN catalog
Create an Rman storage script based on catalog
Catalog-based Rman backup and recovery
RMAN Backup Path confused

The second is to call the Sql,rman statement in the shell script for reference
Linux/unix calling Sql,rman script in shell script
Linux/unix passing variables between shell SQL

The following is the specifics of the script:

[Python]View PlainCopy print?
    1. ##===========================================================
    2. # # Db_bak_rman.sh
    3. # # Created by Robinson
    4. # 2011/11/07
    5. # # Usage:db_bak_rman.sh < $ORACLE _sid> < $BACKUP _level>
    6. # # Backup_level:
    7. # # F:full Backup
    8. # # 0:level 0
    9. # # 1:level 1
    10. ##============================================================
    11. #!/bin/bash
    12. # User specific environment and startup programs
    13. If [-f ~/.bash_profile];
    14. Then
    15. . ~/.bash_profile
    16. Fi
    17. oracle_sid=${1}; Export Oracle_sid
    18. rman_level=${2}; Export Rman_level
    19. timestamp= ' Date +%y%m%d%h%m '; Export TIMESTAMP
    20. Date= ' Date +%y%m%d '; Export DATE
    21. Rman_dir=/u02/database/${oracle_sid}/backup/rman; Export Rman_dir
    22. Rman_data=${rman_dir}/${date}; Export Rman_data
    23. #RMAN_LOG = $RMAN _data/log; Export Rman_log
    24. Rman_log=/u02/database/${oracle_sid}/backup/rman/log Export Rman_log
    25. # Check Rman Level
    26. #======================================================================
    27. If [ "$RMAN _level" = = "F"];
    28. Then unset INCR_LVL
    29. Backup_type=full
    30. Else
    31. Incr_lvl="INCREMENTAL level ${rman_level}"
    32. Backup_type=lev${rman_level}
    33. Fi
    34. Rman_file=${rman_data}/${oracle_sid}_${backup_type}_${timestamp}; Export Rman_file
    35. Ssh_log=${rman_log}/${oracle_sid}_${backup_type}_${timestamp}.log; Export Ssh_log
    36. Maxpiecesize=4G; Export Maxpiecesize
    37. #Check RMAN Backup Path
    38. #=========================================================================
    39. if! Test-d ${rman_data}
    40. Then
    41. Mkdir-p ${rman_data}
    42. Fi
    43. echo "---------------------------------" >>${ssh_log}
    44. echo "" >>${ssh_log}
    45. echo "Rman Begin to Working ..." >>${ssh_log}
    46. echo "Begin time at:" ' Date '--' date +%y%m%d%h%m ' >>${ssh_log}
    47. #Startup Rman to Backup
    48. #=============================================================================
    49. $ORACLE _home/bin/rman Log=${rman_file}.log <<eof
    50. Connect Target/
    51. Run {
    52. CONFIGURE RETENTION POLICY to RECOVERY windows of 3 days;
    53. CONFIGURE BACKUP optimization on;
    54. CONFIGURE Controlfile autobackup on;
    55. CONFIGURE controlfile autobackup FORMAT for DEVICE TYPE DISK to ' ${rman_file}_%f ';
    56. ALLOCATE CHANNEL ' ch1 ' TYPE DISK maxpiecesize=${maxpiecesize};
    57. ALLOCATE CHANNEL ' CH2 ' TYPE DISK maxpiecesize=${maxpiecesize};
    58. Set limit channel ch1 readrate=10240;
    59. Set limit channel ch1 kbytes=4096000;
    60. Set limit channel CH2 readrate=10240;
    61. Set limit channel CH2 kbytes=4096000;
    62. Crosscheck ARCHIVELOG All;
    63. DELETE noprompt EXPIRED ARCHIVELOG all;
    64. BACKUP
    65. #AS Compressed BACKUPSET
    66. ${INCR_LVL}
    67. DATABASE FORMAT ' ${rman_file}_%u ' TAG ' ${oracle_sid}_${backup_type}_${timestamp} ';
    68. SQL ' ALTER SYSTEM ARCHIVE LOG current ';
    69. BACKUP ARCHIVELOG all FORMAT ' ${rman_file}_arc_%u ' TAG ' ${oracle_sid}_arc_${timestamp} '
    70. DELETE INPUT;
    71. DELETE noprompt OBSOLETE;
    72. RELEASE CHANNEL ch1;
    73. RELEASE CHANNEL CH2;
    74. }
    75. SQL "ALTER DATABASE backup Controlfile to ' ${rman_data}/cntl_${backup_type}.bak";
    76. Exit
    77. Eof
    78. Rc=$?
    79. Cat ${rman_file}.log >>${ssh_log}
    80. echo "Rman Stop working @ time:" ' Date ' date +%y%m%d%h%m ' >>${ssh_log}
    81. Echo >>${ssh_log}
    82. echo "------------------------" >>${ssh_log}
    83. echo "------Disk Space------" >>${ssh_log}
    84. Df-h >>${ssh_log}
    85. Echo >>${ssh_log}
    86. If [$RC-ne "0"]; Then
    87. echo "------error------" >>${ssh_log}
    88. Else
    89. echo "------no error found during RMAN backup peroid------" >>${ssh_log}
    90. RM-RF ${rman_file}.log
    91. Fi
    92. #Remove old backup than 3 days
    93. #============================================================================
    94. rmdir=${rman_dir}/'/bin/date +%y%m%d-d "3 days Ago"; Export RMDIR
    95. Echo >>${ssh_log}
    96. ECHO-E "------Remove old backup than 3 days------\ n" >>${ssh_log}
    97. If Test-d ${rmdir}
    98. Then
    99. RM-RF ${rmdir}
    100. Rc=$?
    101. Fi
    102. Echo >>${ssh_log}
    103. If [$RC-ne "0"]; Then
    104. ECHO-E "------Remove old Backup exception------\ n" >>${ssh_log}
    105. Else
    106. ECHO-E "------No error found during remove old backup set peroid------\ n" >>${ssh_log}
    107. Fi
    108. Exit
    109. [Email protected]:~/robinson/scripts/dba_scripts/custom/sql>./db_bak_rman.sh GOBO1 0
    110. Rman> rman> 2> 3>  4> 5> 6>  7> 8> 9>  10> 11> 12>  13> 14> 15>    
    111. 16> 17> 18> 19> 20> 21> 22> 23> 24> rman> rman>
    112. [Email protected]:~/robinson/scripts/dba_scripts/custom/sql>
    113. [Email protected]:/u02/database/gobo1/backup/rman> ls
    114. 20120928 Log
    115. [Email protected]:/u02/database/gobo1/backup/rman/20120928> ls
    116. Cntl_lev0.bak gobo1_lev0_201209281421_arc_4onmb9ro_1_1
    117. Gobo1_lev0_201209281421_4knmb9jn_1_1 gobo1_lev0_201209281421_c-733951103-20120928-
    118. Gobo1_lev0_201209281421_4lnmb9jn_1_1 gobo1_lev0_201209281421_c-733951103-20120928-
    119. Gobo1_lev0_201209281421_arc_4nnmb9rn_1_1
    120. Ext.: http://blog.csdn.net/leshami/article/details/8029245

Linux under Rman backup shell script

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.