12 Replies Latest reply on Apr 17, 2008 3:11 PM by dcminter

    backup not taking

    843859

      hi to all,
      I've a backup code but that will not be taking the backup..

      String ip="localhost";             String port="3306";             String database="rich";             String user="username";             String pass="password";             String path;             JFileChooser chooser = new JFileChooser();             chooser.setCurrentDirectory(new File("."));             chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);             chooser.showSaveDialog(null);             path = chooser.getSelectedFile().getAbsolutePath();             System.out.println(path);                         String dumpCommand = "mysqldump " + database + " -h " + ip + " -u " + user +" -p" + pass;             Runtime rt = Runtime.getRuntime();             File test=new File(path);             PrintStream ps;             try{                 Process child = rt.exec(dumpCommand);             ps=new PrintStream(test);             InputStream in = child.getInputStream();             int ch;             while ((ch = in.read()) != -1) {             ps.write(ch);             System.out.write(ch); //to view it by console                         }             JOptionPane.showMessageDialog (null,"BackUP Successfully Completed");             InputStream err = child.getErrorStream();             while ((ch = err.read()) != -1) {             System.out.write(ch);             }             }catch(Exception exc) {             exc.printStackTrace();             } 

      This code is throwing this error

      path=/home/VEL AREA/backupfile.sql

      java.io.IOException: Cannot run program "mysqldump": java.io.IOException: error=2, No such file or directory
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
      at java.lang.Runtime.exec(Runtime.java:593)
      at java.lang.Runtime.exec(Runtime.java:431)
      at java.lang.Runtime.exec(Runtime.java:328)
      at richwoods.MasterScreen.actionPerformed(MasterScreen.java:682)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
      at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1216)
      at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1257)
      at java.awt.Component.processMouseEvent(Component.java:6038)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
      at java.awt.Component.processEvent(Component.java:5803)
      at java.awt.Container.processEvent(Container.java:2058)
      at java.awt.Component.dispatchEventImpl(Component.java:4410)
      at java.awt.Container.dispatchEventImpl(Container.java:2116)
      at java.awt.Component.dispatchEvent(Component.java:4240)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
      at java.awt.Container.dispatchEventImpl(Container.java:2102)
      at java.awt.Window.dispatchEventImpl(Window.java:2429)
      at java.awt.Component.dispatchEvent(Component.java:4240)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
      Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
      at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
      at java.lang.ProcessImpl.start(ProcessImpl.java:65)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
      ... 31 more

      Help me plz..
      Thanks in Advance..

        • 1. Re: backup not taking
          843859
          Hi,

          Choose file path without space and try.

          path=/home/VELAREA/backupfile.sql


          Regards,
          Ram.
          • 2. Re: backup not taking
            843859
            Thanks for the response..
            The same code is worked well before 2 days ,but now it's not working and also i tried as you said.. but no changes happened still throwing the same error..

            Help me plz.. I'm in the end of my project and wait for the backup.


            Thanks in Advance...
            • 3. Re: backup not taking
              843859
              Hi,

              Try using redirect command output directly to the file as below.
              String dumpCommand = "mysqldump " + database + " -h " + ip + " -u " + user +" -p" + pass +" > "+path;
              Regards,
              Ram
              • 4. Re: backup not taking
                843859
                i tried your way also but no imporvement...
                • 5. Re: backup not taking
                  843859
                  NO one is there,, somebody help me........
                  • 6. Re: backup not taking
                    dcminter
                    Well, the Java app can't find the mysqldump application. Presumably you need to ensure there's an appropriate entry in the PATH environment variable, or alternatively you need to use the fully qualified path to the mysqldump application.

                    If it used to work and now it doesn't, then undo whatever you changed in the interim.
                    • 7. Re: backup not taking
                      843859
                      thank god for you response, i'm changed anything instead i had changed the database name only and the path
                      and now i run the program again , it is throwing the error as given below..

                      java.io.IOException: Cannot run program "mysqldump": CreateProcess error=2, The system cannot find the file specified
                      at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
                      at java.lang.Runtime.exec(Runtime.java:593)
                      at java.lang.Runtime.exec(Runtime.java:431)
                      at java.lang.Runtime.exec(Runtime.java:328)
                      at richwoods.BackUP.export(BackUP.java:23)
                      at richwoods.BackUP.main(BackUP.java:42)

                      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.<init>(ProcessImpl.java:81)
                      at java.lang.ProcessImpl.start(ProcessImpl.java:30)
                      at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
                      ... 5 more
                      BUILD SUCCESSFUL (total time: 0 seconds)
                      I'm end of my project..
                      so help me....plz........
                      • 8. Re: backup not taking
                        dcminter
                        It's the path to mysqldump NOT the path to the sql file that's the problem here.

                        You've changed the PATH environment variable, or you are otherwise running this program in a different way from when it worked. This isn't an opinion - there's no magic here, if it's behaving differently it's because something changed.

                        There are only three ways this can possibly work:

                        If the path to mysqldump is currently set in the PATH environment variable for the account that's running this
                        If the path to mysqldump is explicitly specified (it isn't).
                        If you are running the Java application from the directory containing the mysqldump binary (unlikely).

                        Therefore

                        1. Fix the PATH environment variable or
                        2. Explicitly state the full path to mysqldump in the Java application.
                        • 9. Re: backup not taking
                          843859
                          Sorry i didn't understand the three possible ways ...
                          so could you explain me by an example and how to set PATH environment to mysqldump
                          • 10. Re: backup not taking
                            843859
                            Hi,

                            Locate mysql installtion path by using below command
                            $:whereis mysql
                            String dumpCommand = "mysqlpath/bin/mysqldump " + database + " -h " + ip + " -u " + user +" -p" + pass;
                            Regards,
                            Ram
                            • 11. Re: backup not taking
                              843859
                              Now it is working fine good.. thanks,,,
                              but, is this wirght way to give the entire path, actually we have given the path for mysqldump as

                              C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump

                              and packed as jar file,
                              when we install the jar file in the client side he may installed the MySql in some other location means what i should do..

                              This is a suggestion i'm asking you..

                              Thanks, thanks a lot for the response
                              • 12. Re: backup not taking
                                dcminter
                                He should use a magic wand to find out what path to use. Well, what do you expect the answer to be!?