Start Oracle database with ant

Source: Internet
Author: User
Start the Oracle database with two operations:
1. Start the listener:
<Exec executable = "LSNRCTL">
<Arg line = "start"/>
</Exec>

2. open a database instance:




the first operation is no different here, it is the standard usage of ant to call system commands. Let's take a look at the second command, Net start oracleservice $ {ora_sid}. If you put it directly into the executable attribute, the execution result will certainly be:

build failed: e: \ Java \ testant \ build. XML: 44: Execute failed: Java. io. ioexception: CreateProcess: "Net start oracleservicemy_oracle" error = 2
pain point: Use the following method for a command with spaces:


You can use tstamp target to easily define date attributes:
<Tstamp>
<Format property = "db_backup_time" pattern = "yyyy-mm-dd"/>
</Tstamp>

Appendix: Reference script
<! -- 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>

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.