BAT scripting Learn -4:oracle automatic backup restore script

Source: Internet
Author: User

Get a copy of Oracle's automated backup restore script from a colleague, looks very powerful, bitter in the bat syntax is not familiar, looked for a half-day document, first understand a small paragraph

@echo ifREMin batch, we can use Setloacl enabledelayedexpansion this command to enable "deferred environment variable extension"REMafter we have "deferred environment variable extension" enabled, when Cmd interprets a command with nested formatting, he executes the nested command one at a time before matching.REMso our assignment will be done. And then when the "Delay environment variable extension" is enabled, CMD will use the! Number to determine if this is a variableREMIf you do not enable the variable with%name% such a format to judge, enabled after the use of!name! such a format to judge, this symbol we need to pay attention to!setlocalenabledelayedexpansion::reading configuration FilesEchoReading configuration file ...Set"Base64=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/="REMIf you execute a command, but do not want to see the execution of the command on the screen, you can use "[command]>nul" to block the output of the command on the screen.REMHowever, some command execution will be wrong, that is, the use of ">nul" can not block the command generated information, so in the back with "2>nul" thisREMis "[Command]>nul+ Space +2>nul", so that no matter whether the command is running correctly, will not be seen on the screen generated by this command screen display. REMThe role here is to create a new folder in the system directory, if there is an error, but the NUL screen, will not see the output of the error promptMD%windir%\oracleautobackup >nul 2>nulSetConfigfile=%windir%\oracleautobackup\config.INISetI=0REMIf the file does not exist, create a new line and output a newline characterREM. Represents a newline,> means output to a fileif  not exist%configfile%Echo.>%configfile%REMThe consciousness behind the delims= character is that the contents of each line of the text are divided into columns after the delims= character.REMdelims= can be more than one character later, either a space or nothing.REMWhat doesn't mean anything? It is not the division of anything, but the whole line of content.REMbecause the for default is delimited by, and whitespace, it is generally used to get the entire line of content that usually uses the form "delims=" to cancel the default delimiter for the for. for/F "delims="%%x in (%configfile%) Do(REMi is a global variable    if!i!==0Setbak_hou=%%xif!i!==1Setbak_lot=%%xif!i!==2SetBak_dir=%%xREMGTR indicates greater than    REMset/a represents a numeric operation    REMcall represents the calling function    if!i! GTR 2 (Set/A Gup=!i!-2Pager : Base64_str"%%x"SetOra[!gup!] =!val! )Set/a i+=1)CLS::take the default valueREM^ Indicates the beginning of the line, "^step" matches only the first word in "Step Hello World"REM$ means end of line, "step$" matches only the last word in "Hello World Step"REM* Indicates a repeat number of 0 or more timesREM^[0-9]*$ represents a pure numberREM| | You can execute multiple commands at the same time, and when you run into the correct command, the subsequent commands are no longer executed. If it has not been correct, the execution is complete.REM&& can execute multiple commands at the same time, and when it encounters a command that executes the error, the subsequent command is no longer executed. If there has been no error, the execution is completeREM& executes multiple commands at the same time, regardless of whether or not the command executes successfullyREMso these two meanings are assigned if it is empty, and if it is a number, the value is not assigned, and the original value is preserved.if"!bak_hou!" ==""SetBak_hou=3Echo!bak_hou!| Findstr "^[0-9]*$" >nul | |SetBak_hou=3if"!bak_lot!" ==""SetBak_lot=7Echo!bak_lot!| Findstr "^[0-9]*$" >nul | |SetBak_lot=7REM%cd% represents the current folder (the folder where the execution occurs),%~dp0 indicates the folder where the batch file is locatedif"!bak_dir!" ==""Setbak_dir=%CD%\Database BackupREMThe meaning of "delims=" is to cancel the default delimiter, so it will copy the contents of the line.REM"tokens=*" means getting all the content on the line, but ignores all the spaces at the beginning of the row. REM%~fi-Will%I To a fully qualified path name, this I is actually the variable we are bringing in for, here x for/F "tokens=*"%%x in ("!bak_dir!") Do SetBak_dir=%%~fxif  not exist!bak_dir!MD!val! >nul 2>nul::Get rid of malformed database connection configuration ItemsSetJ=0 for%%i in (1,2,3,4,5,6,7,8,9) Do(REM&& can execute multiple commands at the same time, and when it encounters a command that executes the error, the subsequent command is no longer executed. If there has been no error, the execution is complete    SetOra[%%i]>nul 2>nul&& (REMNo value after set indicates empty variable        SetOra_cur=REMUSEBACKQ is an enhanced parameter, and when this parameter is used, the first notation in the original for statement is changed as follows:        REMif the object in the first parenthesis is a command statement, the original single quotation mark ' should be replaced with a post quote ';        REMif the object in the first parenthesis is a string, the original double quotation mark "is changed to single quote";        REMif the object in the first parenthesis is a file name, enclose it in double quotes .                REMTokens=1-3 "for the 1 to 3 columns, behind the suspect is%%a, how can it be%%b?"          for/F "Usebackq delims==. Tokens=1-3 "%%a in ('SetOra[%%i] ') Do SetOra_cur=%%bSetora[%%i]=REM\ \ means escaped/        Echo!ora_cur!| Findstr "\" >nul 2>nul &&Echo!ora_cur!| Findstr "@" >nul 2>nul && (Set/A J+=1SetOra[!j!] =!ora_cur! )    ))

Wrote a lot of notes in order to understand

BAT scripting Learn -4:oracle automatic backup restore 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.