@@ -37,8 +37,13 @@ public static String dumpToString(String jdbcUrl, String username, String passwo
3737
3838 public static String dumpToString (String jdbcUrl , String username , String password , List <Schema > schemas ,
3939 PostgresDumpOption ... options ) {
40+ return dumpToString (jdbcUrl , username , password , schemas , List .of (), options );
41+ }
42+
43+ public static String dumpToString (String jdbcUrl , String username , String password , List <Schema > schemas ,
44+ List <String > excludeTableDataPatterns , PostgresDumpOption ... options ) {
4045 try (StringWriter writer = new StringWriter ()) {
41- dump (writer , jdbcUrl , username , password , schemas , options );
46+ dump (writer , jdbcUrl , username , password , schemas , excludeTableDataPatterns , options );
4247 return writer .toString ();
4348 } catch (IOException e ) {
4449 throw new RuntimeException (e );
@@ -52,8 +57,14 @@ public static void dumpToFile(Path path, String jdbcUrl, String username, String
5257
5358 public static void dumpToFile (Path path , String jdbcUrl , String username , String password ,
5459 PostgresDumpFormat format , List <Schema > schemas , PostgresDumpOption ... options ) {
60+ dumpToFile (path , jdbcUrl , username , password , format , schemas , List .of (), options );
61+ }
62+
63+ public static void dumpToFile (Path path , String jdbcUrl , String username , String password ,
64+ PostgresDumpFormat format , List <Schema > schemas , List <String > excludeTableDataPatterns ,
65+ PostgresDumpOption ... options ) {
5566 try (OutputStream outputStream = Files .newOutputStream (path )) {
56- dump (outputStream , jdbcUrl , username , password , format , schemas , options );
67+ dump (outputStream , jdbcUrl , username , password , format , schemas , excludeTableDataPatterns , options );
5768 } catch (IOException e ) {
5869 throw new RuntimeException (e );
5970 }
@@ -66,7 +77,12 @@ public static void dump(Writer writer, String jdbcUrl, String username, String p
6677
6778 public static void dump (Writer writer , String jdbcUrl , String username , String password , List <Schema > schemas ,
6879 PostgresDumpOption ... options ) {
69- dump (jdbcUrl , username , password , PostgresDumpFormat .PLAIN_TEXT , schemas , inputStream -> {
80+ dump (writer , jdbcUrl , username , password , schemas , List .of (), options );
81+ }
82+
83+ public static void dump (Writer writer , String jdbcUrl , String username , String password , List <Schema > schemas ,
84+ List <String > excludeTableDataPatterns , PostgresDumpOption ... options ) {
85+ dump (jdbcUrl , username , password , PostgresDumpFormat .PLAIN_TEXT , schemas , excludeTableDataPatterns , inputStream -> {
7086 try (InputStreamReader inputStreamReader = new InputStreamReader (inputStream , ENCODING )) {
7187 return inputStreamReader .transferTo (writer );
7288 }
@@ -80,14 +96,21 @@ public static void dump(OutputStream outputStream, String jdbcUrl, String userna
8096
8197 public static void dump (OutputStream outputStream , String jdbcUrl , String username , String password ,
8298 PostgresDumpFormat format , List <Schema > schemas , PostgresDumpOption ... options ) {
83- dump (jdbcUrl , username , password , format , schemas , inputStream -> inputStream . transferTo ( outputStream ), options );
99+ dump (outputStream , jdbcUrl , username , password , format , schemas , List . of ( ), options );
84100 }
85101
86- public static void dump (String jdbcUrl , String username , String password , PostgresDumpFormat format ,
87- List <Schema > schemas , ThrowingFunction < InputStream , Long > inputStreamProcessor ,
102+ public static void dump (OutputStream outputStream , String jdbcUrl , String username , String password ,
103+ PostgresDumpFormat format , List <Schema > schemas , List < String > excludeTableDataPatterns ,
88104 PostgresDumpOption ... options ) {
105+ dump (jdbcUrl , username , password , format , schemas , excludeTableDataPatterns ,
106+ inputStream -> inputStream .transferTo (outputStream ), options );
107+ }
108+
109+ private static void dump (String jdbcUrl , String username , String password , PostgresDumpFormat format ,
110+ List <Schema > schemas , List <String > excludeTableDataPatterns ,
111+ ThrowingFunction <InputStream , Long > inputStreamProcessor , PostgresDumpOption ... options ) {
89112 try (GenericContainer <?> container =
90- createPgDumpInContainer (jdbcUrl , username , password , format , schemas , options )) {
113+ createPgDumpInContainer (jdbcUrl , username , password , format , schemas , excludeTableDataPatterns , options )) {
91114 container .start ();
92115
93116 container .copyFileFromContainer (CONTAINER_DUMP_FILE , inputStreamProcessor );
@@ -96,9 +119,10 @@ public static void dump(String jdbcUrl, String username, String password, Postgr
96119
97120 private static GenericContainer <?> createPgDumpInContainer (String jdbcUrl , String username , String password ,
98121 PostgresDumpFormat format , List <Schema > schemas ,
122+ List <String > excludeTableDataPatterns ,
99123 PostgresDumpOption ... options ) {
100124 ConnectionInformation connectionInformation = PostgresUtils .parseConnectionInformation (jdbcUrl , username , password );
101- String [] command = createPgDumpCommand (connectionInformation , format , schemas , options );
125+ String [] command = createPgDumpCommand (connectionInformation , format , schemas , excludeTableDataPatterns , options );
102126
103127 log .debug ("Executing {}" , String .join (" " , command ));
104128
@@ -113,7 +137,8 @@ private static GenericContainer<?> createPgDumpInContainer(String jdbcUrl, Strin
113137 }
114138
115139 private static String [] createPgDumpCommand (ConnectionInformation connectionInformation , PostgresDumpFormat format ,
116- List <Schema > schemas , PostgresDumpOption ... options ) {
140+ List <Schema > schemas , List <String > excludeTableDataPatterns ,
141+ PostgresDumpOption ... options ) {
117142 List <String > commandArgs = new ArrayList <>(List .of (
118143 "pg_dump" ,
119144 "--host=" + connectionInformation .host (),
@@ -131,6 +156,10 @@ private static String[] createPgDumpCommand(ConnectionInformation connectionInfo
131156 commandArgs .addAll (schema .getCommandArguments ());
132157 }
133158
159+ for (String excludeTableDataPattern : excludeTableDataPatterns ) {
160+ commandArgs .add ("--exclude-table-data=" + excludeTableDataPattern );
161+ }
162+
134163 for (PostgresDumpOption option : options ) {
135164 commandArgs .add (option .getCommandArgument ());
136165 }
0 commit comments