Olá pessoal.

Estou tentando fazer o seguinte:

    public void realizaBackup() {
        Runtime r = Runtime.getRuntime();
        String ip="";
        try {
            BufferedReader in = new BufferedReader(new
FileReader("./IP.txt"));
            String str;
            while((str = in.readLine()) != null){
                //JOptionPane.showMessageDialog(null, str);
                ip = str;
            }
            in.close();
            }catch (Exception ex) {
                ex.printStackTrace();
            }
        System.out.println(ip);
        try {
            String cmd = "pg_dump -i -h "+ ip +" -p 5432 -U postgres -F c
-b -o -v -f \"H:/Backup/BDFisio.backup \" \"fisio\"";
            System.out.println(cmd);
            Process p = r.exec("pg_dump -i -h"+ ip +"-p 5432 -U postgres -F
c -b -o -v -f \"H:/Backup/BDFisio.backup \" \"fisio\"");

            if (p != null) {
                OutputStream outputStream = p.getOutputStream();
                outputStream.write("123\r\n".getBytes());
                outputStream.flush();
                outputStream.close();
                InputStreamReader streamReader = new
InputStreamReader(p.getErrorStream());
                BufferedReader reader = new BufferedReader(streamReader);
                String linha;
                while ((linha = reader.readLine()) != null) {
                    System.out.println(linha);
                }
            }

            JOptionPane.showMessageDialog(null, "Backup realizado com
sucesso!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(null, "Erro ao tentar realizar o
backup!\n" + ioe.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
            ioe.printStackTrace();
        }
    }

O meu retorno no console é o seguinte

run:
127.0.0.1
pg_dump -i -h 127.0.0.1 -p 5432 -U postgres -F c -b -o -v -f
"H:/Backup/BDFisio.backup " "fisio"
pg_dump: too many command-line arguments (first is "-U")
Try "pg_dump --help" for more information.

Não estou conseguindo enxergar o erro!

Quando executo o arquivo de lote contendo o código abaixo ele funciona
perfeitamente

@echo off
SET PGUSER=postgres
SET PGPASSWORD=123
if exist H:\Backup (chdir H:\Backup) else (mkdir H:\Backup)
echo "Aguarde, realizando o backup do Banco de Dados"
for /f "tokens=1,2,3,4 delims=/ " %%a in ('DATE /T') do set Date=%%b-%%c-%%d
rem O comando acima serve para armazenar a data no formato dia-mes-ano na
variável Date;
pg_dump -i -h localhost -p 5432 -U postgres -F c -b -o -v -f
"H:\Backup\BDFisio%Date%.backup" fisio
pause
exit

Alguém pode me dizer onde está o erro!

valeu galera
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a