@@ -37,8 +37,13 @@ public static String dumpToString(String jdbcUrl, String username, String passwo
37
37
38
38
public static String dumpToString (String jdbcUrl , String username , String password , List <Schema > schemas ,
39
39
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 ) {
40
45
try (StringWriter writer = new StringWriter ()) {
41
- dump (writer , jdbcUrl , username , password , schemas , options );
46
+ dump (writer , jdbcUrl , username , password , schemas , excludeTableDataPatterns , options );
42
47
return writer .toString ();
43
48
} catch (IOException e ) {
44
49
throw new RuntimeException (e );
@@ -52,8 +57,14 @@ public static void dumpToFile(Path path, String jdbcUrl, String username, String
52
57
53
58
public static void dumpToFile (Path path , String jdbcUrl , String username , String password ,
54
59
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 ) {
55
66
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 );
57
68
} catch (IOException e ) {
58
69
throw new RuntimeException (e );
59
70
}
@@ -66,7 +77,12 @@ public static void dump(Writer writer, String jdbcUrl, String username, String p
66
77
67
78
public static void dump (Writer writer , String jdbcUrl , String username , String password , List <Schema > schemas ,
68
79
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 -> {
70
86
try (InputStreamReader inputStreamReader = new InputStreamReader (inputStream , ENCODING )) {
71
87
return inputStreamReader .transferTo (writer );
72
88
}
@@ -80,14 +96,21 @@ public static void dump(OutputStream outputStream, String jdbcUrl, String userna
80
96
81
97
public static void dump (OutputStream outputStream , String jdbcUrl , String username , String password ,
82
98
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 );
84
100
}
85
101
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 ,
88
104
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 ) {
89
112
try (GenericContainer <?> container =
90
- createPgDumpInContainer (jdbcUrl , username , password , format , schemas , options )) {
113
+ createPgDumpInContainer (jdbcUrl , username , password , format , schemas , excludeTableDataPatterns , options )) {
91
114
container .start ();
92
115
93
116
container .copyFileFromContainer (CONTAINER_DUMP_FILE , inputStreamProcessor );
@@ -96,9 +119,10 @@ public static void dump(String jdbcUrl, String username, String password, Postgr
96
119
97
120
private static GenericContainer <?> createPgDumpInContainer (String jdbcUrl , String username , String password ,
98
121
PostgresDumpFormat format , List <Schema > schemas ,
122
+ List <String > excludeTableDataPatterns ,
99
123
PostgresDumpOption ... options ) {
100
124
ConnectionInformation connectionInformation = PostgresUtils .parseConnectionInformation (jdbcUrl , username , password );
101
- String [] command = createPgDumpCommand (connectionInformation , format , schemas , options );
125
+ String [] command = createPgDumpCommand (connectionInformation , format , schemas , excludeTableDataPatterns , options );
102
126
103
127
log .debug ("Executing {}" , String .join (" " , command ));
104
128
@@ -113,7 +137,8 @@ private static GenericContainer<?> createPgDumpInContainer(String jdbcUrl, Strin
113
137
}
114
138
115
139
private static String [] createPgDumpCommand (ConnectionInformation connectionInformation , PostgresDumpFormat format ,
116
- List <Schema > schemas , PostgresDumpOption ... options ) {
140
+ List <Schema > schemas , List <String > excludeTableDataPatterns ,
141
+ PostgresDumpOption ... options ) {
117
142
List <String > commandArgs = new ArrayList <>(List .of (
118
143
"pg_dump" ,
119
144
"--host=" + connectionInformation .host (),
@@ -131,6 +156,10 @@ private static String[] createPgDumpCommand(ConnectionInformation connectionInfo
131
156
commandArgs .addAll (schema .getCommandArguments ());
132
157
}
133
158
159
+ for (String excludeTableDataPattern : excludeTableDataPatterns ) {
160
+ commandArgs .add ("--exclude-table-data=" + excludeTableDataPattern );
161
+ }
162
+
134
163
for (PostgresDumpOption option : options ) {
135
164
commandArgs .add (option .getCommandArgument ());
136
165
}
0 commit comments