<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 調用mysql備份腳本 1. java調用Linux命令 ~~~ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class RunShell { public int runShell(String[] args) throws IOException, InterruptedException { int exitValue = 0; //腳本執行返回狀態碼 InputStreamReader stdISR = null; // 標準輸入流 InputStreamReader errISR = null; // error流 Process process = null; String command = ""; for (String cmd : args) { command += cmd + " "; } try { process = Runtime.getRuntime().exec(command.trim()); exitValue = process.waitFor(); String line = null; stdISR = new InputStreamReader(process.getInputStream()); BufferedReader stdBR = new BufferedReader(stdISR); while ((line = stdBR.readLine()) != null) { System.out.println("INFO line:" + line); } errISR = new InputStreamReader(process.getErrorStream()); BufferedReader errBR = new BufferedReader(errISR); while ((line = errBR.readLine()) != null) { System.out.println("ERROR line:" + line); } } finally { try { if (stdISR != null) { stdISR.close(); } if (errISR != null) { errISR.close(); } if (process != null) { process.destroy(); } } catch (IOException e) { System.out.println("正式執行命令:" + command + "有IO異常"); } } return exitValue; } } ~~~ 2. 測試類 ~~~ import java.io.IOException; /** * Created by dailin on 2017/12/25. */ public class TestShell { public static void main(String[] args) throws IOException, InterruptedException { RunShell runShell = new RunShell(); int code = runShell.runShell(args); System.out.println("執行狀態:" + code); } } ~~~ 3. 打包到Linux上 maven 加入打包插件 ~~~ <build> <finalName>App</finalName> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>JavaTest.shell.TestShell</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ~~~ 4. shell腳本 ~~~ #!/bin/bash #set -x source $1 DATE=`date +'%Y-%m-%d-%H:%M'` table(){ mysqldump --host=$FROM_IP -u$FROM_USER -p$FROM_PASSWD --databases $FROM_DATABASE --table $TABLES > $BACKUP_DIR/$1_$DATE.sql } databases(){ mysqldump --host=$FROM_IP -u$FROM_USER -p$FROM_PASSWD --databases $FROM_DATABASE > $BACKUP_DIR/$1_$DATE.sql } case $2 in table) table $3 ;; database) databases $3 ;; *) echo "USAGE: $0 <config_file> table|database backup-mark" echo "e.g.: $0 <transfer.properties> device_training_record test" exit 1; ;; esac ~~~ 腳本配置文件 ~~~ #備份數據保存位置 BACKUP_DIR='/data/backup/mysql' #源數據庫 FROM_IP='192.168.56.130' FROM_USER='root' FROM_PASSWD='tuna' #要備份的數據庫以空格分隔 FROM_DATABASE='mybatis laonanhai' #要備份的表以空格分隔 TABLES='' ~~~ 5. 調用jar java -jar <jar文件> 參數。。。。 ~~~ java -jar App.jar /home/tuna/shell/mysql/mysqlbackup.sh /home/tuna/shell/mysql/backup.properties database hellomysql ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看