簡體   English   中英

Windows XP SP3 MySQL 自動備份出錯

[英]Windows XP SP3 MySQL automatic backup error

在嘗試使用 Java 進行自動 MYSQL 備份時,我不斷收到以下錯誤,並且整個上午都在嘗試解決問題。 系統為WindowsXP SP3,運行Apache Tomcat 6,Java 1.6.25

我不斷收到此錯誤:

ERROR com.busytech.barba.exception.BarbaException – java.io.IOException: Cannot run program “C:\Program”: CreateProcess error=2, The system cannot find the file specified
com.busytech.barba.exception.BarbaException: Cannot run program “C:\Program”: CreateProcess error=2, The system cannot find the file specified
at com.busytech.barba.persistence.BackUpAndRestoreDatabaseManager.getTableBackup(BackUpAndRestoreDatabaseManager.java:52)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.processRequest(CashSummaryServlet.java:95)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.doPost(CashSummaryServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
at java.lang.Thread.run(Unknown Source)
java.io.IOException: Cannot run program “C:\Program”: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at com.busytech.barba.persistence.BackUpAndRestoreDatabaseManager.getTableBackup(BackUpAndRestoreDatabaseManager.java:30)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.processRequest(CashSummaryServlet.java:95)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.doPost(CashSummaryServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 21 more
347156 [http-8080-4] ERROR com.busytech.barba.exception.BarbaException – java.io.IOException: Cannot run program “C:\Program”: CreateProcess error=2, The system cannot find the file specified
com.busytech.barba.exception.BarbaException: Cannot run program “C:\Program”: CreateProcess error=2, The system cannot find the file specified
at com.busytech.barba.persistence.BackUpAndRestoreDatabaseManager.getTableBackup(BackUpAndRestoreDatabaseManager.java:52)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.processRequest(CashSummaryServlet.java:95)
at com.busytech.barba.servlet.checkcash.CashSummaryServlet.doPost(CashSummaryServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:864)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1665)
at java.lang.Thread.run(Unknown Source)

這是一個補充:這是我所做的嘗試{

Process run = null;
        if (System.getProperty("os.name").toLowerCase().contains("window")) {
            run = Runtime.getRuntime().exec(SystemInformation.getWindowsMySQLDump() + " --host=" + host + " --port=" + port
                    + " --user=" + user + " --password=" + password
                    + " --compact --complete-insert --extended-insert "
                    + "--skip-comments --skip-triggers --skip-lock-tables --single-transaction " + database + " " + table);

        } else {
            run = Runtime.getRuntime().exec("mysqldump --host=" + host + " --port=" + port
                    + " --user=" + user + " --password=" + password
                    + " --compact --complete-insert --extended-insert "
                    + "--skip-comments --skip-triggers --skip-lock-tables --single-transaction " + database + " " + table);
        }
        InputStream in = run.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        int count;
        char[] cbuf = new char[BUFFER];

        while ((count = br.read(cbuf, 0, BUFFER)) != -1) {
            temp.append(cbuf, 0, count);
        }
        br.close();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

不確定這是一個 MySQL 或備份問題,但從錯誤:

無法運行程序“C:\Program”

看起來您忘記在某處的字符串周圍加上引號。

如果你嘗試運行

c:\program files\myapp\something.exe

然后它可能會在第一個空間分裂,所以你試圖執行c:\program - 我懷疑它是一個實際的可執行文件。 嘗試

"c:\program files\myapp\something.exe"

問題是您的應用程序(在您的情況下可能是 MySQL)的安裝路徑。

C:\Program Files\MySQL\bin\mysql.exe

“Program Files”中的空白導致問題,您沒有在其上加引號。

“C:\Program Files\MySQL\bin\mysql.exe”

您可以使用Apache Exec從 Java 啟動進程。當從 Java 應用程序啟動進程時,這會處理所有可能 go 錯誤的常見內容

如果您可以提供更多信息,您將如何嘗試啟動該過程。

這是我推薦的(使用 Apache Commons Exec 的實現)。

CommandLine cmdLine = CommandLine.parse("C:\\Program Files\\MySQL\\bin\\mysqldump");
cmdLine.addArgument("--user=");
// add further args here
Executor executor = new DefaultExecutor();
OutputStream stdOut = new ByteArrayOutputStream();
    PumpStreamHandler psh = new PumpStreamHandler(stdOut);
    executor.setStreamHandler(psh);

    try {
        int exitCode = executor.execute(cmdLine);
        String output = stdOut.toString();

        BufferedReader lineReader = new BufferedReader(new StringReader(output));

        String line;
        while ((line = lineReader.readLine()) != null) {
            log.debug("Reading line #{} - '{}'", lineCount, line);
        }

    } catch (IOException e) {
        // handle the exception
    }

這是我使用的解決方案,它在 windows 和 linux 上的工作方式與上述使用 apache commons exec 的建議相同:

        String cmdline = "mysqldump";
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        CommandLine commandLine = CommandLine.parse(cmdline);
        commandLine.addArgument("--host=" + dbhost);
        commandLine.addArgument("--port=" + dbport);
        commandLine.addArgument("--user=" + dbuser);
        commandLine.addArgument("--password=" + dbpass);
        commandLine.addArgument(database);

        Set keys = table.keySet();
        for (Iterator i = keys.iterator(); i.hasNext();) {
            String key = (String) i.next();
            String value = (String) table.get(key);
            commandLine.addArgument(value);
        }
        commandLine.addArgument("-r");
        //outputFile might be a file on the server that can be downloaded
        //used apache file upload to download the files from the server
        commandLine.addArgument(outputFile);
        Executor executor = new DefaultExecutor();
        executor.execute(commandLine, resultHandler);
        resultHandler.waitFor();

並將文件恢復到服務器,上傳文件,這里是從 mysqldumpfile 恢復的代碼,如果在 windows 上的環境變量上僅設置了 mysql 路徑,但在 linux 上它按原樣工作

        String cmdline = "mysql";
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        CommandLine commandLine = CommandLine.parse(cmdline);
        commandLine.addArgument("--user=" + dbuser);
        commandLine.addArgument("--password=" + dbpass);
        commandLine.addArgument("--force");
        commandLine.addArgument("-v");
        commandLine.addArgument("-e");
        commandLine.addArgument("source");
        commandLine.addArgument(backUpFile);
        commandLine.addArgument(database);
        Executor executor = new DefaultExecutor();
        executor.execute(commandLine, resultHandler);
        resultHandler.waitFor();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM