用ANT啟動oracle資料庫

來源:互聯網
上載者:User
啟動oracle資料庫,操作有兩個:
1.         啟動監聽:
              <exec executable="lsnrctl" >
                     <arg line=" start "/>
              </exec>

2.         開啟資料庫執行個體:
              <exec executable='cmd' >
                     <arg line="/c net start oracleservice${ORA_SID} "/>
              </exec>
    
    第一個操作在這裡沒有什麼區別,就是ant調用系統命令的標準用法,我們來看一下第二個命令, net start oracleservice${ORA_SID},如果你直接放入到executable屬性中,執行結果一定會是:

BUILD FAILED: E:\java\TestAnt\build.xml:44: Execute failed: java.io.IOException: CreateProcess: "net start oracleservicemy_oracle" error=2
       痛苦吧,帶有空格的命令應該使用以下方法:
              <exec executable='cmd' >
                     <arg line="/c net start oracleservice${ORA_SID} "/>
              </exec>

使用 tstamp target可以非常方便的定義日期屬性:
              <tstamp>
                     <format property="DB_BACKUP_TIME" pattern="yyyy-MM-dd"/>
              </tstamp>

附錄:參考指令碼
<!-- 2005 by guipei. -->
<project name="TestAntOracle"  default="demo"  basedir="./">
       <!-- set global properties for this build -->
       <property name="DB_BACKUP_DIR" value="." />
       <property name="ORA_SID" value="my_oracle"/>
       <property name="ORA_USER" value="scott"/>
       <property name="ORA_PWD" value="tiger"/>
       <property name="ORA_RESTORE_FILE" value="db_back.dmp"/>   
       <target name="demo" >
              <echo> ant db_backup to backup db </echo>
              <echo> ant db_restore to restore db </echo>
              <echo> ant db_start to start db </echo>
              <echo> ant db_stop to stop db </echo>
       </target>
       <target name="db_backup">
              <tstamp>
                     <format property="DB_BACKUP_TIME" pattern="yyyy-MM-dd"/>
              </tstamp>
              <property name="DB_BACKUP_FILE" value="MYDB_${DB_BACKUP_TIME}.DMP" />
              <echo>will backup db at ${DB_BACKUP_FILE}</echo>
              <exec dir="${DB_BACKUP_DIR}" executable="exp" >
                   <arg line=" ${ORA_USER}/${ORA_PWD}@${ORA_SID} file=MYDB_${DB_BACKUP_TIME}.DMP  "/>
              </exec>
       </target>
       <target name="db_restore">
              <exec dir="${DB_BACKUP_DIR}" executable="imp" >
                     <arg line=" ${ORA_USER}/${ORA_PWD}@${ORA_SID} file=${ORA_RESTORE_FILE} full=y"/>
              </exec>
       </target>
       <target name="db_start">
              <exec executable="lsnrctl" >
                     <arg line=" start "/>
              </exec>
              <exec executable='cmd' >
                     <arg line="/c net start oracleservice${ORA_SID}  "/>
              </exec>
       </target>
       <target name="db_stop">
              <exec executable="lsnrctl" >
                     <arg line=" stop "/>
              </exec>
              <exec executable='cmd' >
                     <arg line="/c net stop oracleservice${ORA_SID}  "/>
              </exec>
       </target>
</project>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.