RMAN backup script in Linux

Source: Internet
Author: User

SKIP Option
Excludes datafiles or archived redo logs from the backup set according to the criteria specified by the following keywords.
Note: You can also specify this option in the backupSpec clause.

OFFLINE
Specifies that offline datafiles shocould be excluded from the backup set.

READONLY
Specifies that read-only datafiles shocould be excluded from the backup set.

INACCESSIBLE
Specifies that datafiles or archived redo logs that cannot be read due to I/O errors shocould be excluded from the backup set.

A datafile is only considered inaccessible if it cannot be read. Some offline datafiles can be still be read because they still exist on disk. Others have been deleted or moved and

So cannot be read, making them inaccessible.


FILESPERSET = integer
Specifies the maximum number of input files in each backup set. If you set FILESPERSET = n, then RMAN never than DES more than n files in a backup set. The default

FILESPERSET is the lesser of these two values: 64, number of input files divided by the number of channels. For example, if you back up 100 datafiles by using two channels, RMAN

Sets FILESPERSET to 50.

RMAN always attempts to create enough backup sets so that all allocated channels have work to do. an exception to the rule occurs when there are more channels than files to back up. for example, if RMAN backs up two datafiles when three channels are allocated and FILESPERSET = 1, then one channel is necessarily idle.

Example:
The average number of files refers to the number of files/channels.
Allocate channel provides backup concurrency. If the average number of files <filesperset, backup is performed based on the average number of files/backup sets. If the number of files exceeds the limit, backup sets are generated based on the number of filesperset. For example:
1. run {
Allocate channel category type disk;
Allocate channel ch2 type disk;
Backup datafile 3, 4, 5, 6 filesperset 3;
Release channel identifier;
Release channel ch2;
}
The average value is 4 (number of files)/2 (number of channels) = 2. If the value is smaller than filesperset 3, two backup sets are generated. Each backup set contains two data files.

2. run {
Allocate channel category type disk;
Allocate channel ch2 type disk;
Backup datafile 3, 4, 5, 6 filesperset 1;
Release channel identifier;
Release channel ch2;
}
Generates four backup sets, each containing one data file

Rman nocatalog target sys/Oracle msglog rmanLog. out append -- append the command execution log to the rmanLog. out file. If no append exists, the existing rmanLog. out file is overwritten.

Backup script:

  1. ######################################## #################################
  2. # T_database_backup.sh ##
  3. # Created by Tianlesoftware ##
  4. #2010-7-16 ##
  5. ######################################## #################################
  6. #! /Bin/bash
  7. #---------------------------------------------------------------------------
  8. # Determine the user which is executing this script.
  9. #---------------------------------------------------------------------------
  10. CUSER = 'id | cut-d "("-f2 | cut-d ")"-f1'
  11. #---------------------------------------------------------------------------
  12. # Put output in <this file name>. out. Change as desired.
  13. # Note: output directory requires write permission.
  14. #---------------------------------------------------------------------------
  15. RMAN_LOG_FILE =$ {0}. out
  16. #---------------------------------------------------------------------------
  17. # You may want to delete the output file so that backup information does
  18. # Not accumulate. If not, delete the following lines.
  19. #---------------------------------------------------------------------------
  20. If [-f "$ RMAN_LOG_FILE"]
  21. Then
  22. Rm-f "$ RMAN_LOG_FILE"
  23. Fi
  24. #-----------------------------------------------------------------
  25. # Initialize the log file.
  26. #-----------------------------------------------------------------
  27. Echo> $ RMAN_LOG_FILE
  28. Chmod 666 $ RMAN_LOG_FILE
  29. #---------------------------------------------------------------------------
  30. # Log the start of this script.
  31. #---------------------------------------------------------------------------
  32. Echo Script {1 }>>$ RMAN_LOG_FILE
  33. Echo === started on 'date' ==>> $ RMAN_LOG_FILE
  34. Echo> $ RMAN_LOG_FILE
  35. #---------------------------------------------------------------------------
  36. # Oracle home path.
  37. #---------------------------------------------------------------------------
  38. ORACLE_HOME =/home/oracle/product/10.2.0/db_1
  39. Export ORACLE_HOME
  40. #---------------------------------------------------------------------------
  41. # The Oracle SID of the target database.
  42. #---------------------------------------------------------------------------
  43. ORACLE_SID = oralife
  44. Export ORACLE_SID
  45. #---------------------------------------------------------------------------
  46. # The Oracle DBA user id (account ).
  47. #---------------------------------------------------------------------------
  48. ORACLE_USER = oracle
  49. Export ORACLE_USER
  50. #---------------------------------------------------------------------------
  51. # Set the Oracle Recovery Manager name.
  52. #---------------------------------------------------------------------------
  53. RMAN = $ ORACLE_HOME/bin/rman
  54. #---------------------------------------------------------------------------
  55. # Print out the value of the variables set by this script.
  56. #---------------------------------------------------------------------------
  57. Echo> $ RMAN_LOG_FILE
  58. Echo "RMAN: $ RMAN" >>$ RMAN_LOG_FILE
  59. Echo "ORACLE_SID: $ ORACLE_SID" >>$ RMAN_LOG_FILE
  60. Echo "ORACLE_USER: $ ORACLE_USER" >>$ RMAN_LOG_FILE
  61. Echo "ORACLE_HOME: $ ORACLE_HOME" >>$ RMAN_LOG_FILE
  62. #---------------------------------------------------------------------------
  63. # Print out the value of the variables set by bphdb.
  64. #---------------------------------------------------------------------------
  65. # Echo> $ RMAN_LOG_FILE
  66. # Echo "NB_ORA_FULL: $ NB_ORA_FULL"> $ RMAN_LOG_FILE
  67. # Echo "NB_ORA_INCR: $ NB_ORA_INCR"> $ RMAN_LOG_FILE
  68. # Echo "NB_ORA_CINC: $ NB_ORA_CINC"> $ RMAN_LOG_FILE
  69. # Echo "NB_ORA_SERV: $ NB_ORA_SERV"> $ RMAN_LOG_FILE
  70. # Echo "NB_ORA_POLICY: $ NB_ORA_POLICY"> $ RMAN_LOG_FILE
  71. #---------------------------------------------------------------------------
  72. # NOTE: This script assumes that the database is properly opened. If desired,
  73. # This wocould be the place to verify that.
  74. #---------------------------------------------------------------------------
  75. Echo> $ RMAN_LOG_FILE
  76. #---------------------------------------------------------------------------
  77. #---------------------------------------------------------------------------
  78. # Call Recovery Manager to initiate the backup.
  79. #---------------------------------------------------------------------------
  80. Pai_str ="
  81. ORACLE_HOME = $ ORACLE_HOME
  82. Export ORACLE_HOME
  83. ORACLE_SID = $ ORACLE_SID
  84. Export ORACLE_SID
  85. $ RMAN nocatalog target sys/admin msglog $ RMAN_LOG_FILE append <EOF
  86. RUN {
  87. Allocate channel c1 type disk;
  88. Allocate channel c2 type disk;
  89. Backup format '/home/oracle/backup/oralife _ % U _ % t' skip inaccessible filesperset 5 database tag oralife_hot_db_bk;
  90. SQL 'alter system archive log current ';
  91. BACKUP format'/home/oracle/backup/arch _ % U _ % t' skip inaccessible filesperset 5 archivelog all delete input;
  92. Backup current controlfile tag = 'bak _ ctlfile 'format ='/home/oracle/backup/ctl_file _ % U _ % T ';
  93. Backup spfile tag = 'spfile' format = '/home/oracle/backup/oralife_spfile _ % U _ % T ';
  94. Release channel c2;
  95. Release channel c1;
  96. }
  97. Report obsolete;
  98. Delete noprompt obsolete;
  99. Crosscheck backup;
  100. Delete noprompt expired backup;
  101. List backup summary;
  102. # EOF
  103. "
  104. # Initiate the command string
  105. If ["$ CUSER" = "root"]
  106. Then
  107. Echo "Root Command String: $ CMD_STR" >>$ RMAN_LOG_FILE
  108. Su-$ ORACLE_USER-c "$ pai_str"> $ RMAN_LOG_FILE
  109. RSTAT = $?
  110. Else
  111. Echo "User Command String: $ pai_str" >>$ RMAN_LOG_FILE
  112. /Bin/sh-c "$ CMD_STR"> $ RMAN_LOG_FILE
  113. RSTAT = $?
  114. Fi
  115. #---------------------------------------------------------------------------
  116. # Log the completion of this script.
  117. #---------------------------------------------------------------------------
  118. If ["$ RSTAT" = "0"]
  119. Then
  120. LOGMSG = "ended successfully"
  121. Else
  122. LOGMSG = "ended in error"
  123. Fi
  124. Echo> $ RMAN_LOG_FILE
  125. Echo Script {1 }>>$ RMAN_LOG_FILE
  126. Echo ===$ LOGMSG on 'date' ====>> $ RMAN_LOG_FILE
  127. Echo> $ RMAN_LOG_FILE
  128. #/Bin/mailx-s "RMAN Backup SID" daimm@sf-express.com <$ RMAN_LOG_FILE
  129. Exit $ RSTAT

Email configuration...

Refer:

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.