Bat指令碼學習-6:Oracle自動備份還原指令碼

來源:互聯網
上載者:User

標籤:顏色   base   pause   delete   刪除   包括   自動備份   時間   auto   

這次注釋沒寫多少,先跳過一些吧

::2.資料庫到期備份刪除echo.echo.echo 二、正在清除到期的備份檔案……REM wscript.echo是vbs文法,相當於alertREM >是特殊字元,所以放在 for 命令裡面需要使用轉義符號^>,包括^&也是轉義的&REM //Nologo屏弊輸出:Prevent logo display: No banner will be shown at execution timefor /f "tokens=1,2,3 delims=-" %%a in (‘echo wscript.echo date-!bak_lot! ^>t~.vbs ^& cscript //nologo t~.vbs ^& del t~.vbs‘) do (    set y=%%a&set m=%%b&set d=%%c    if %%b lss 10 set m=0%%b    if %%c lss 10 set d=0%%c)REM 此處-為字串串連符set DateE=!y!-!m!-!d!for %%i in (1,2,3,4,5,6,7,8,9) do (    set ora[%%i]>nul 2>nul&& (        set ora_cur=        for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b        set ora_usr=        set ora_net=        for /f "delims=/" %%a in (‘echo !ora_cur!‘) do set ora_usr=%%a        for /f "[email protected] tokens=2" %%a in (‘echo !ora_cur!‘) do set ora_net=%%a        set cur_dir=!bak_dir!\!ora_net!__!ora_usr!        for /f "tokens=*" %%x in ("!cur_dir!") do set cur_dir=%%~fx                echo 檢查今天的備份成功了沒有 >nul        set fnm_pre=!cur_dir!\!ora_net!__!ora_usr!__!date:~0,4!!date:~5,2!!date:~8,2!-& set today_success=0        REM dir /B 只顯示檔案名稱與副檔名,即使用空格式(沒有標題資訊或摘要)        dir !fnm_pre!*.dmp !fnm_pre!*.zip !fnm_pre!*.rar /b >nul 2>nul && set today_success=1        if "!today_success!"=="1" (            echo 判斷檔案夾條件是否滿足 >nul            for %%a in (!cur_dir!\*.dmp,!cur_dir!\*.log,!cur_dir!\*.zip,!cur_dir!\*.rar) do (                echo 判斷檔案名稱條件是否滿足 >nul                set n=%%a&set n=!n:~-17,-9!&set n=!n:~0,4!-!n:~4,2!-!n:~6,2!                set t=%%~ta                set FileDate=!t:~0,10!                if "!n!"=="!FileDate!" (                    echo 判斷時間條件是否滿足 >nul                    if !FileDate! leq %DateE% (                        echo %date:~0,10% %time:~0,8%  刪除到期備份 %%a                        echo %date:~0,10% %time:~0,8%  刪除到期備份 %%a>>!cur_dir!\delete.log                         del /q "%%a"                    )                )            )        ) else (            echo %date:~0,10% %time:~0,8%  [!ora_net!__!ora_usr!]因為今天的備份沒有成功,暫時不刪除到期檔案!            echo %date:~0,10% %time:~0,8%  [!ora_net!__!ora_usr!]因為今天的備份沒有成功,暫時不刪除到期檔案!>>!cur_dir!\delete.log         )    ))::3.完成退出echo.echo.echo 三、本次備份操作完成,即將退出。ping -n 10 127.1 >nul 2>nulexit::=================================以上是備份程式=================================::=================================以下是管理程式=================================REM 初始化標題和顏色:initmode con cols=100 lines=40title Oracle自動備份 color 0e::複製到 Windows 目錄REM  %0 is the actual command that you callREM %~fN (where N is the parameter on the command line you‘re interested in)copy "%~f0" "%windir%\OracleAutoBackup\OracleAutoBackup.bat" >nul 2>nul::註冊計劃任務:regtasksREM sc config (服務名稱)start= auto(注意:start=後面有一個空格.)sc config schedule start= auto >nul 2>nulat|find "服務尚未啟動">nul 2>nul&&(    net start schedule    if not !errorlevel!==0 (        echo Task Scheduler^(計劃任務^)服務未能啟動,程式即將退出!        pause>nul        goto exit    ))set job_tmr=!bak_hou!:00if !bak_hou! lss 10 set job_tmr=0!bak_hou!:00at !job_tmr! /every:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 %windir%\OracleAutoBackup\OracleAutoBackup.bat -backup >nul 2>nulfor /f "usebackq" %%i in (`dir %windir%\tasks\at*.job /b/o:d`) do set lastAt=%%idel %windir%\tasks\Oracle自動備份.job >nul 2>nulrename %windir%\tasks\!lastAt! Oracle自動備份.job::儲存設定檔:saveconfigecho !bak_hou!>%configFile%echo !bak_lot!>>%configFile%echo !bak_dir!>>%configFile%for %%i in (1,2,3,4,5,6,7,8,9) do (    set ora[%%i]>nul 2>nul&& (        set ora_cur=        for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b        call :str_base64 "!ora_cur!"        if not "!val!"=="" echo !val!>>%configFile%    ))::準備資料庫配置字串set ora_str=for %%i in (1,2,3,4,5,6,7,8,9) do (    set ora[%%i]>nul 2>nul&& (        set ora_cur=        for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b        set ora_usr=        set ora_net=        for /f "delims=/" %%a in (‘echo !ora_cur!‘) do set ora_usr=%%a        for /f "[email protected] tokens=2" %%a in (‘echo !ora_cur!‘) do set ora_net=%%a        set ora_str=!ora_str!%%i. !ora_usr!/******@!ora_net!;     ))

 

Bat指令碼學習-6:Oracle自動備份還原指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.