Tudo bom pessoal?
Então, o problema é o seguinte:
Preciso compactar(zip) no arquivo “athus_bkp.sql” depois que foi criado.
Este arquivo é um bkp do banco, e precisaria compacta-lo para naum ficar tão grande!
O código é este:
public class BackupDB {
public void realizarBackup() throws Exception{
Runtime r = Runtime.getRuntime();
try{
String diretorioPg = DiretorioPostgresUtil.getDiretorioPgDump();
String fileBackup = CaminhoUtils.CAMINHO_PASTA_ATHUS + "backup"
+ File.separatorChar + "athus_bkp.sql";
File file = new File(fileBackup);
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
diretorioPg = diretorioPg.concat(" -U postgres --file=\""+fileBackup+"\" athus");
System.out.println(diretorioPg);
Process p = r.exec(diretorioPg);
int i = p.waitFor();
if(i > 0){
InputStreamReader streamReader = new InputStreamReader(p.getErrorStream());
BufferedReader reader = new BufferedReader(streamReader);
String linha;
while((linha = reader.readLine()) != null){
System.err.println(linha);
}
}
System.out.println("Backup realizado com sucesso!");
}catch(IOException ex){
System.out.println("Erro ao tentar realizar o backup!"+ex.getMessage());
}
}
public static void main(String[] args) throws Exception{
BackupDB b = new BackupDB();
b.realizarBackup();
}
}
Obrigado, desde já, pela ajuda!
