程序实现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+”
< ” + file
NamePath};

Runtime.getRuntime().exec(command);

转载自:https://blog.csdn.net/wwwxzycom/article/details/72729760

You may also like...

退出移动版