程序实现postgresql备份还原

1、windows下Java程序备份还原:

①、备份:

String command = "cmd /c pg_dump -h "+hostName+" -o -U "+userName+" -F t -d "+dbName+" > " + pathName + File.separator  + fileName;  

Runtime.getRuntime().exec(command);

②、还原:

String command = "cmd /c pg_restore -h "+hostName+" -U "+userName+" -c -d "+dbName+" < " + fileNamePath;

Runtime.getRuntime().exec(command);

2、linux下Java程序备份还原:

①、备份:
String[] command = new String[]{"sh","-c","pg_dump -h "+hostName+" -o -U "+userName+" -F t -d "+dbName+" > " + pathName + File.separator +fileName}; 
Runtime.getRuntime().exec(command);

②、还原:

String[] command = new String[]{"sh","-c","pg_restore -h "+hostName+" -U "+userName+" -c -d "+dbName+" < " + fileNamePath};

Runtime.getRuntime().exec(command);

你可能感兴趣的:(postgresql,javaEE)