Linux RMAN backup shell script

Source: Internet
Author: User

RMAN backup is easy to use for Oracle database backup and recovery, with low costs. For non-catalog mode, it is undoubtedly the first choice to embed the RMAN script into the shell script and then use crontab to back up small and medium databases. This document provides an easy-to-use RMAN backup script based on linux shell for your reference. You can make appropriate adjustments as needed.

The specific content of the script is as follows:

  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 :"'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 WINDOW3DAYS;
  53. Configure backup optimization on;
  54. Configure controlfile autobackup on;
  55. CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK'$ {RMAN_FILE} _ % F';
  56. ALLOCATE CHANNEL'Authorization'Type disk maxpiecesize =$ {MAXPIECESIZE };
  57. ALLOCATE CHANNEL'Ch2'Type disk maxpiecesize =$ {MAXPIECESIZE };
  58. Set limit channel ready readrate =10240;
  59. Set limit channel limit 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 identifier;
  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. IfTest-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. Oracle @ SZDB :~ /Robinson/scripts/dba_scripts/custom/SQL>./db_bak_rman.sh GOBO10
  110. 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>
  112. Oracle @ SZDB :~ /Robinson/scripts/dba_scripts/custom/SQL>
  113. Oracle @ SZDB:/u02/database/GOBO1/backup/rman> ls
  114. 20120928Log
  115. Oracle @ SZDB:/u02/database/GOBO1/backup/rman/20120928> Ls
  116. Cntl_lev0.bak gobow.lev0_201209281421_arc_4onmb9ro_1_1
  117. GOBO1_lev0_201209281421_4knmb9jn_1_1 GOBO1_lev0_201209281421_c-733951103-20120928-00
  118. GOBO1_lev0_201209281421_4lnmb9jn_1_1 GOBO1_lev0_201209281421_c-733951103-20120928-01
  119. Gobow.lev0_201209281421_arc_4nnmb9rn_1_1

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.