Using shell scripts to validate Rman backup sets and perform periodic recovery experiments

Source: Internet
Author: User
Tags scp command

Content Introduction:

Two kinds of shell script detailed

Operational actions to verify the validity of Rman backup sets

Rman Backup Recovery experiment Operation Warfare Technique


Often listen to some master said, to do a regular Oracle Database backup recovery experiment, it must wait until the database problem, say what is late. Of course, every company has a different approach and business scenario. In fact, this problem also bothered me for a long time, and then just learned a bit shell knowledge, I think I can use shell script to write some Rman related day-to-day maintenance operations. Thus, from March this year, for nearly one months, the two shell scripts, "Verifying the validity of the Rman backup set" and "Using the Rman backup set for periodic recovery experiments", were released. Finally repeated tests, the normal operation. Today, we share this platform with the community.


One or two kinds of shell script detailed


First, the first shell script, "rman_validate_v2.sh", is used to verify the validity of the Oracle Rman backup set.


Introduction to script Content


For the script annotation section, see the following figure:



This part is a number of annotated content, the first red box is the personal name, email mailbox and my technical blog address; the second red box is the database type, the operating system type, the script file name, the script type, and the purpose of the script; the third red box is a matter of note, Is that the script file is first to run after the test environment test passes through to the production environment.


Script variable definition section, look at the following figure:



The first red box is the environment variable in which the. bash_profile file is imported; the second red box is the absolute path that defines the outer variable of the shell; the third red box defines some common string variables, such as the location of the Rman backup set, the location of the Rman log, and so on.


The script "queries the Bs_key value of the Rman backup set" section, as shown in the following illustration:



To explain the contents of the red box above, through the Sqlplus command to connect to the database, using SQL statements to find the previous day of the Rman backup set of the Bs_key value saved to a variable bskey_list, this value can be more than one yo, so again with a variable bskey_list_ With_comma these values together with commas.


The script "Validate checksum" section, as shown in the following illustration:



This is also the most critical aspect of the entire shell script, using the "Validate Backupset Bs_key value list check logical;" (Shaped like validate backupset 6197,6198,6199,6200,6201,6202 ...) 6210 check logical; This command sequentially verifies the validity of all Rman backup sets that were generated the day before. Because our Rman backup uses a redundancy strategy of one week, Friday full, Saturday to next week Thursday for an incremental level 1 backup, which is the entire backup cycle of Rman. So, I was the same night that the day before the validation of the Rman backup generated. If you are in a company with a large amount of data, you can also perform a 1-week check, then this situation, the script content will be modified accordingly.


The above is all the contents of the shell script, "Verifying the validity of Rman backup sets."


Next, the second shell script is used to perform the Rman recovery experiment. Strictly speaking, it is not a shell script can be done, according to the entire recovery experiment, the need for 5 shell scripts, as shown in the following figure:



In order to let you better understand these 5 shell script files, I wrote 2 readme txt file, a Chinese version, an English version, see the following figure:



Introduction to the description file for the shell script


Readme_cn. TXT introduction, see the following figure:



Reamdme_en. TXT introduction, see the following figure:



Introduction to each shell script file


(1) The content of "ssh_mutual_trust_linux_for_source.sh", see the following figure:



The first red box is the absolute path that defines some shell external commands; The second red box is to add the host name of the remote host and the corresponding IP address to the/etc/hosts file under root; The added format is placed in the # comment For example four lines below The third red box is the log file name generated when you set up the SSH Trust feature.


The following is a partial hint code for ping remote host, which is the host for Rman recovery, as shown in the following illustration:



How to ping the remote host, will output "proceeding further ...", otherwise it will output "exiting now ..." and directly exit the shell script run, the following is to ping the remote host, will be on the source host to generate a RSA algorithm public and private key pair and transfer the public key file to the remote host, as shown in the following figure:



The two command actions in the red box are the case of generating key pairs and sending public keys.


(2) The content of "ssh_mutual_trust_linux_for_target.sh", see the following figure:



The previous Code section is the same as the script file "ssh_mutual_trust_linux_for_source.sh", and the only difference is the content added to the file/etc/hosts above.


(3) The content of "collect_info_from_source_oracle.sh". Since the code for this shell script file has 694 lines, just intercept the most critical part of it, as shown in the following illustration:



is to obtain the value of the above 28 variables from the source Oracle database, such as "host name, operating system name, database name, archive log path, path to Rman backup, total size of Rman backup (in megabytes), path for listening to files and password files, and so on."


(4) The contents of "scp_log_file_to_target.sh" are as follows:



The first red box defines the location of the log file generated by the script "collect_info_from_source_oracle.sh" on the source Oracle database. The second red box is to use the SCP command to remotely copy the log file to the host on which the Rman recovery is to be performed.


(5) The content of "rman_restore_and_recover_to_target_oracle.sh". Since this shell script file has 536 lines, it is only the most important part of the interception I think, see the following figure:



The contents of the Red frame circle indicate that you want to create these 8 basic directories with the "mkdir–p" command on the target host, of course, the disk space required on the target host is greater than the amount of space given by the source host, which is beyond doubt. As long as this step is done, the Rman backup set and other files can be replicated remotely and so on, so this procedure is critical. Finally, the SPFile and control files are restored in turn, the database is booted to Mount state, and the database is restored and restored with the Rman restore and recover commands.


Ii. verifying the effectiveness of Rman backup set operation


A week of Rman backup content, see the following figure:



"2017-05-05" This day is Friday, "2017-05-11" This day is Thursday, this time is just a full Rman backup. 05-05 of them are full backups, with a data volume of 11G, and the remaining six days as incremental backups, so the amount of data is small. After the date is the automatic backup of the control file, but also kept for a week, but to be on the day of the Rman recovery experiment, but to use which day yo.


A week of Rman checksum log files, see the following figure:



Friday Rman fully backed up the contents of the file, see the following figure:



Friday Rman Checksum generated log file contents, see the following figure:



The first red box is the file name of the checksum log (yesterday, Saturday night checksum, this is the Friday Rman Backup), the following three red boxes are the 3 Rman backup set files (0-level incremental backup data files), followed by the archive log for verifying the backup and the contents of the control file for automatic backup, see the following figure:



The contents of the file for the Saturday Rman incremental backup, see the following figure:



Saturday Rman Checksum generated log file contents, see the following figure:


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.