【问题标题】:Windows XP SP3 MySQL automatic backup errorWindows XP SP3 MySQL自动备份错误
【发布时间】:2012-04-05 09:26:17
【问题描述】:

在尝试使用 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();
    }

【问题讨论】:

    标签: java mysql windows-xp backup


    【解决方案1】:

    不确定这是 MySQL 还是 Backup 问题,但来自错误:

    无法运行程序“C:\Program”

    您似乎忘记在某处为字符串加上引号。

    如果你尝试运行

    c:\program files\myapp\something.exe
    

    那么它可能会在第一个空格处拆分,因此您正在尝试执行 c:\program - 我怀疑它是一个实际的可执行文件。 试试

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

    【讨论】:

      【解决方案2】:

      问题在于您的应用程序(在您的情况下可能是 MySQL)的安装路径。

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

      “程序文件”中的空白会导致问题,您不要在上面加上引号。

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

      您可以使用Apache Exec 从 Java 启动进程。这可以处理从 Java 应用程序启动进程时可能出错的所有常见问题

      如果您能提供更多信息,您将如何尝试启动该过程。

      这是我推荐的(使用 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
          }
      

      【讨论】:

        【解决方案3】:

        这是我使用的解决方案,它就像在 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();
        

        【讨论】:

          猜你喜欢
          • 2012-04-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-27
          • 2010-10-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多