Skip to content

Commit 7625828

Browse files
committed
#944 Add support for skip/include data in backup manager
1 parent d8491d4 commit 7625828

5 files changed

Lines changed: 470 additions & 11 deletions

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,24 @@ This non-standard behaviour may change before Jaybird 7.0.0 release, or in a lat
649649
// TODO Revise above, depending on https://github.com/FirebirdSQL/jaybird/issues/343 or maybe https://github.com/FirebirdSQL/jaybird/issues/833
650650
====
651651
652+
[#backup-skip-include-data]
653+
=== Support for including and excluding table data in `BackupManager`
654+
655+
The backup manager API was extended with support for including and excluding table data for backup or restore.
656+
657+
Four properties were added to `org.firebirdsql.management.BackupManager` and its implementations:
658+
659+
[horizontal.compact]
660+
`skipData`::
661+
SQL regular expression for table names to skip
662+
`skipSchemaData`::
663+
(Firebird 6+) SQL regular expression for schema names to skip
664+
`includeData`::
665+
SQL regular expression for table names to include
666+
`includeSchemaData`::
667+
(Firebird 6+) SQL regular expression for schema names to include
668+
669+
For more information, refer to https://firebirdsql.org/file/documentation/html/en/firebirddocs/gbak/firebird-gbak.html[Firebird's gbak Backup and Restore Utility].
652670
653671
// TODO add major changes
654672

src/main/org/firebirdsql/gds/ISCConstants.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
SPDX-FileCopyrightText: 2000-2025 Firebird development team and individual contributors
2+
SPDX-FileCopyrightText: Copyright 2000-2026 Firebird development team and individual contributors
33
SPDX-FileCopyrightText: Copyright 2001 Boix i Oltra, S.L.
44
SPDX-FileContributor: Alejandro Alberola (Boix i Oltra, S.L.)
55
SPDX-FileCopyrightText: Copyright 2001-2002 David Jencks
@@ -9,7 +9,7 @@
99
SPDX-FileCopyrightText: Copyright 2003 Ryan Baldwin
1010
SPDX-FileCopyrightText: Copyright 2005 Gabriel Reid
1111
SPDX-FileCopyrightText: Copyright 2009 Thomas Steinmaurer
12-
SPDX-FileCopyrightText: Copyright 2012-2025 Mark Rotteveel
12+
SPDX-FileCopyrightText: Copyright 2012-2026 Mark Rotteveel
1313
SPDX-FileCopyrightText: Copyright 2015 Hajime Nakagami
1414
SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
1515
SPDX-FileComment: The constants listed here were obtained from the Firebird sources, which are licensed under the IPL (InterBase Public License) and/or IDPL (Initial Developer Public License), both are variants of the Mozilla Public License version 1.1
@@ -178,6 +178,8 @@ public interface ISCConstants {
178178
int isc_spb_bkp_crypt = 18;
179179
int isc_spb_bkp_include_data = 19;
180180
int isc_spb_bkp_parallel_workers = 21;
181+
int isc_spb_bkp_skip_schema_data = 22;
182+
int isc_spb_bkp_include_schema_data = 23;
181183
int isc_spb_bkp_ignore_checksums = 0x01;
182184
int isc_spb_bkp_ignore_limbo = 0x02;
183185
int isc_spb_bkp_metadata_only = 0x04;
@@ -288,6 +290,8 @@ public interface ISCConstants {
288290
int isc_spb_res_access_mode = 12;
289291
int isc_spb_res_fix_fss_data = 13;
290292
int isc_spb_res_fix_fss_metadata = 14;
293+
int isc_spb_res_skip_schema_data = isc_spb_bkp_skip_schema_data;
294+
int isc_spb_res_include_schema_data = isc_spb_bkp_include_schema_data;
291295
int isc_spb_res_keyholder = isc_spb_bkp_keyholder;
292296
int isc_spb_res_keyname = isc_spb_bkp_keyname;
293297
int isc_spb_res_crypt = isc_spb_bkp_crypt;

src/main/org/firebirdsql/management/BackupManager.java

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.firebirdsql.management;
99

1010
import org.firebirdsql.gds.ISCConstants;
11+
import org.jspecify.annotations.Nullable;
1112

1213
import java.sql.SQLException;
1314

@@ -242,6 +243,124 @@ public interface BackupManager extends ServiceManager {
242243
*/
243244
void setRestoreReadOnly(boolean readOnly);
244245

246+
/**
247+
* SQL regular expression for the tables to exclude from the backup or restore.
248+
* <p>
249+
* Metadata of excluded tables is included, but their data is not included in the backup, or not written on restore.
250+
* </p>
251+
* <p>
252+
* See also <a href="https://firebirdsql.org/file/documentation/html/en/firebirddocs/gbak/firebird-gbak.html#gbak-cmdline-skip-data">-SKIP_D[ATA]</a>
253+
* in <em>Firebird's gbak Backup and Restore Utility</em>, and <a href="https://firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref50/fblangref50-commons-predicates.html#fblangref50-commons-syntaxregex">Syntax: SQL Regular Expressions</a>
254+
* in the <em>Firebird 5.0 Language Reference</em>.
255+
* </p>
256+
*
257+
* @param sqlRegex
258+
* SQL regular expression for tables to exclude, {@code null} to clear
259+
* @see #getSkipData()
260+
* @see #setSkipSchemaData(String)
261+
* @see #setIncludeData(String)
262+
* @see #setIncludeSchemaData(String)
263+
* @since 7
264+
*/
265+
void setSkipData(@Nullable String sqlRegex);
266+
267+
/**
268+
* @return SQL regular expression for tables to exclude, {@code null} for no filtering
269+
* @see #setSkipData(String)
270+
* @since 7
271+
*/
272+
@Nullable String getSkipData();
273+
274+
/**
275+
* SQL regular expression for the schemas to exclude from the backup or restore.
276+
* <p>
277+
* Metadata of excluded schemas and tables is included, but their data is not included in the backup, or not written
278+
* on restore.
279+
* </p>
280+
* <p>
281+
* Ignored on Firebird 5.0 and older.
282+
* </p>
283+
* <p>
284+
* See also <a href="https://firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref50/fblangref50-commons-predicates.html#fblangref50-commons-syntaxregex">Syntax: SQL Regular Expressions</a>
285+
* in the <em>Firebird 5.0 Language Reference</em>.
286+
* </p>
287+
*
288+
* @param sqlRegex
289+
* SQL regular expression for schemas to exclude, {@code null} to clear
290+
* @see #getSkipSchemaData()
291+
* @see #setSkipData(String)
292+
* @see #setIncludeData(String)
293+
* @see #setIncludeSchemaData(String)
294+
* @since 7
295+
*/
296+
void setSkipSchemaData(@Nullable String sqlRegex);
297+
298+
/**
299+
* @return SQL regular expression for schemas to exclude, {@code null} for no filtering
300+
* @see #setSkipSchemaData(String)
301+
* @since 7
302+
*/
303+
@Nullable String getSkipSchemaData();
304+
305+
/**
306+
* SQL regular expression for the tables to include in the backup or restore.
307+
* <p>
308+
* Metadata of excluded tables is included, but their data is not included in the backup, or not written on restore.
309+
* </p>
310+
* <p>
311+
* See also <a href="https://firebirdsql.org/file/documentation/html/en/firebirddocs/gbak/firebird-gbak.html#gbak-cmdline-include-data">-INCLUDE[_DATA]</a>
312+
* in <em>Firebird's gbak Backup and Restore Utility</em>, and <a href="https://firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref50/fblangref50-commons-predicates.html#fblangref50-commons-syntaxregex">Syntax: SQL Regular Expressions</a>
313+
* in the <em>Firebird 5.0 Language Reference</em>.
314+
* </p>
315+
*
316+
* @param sqlRegex
317+
* SQL regular expression for tables to include, {@code null} to clear
318+
* @see #getIncludeData()
319+
* @see #setSkipData(String)
320+
* @see #setSkipSchemaData(String)
321+
* @see #setIncludeSchemaData(String)
322+
* @since 7
323+
*/
324+
void setIncludeData(@Nullable String sqlRegex);
325+
326+
/**
327+
* @return SQL regular expression for tables to include, {@code null} for no filtering
328+
* @see #setIncludeData(String)
329+
* @since 7
330+
*/
331+
@Nullable String getIncludeData();
332+
333+
/**
334+
* SQL regular expression for the schemas to include in the backup or restore.
335+
* <p>
336+
* Metadata of excluded schemas and tables is included, but their data is not included in the backup, or not written
337+
* on restore.
338+
* </p>
339+
* <p>
340+
* Ignored on Firebird 5.0 and older.
341+
* </p>
342+
* <p>
343+
* See also <a href="https://firebirdsql.org/file/documentation/chunk/en/refdocs/fblangref50/fblangref50-commons-predicates.html#fblangref50-commons-syntaxregex">Syntax: SQL Regular Expressions</a>
344+
* in the <em>Firebird 5.0 Language Reference</em>.
345+
* </p>
346+
*
347+
* @param sqlRegex
348+
* SQL regular expression for schemas to include, {@code null} to clear
349+
* @see #getIncludeSchemaData()
350+
* @see #setSkipData(String)
351+
* @see #setSkipSchemaData(String)
352+
* @see #setIncludeData(String)
353+
* @since 7
354+
*/
355+
void setIncludeSchemaData(@Nullable String sqlRegex);
356+
357+
/**
358+
* @return SQL regular expression for schemas to include, {@code null} for no filtering
359+
* @see #setIncludeSchemaData(String)
360+
* @since 7
361+
*/
362+
@Nullable String getIncludeSchemaData();
363+
245364
/**
246365
* Perform the restore operation.
247366
*
@@ -259,4 +378,5 @@ public interface BackupManager extends ServiceManager {
259378
* if a database error occurs during the restore
260379
*/
261380
void restoreDatabase(int options) throws SQLException;
381+
262382
}

src/main/org/firebirdsql/management/FBBackupManagerBase.java

Lines changed: 141 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ public String toString() {
8383
private int restorePageSize = -1;
8484
private boolean restoreReadOnly;
8585
private boolean restoreReplace;
86+
private @Nullable String skipData;
87+
private @Nullable String skipSchemaData;
88+
private @Nullable String includeData;
89+
private @Nullable String includeSchemaData;
8690

8791
private static final int RESTORE_REPLACE = isc_spb_res_replace;
8892
private static final int RESTORE_CREATE = isc_spb_res_create;
@@ -169,15 +173,36 @@ protected ServiceRequestBuffer getBackupSRB(FbService service, int options) thro
169173
backupSPB.addArgument(SpbItems.isc_spb_verbose);
170174
}
171175

172-
if (getParallelWorkers() > 0 && supportInfoFor(service).supportsParallelWorkers()) {
173-
backupSPB.addArgument(isc_spb_bkp_parallel_workers, getParallelWorkers());
174-
}
176+
setCommonServiceRequestOptions(CommonOptions.BACKUP, service, backupSPB);
175177

176178
backupSPB.addArgument(SpbItems.isc_spb_options, options);
177179

178180
return backupSPB;
179181
}
180182

183+
private void setCommonServiceRequestOptions(CommonOptions commonOptions, FbService service,
184+
ServiceRequestBuffer srb) {
185+
if (getParallelWorkers() > 0 && supportInfoFor(service).supportsParallelWorkers()) {
186+
srb.addArgument(commonOptions.parallelWorkers(), getParallelWorkers());
187+
}
188+
189+
if (getSkipData() != null) {
190+
srb.addArgument(commonOptions.skipData(), getSkipData());
191+
}
192+
193+
if (getSkipSchemaData() != null && supportInfoFor(service).supportsSchemas()) {
194+
srb.addArgument(commonOptions.skipSchemaData(), getSkipSchemaData());
195+
}
196+
197+
if (getIncludeData() != null) {
198+
srb.addArgument(commonOptions.includeData(), getIncludeData());
199+
}
200+
201+
if (getIncludeSchemaData() != null && supportInfoFor(service).supportsSchemas()) {
202+
srb.addArgument(commonOptions.includeSchemaData(), getIncludeSchemaData());
203+
}
204+
}
205+
181206
@Override
182207
public void restoreDatabase() throws SQLException {
183208
restoreDatabase(0);
@@ -248,6 +273,46 @@ public void setRestoreReadOnly(boolean readOnly) {
248273
this.restoreReadOnly = readOnly;
249274
}
250275

276+
@Override
277+
public void setSkipData(@Nullable String skipData) {
278+
this.skipData = skipData;
279+
}
280+
281+
@Override
282+
public @Nullable String getSkipData() {
283+
return skipData;
284+
}
285+
286+
@Override
287+
public void setSkipSchemaData(@Nullable String skipSchemaData) {
288+
this.skipSchemaData = skipSchemaData;
289+
}
290+
291+
@Override
292+
public @Nullable String getSkipSchemaData() {
293+
return skipSchemaData;
294+
}
295+
296+
@Override
297+
public void setIncludeData(@Nullable String includeData) {
298+
this.includeData = includeData;
299+
}
300+
301+
@Override
302+
public @Nullable String getIncludeData() {
303+
return includeData;
304+
}
305+
306+
@Override
307+
public void setIncludeSchemaData(@Nullable String includeSchemaData) {
308+
this.includeSchemaData = includeSchemaData;
309+
}
310+
311+
@Override
312+
public @Nullable String getIncludeSchemaData() {
313+
return includeSchemaData;
314+
}
315+
251316
/**
252317
* Creates and returns the "restore" service request buffer for the Service Manager.
253318
*
@@ -294,9 +359,7 @@ protected ServiceRequestBuffer getRestoreSRB(FbService service, int options) thr
294359
restoreSPB.addArgument(SpbItems.isc_spb_verbose);
295360
}
296361

297-
if (getParallelWorkers() > 0 && supportInfoFor(service).supportsParallelWorkers()) {
298-
restoreSPB.addArgument(isc_spb_res_parallel_workers, getParallelWorkers());
299-
}
362+
setCommonServiceRequestOptions(CommonOptions.RESTORE, service, restoreSPB);
300363

301364
if ((options & RESTORE_CREATE) != RESTORE_CREATE
302365
&& (options & RESTORE_REPLACE) != RESTORE_REPLACE) {
@@ -329,4 +392,76 @@ protected abstract void addBackupsToBackupRequestBuffer(FbService service, Servi
329392
*/
330393
protected abstract boolean verboseBackup();
331394

395+
/**
396+
* Options shared between backup and restore
397+
*/
398+
private enum CommonOptions {
399+
400+
// We could do without this enum. as these options have the same value for both isc_spb_bkp_* and isc_spb_res_*.
401+
// However, we consider this cleaner.
402+
403+
BACKUP {
404+
@Override
405+
int parallelWorkers() {
406+
return isc_spb_bkp_parallel_workers;
407+
}
408+
409+
@Override
410+
int skipData() {
411+
return isc_spb_bkp_skip_data;
412+
}
413+
414+
@Override
415+
int skipSchemaData() {
416+
return isc_spb_bkp_skip_schema_data;
417+
}
418+
419+
@Override
420+
int includeData() {
421+
return isc_spb_bkp_include_data;
422+
}
423+
424+
@Override
425+
int includeSchemaData() {
426+
return isc_spb_bkp_include_schema_data;
427+
}
428+
},
429+
RESTORE {
430+
@Override
431+
int parallelWorkers() {
432+
return isc_spb_res_parallel_workers;
433+
}
434+
435+
@Override
436+
int skipData() {
437+
return isc_spb_res_skip_data;
438+
}
439+
440+
@Override
441+
int skipSchemaData() {
442+
return isc_spb_res_skip_schema_data;
443+
}
444+
445+
@Override
446+
int includeData() {
447+
return isc_spb_res_include_data;
448+
}
449+
450+
@Override
451+
int includeSchemaData() {
452+
return isc_spb_res_include_schema_data;
453+
}
454+
};
455+
456+
abstract int parallelWorkers();
457+
458+
abstract int skipData();
459+
460+
abstract int skipSchemaData();
461+
462+
abstract int includeData();
463+
464+
abstract int includeSchemaData();
465+
466+
}
332467
}

0 commit comments

Comments
 (0)