Skip to content

Commit a79fd32

Browse files
committed
PXB-3662 [DOCS] - Clarify --tables and --databases conflict in docs
8.0 modified: docs/create-individual-partition-backup.md modified: docs/create-partial-backup.md modified: docs/xtrabackup-option-reference.md
1 parent 17ce1b9 commit a79fd32

3 files changed

Lines changed: 136 additions & 58 deletions

File tree

docs/create-individual-partition-backup.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ tables.
1111
There are three ways of specifying which part of the whole data will be backed
1212
up: regular expressions (`--tables`), enumerating the
1313
tables in a file (`--tables-file`) or providing a list of
14-
databases (`--databases`).
14+
databases or specific tables (`--databases`).
1515

16-
!!! note "Mutual exclusion"
16+
!!! warning "Do not use `--tables` and `--databases` together"
1717

18-
The `--tables` and `--databases` options are mutually exclusive. If you use both options in the same command, XtraBackup ignores `--databases` and only uses `--tables`. Use only one of these options per backup operation.
18+
Do not use both `--tables` and `--databases` in the same command. The resulting backup may not contain the data you intended to back up and risks data loss on restore. Use only one of these options per backup operation. See [Create a partial backup](create-partial-backup.md#filtering-behavior-with-examples) for details and alternatives such as `--tables-file` with `--databases`.
1919

2020
The regular expression provided to this option will be matched against the fully
2121
qualified database name and table name, in the form of

docs/create-partial-backup.md

Lines changed: 114 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,177 @@
11
# Create a partial backup
22

33
*xtrabackup* supports taking partial backups when the
4-
`innodb_file_per_table` option is enabled. There are three ways to create
4+
`innodb_file_per_table` option is enabled. There are multiple ways to create
55
partial backups:
66

7-
1. matching the tables names with a regular expression
7+
* matching the tables names with a regular expression
88

9-
2. providing a list of table names in a file
9+
* providing a list of table names in a file
1010

11-
3. providing a list of databases
11+
* providing a list of databases
1212

1313
!!! warning
1414

15-
Do not copy back the prepared backup.
15+
* Restore: Do not copy back the prepared backup. Restore partial backups by importing the tables (see [Restore a partial backup](restore-partial-backup.md) and [Restore single tables](restore-individual-tables.md) for the procedure), not by using the –copy-back option. Copying back the files is possible in some scenarios but can lead to database inconsistencies and is not recommended.
1616

17-
Restoring partial backups should be done by importing the tables,
18-
not by using the –copy-back option. It is not
19-
recommended to run incremental backups after running a partial
20-
backup.
17+
* Incremental backups: Do not run incremental backups after a partial backup.
2118

22-
Although there are some scenarios where restoring can be done by
23-
copying back the files, this may lead to database
24-
inconsistencies in many cases and it is not a recommended way to
25-
do it.
26-
27-
For the purposes of this manual page, we will assume that there is a database
19+
For the purposes of this manual page, we assume that there is a database
2820
named `test` which contains tables named `t1` and `t2`.
2921

3022
!!! warning
3123

3224
If any of the matched or listed tables is deleted during the backup,
33-
*xtrabackup* will fail.
25+
*xtrabackup* fails.
3426

35-
There are multiple ways of specifying which part of the whole data is backed up:
27+
There are multiple ways to specify which part of the whole data to back up:
3628

3729
* Use the `--tables` option to list the table names
3830

3931
* Use the `--tables-file` option to list the tables in a file
4032

41-
* Use the `--databases` option to list the databases
33+
* Use the `--databases` option to list the databases or specific tables
34+
35+
* Use the `--databases-file` option to list the databases or specific tables in a file
36+
37+
!!! warning "Do not use `--tables` and `--databases` together"
4238

43-
* Use the `--databases-file` option to list the databases
39+
Do not use both `--tables` and `--databases` in the same command. The resulting backup does not reliably contain the data you intended to back up. When you restore, you risk data loss or discover that critical tables were never included. A backup that does not match your intent risks data loss.
4440

45-
!!! note "Mutual exclusion"
41+
The two options use different filtering mechanisms and conflict when used together:
4642

47-
The `--tables` and `--databases` options are mutually exclusive. If you use both options in the same command, XtraBackup ignores `--databases` and only uses `--tables`. Use only one of these options per backup operation.
43+
* `--tables` uses regular expressions and implies a partial backup.
44+
* `--databases` uses exact matching and implies a full backup of the listed databases.
45+
46+
For example, a database listed in `--databases` is fully backed up even when you wanted only specific tables from that database via `--tables`; or tables you expected to be included are omitted. To combine specific tables from one database with full backups of other databases, use `--tables-file` with `--databases` instead of `--tables` (see [Filtering behavior with examples](#filtering-behavior-with-examples)).
4847

4948
## The `–-tables` option
5049

5150
The first method involves the xtrabackup `--tables` option. This option accepts either:
5251
* A comma-separated list of fully qualified table names in the format `database.table` (for example, `db1.t1,db1.t2,db2.t3`)
53-
* A POSIX regular expression surrounded by single quotes that is matched against the fully-qualified database name and table name using the `databasename.tablename` format
52+
* A POSIX regular expression surrounded by single quotes that XtraBackup matches against the fully-qualified database name and table name in `databasename.tablename` format
5453

5554
To back up only tables in the `test` database, use the following
5655
command:
5756

58-
```{.bash data-prompt="$"}
59-
$ xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \
60-
--tables="^test[.].*"
57+
```shell
58+
xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \
59+
--tables='^test[.].*'
6160
```
6261

6362
To back up only the `test.t1` table, use the following command:
6463

65-
```{.bash data-prompt="$"}
66-
$ xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \
67-
--tables="^test[.]t1"
64+
```shell
65+
xtrabackup --backup --datadir=/var/lib/mysql --target-dir=/data/backups/ \
66+
--tables='^test[.]t1'
6867
```
6968

7069
## The `-–tables-file` option
7170

7271
The `--tables-file` option specifies a file that can contain multiple table
73-
names, one table name per line in the file. Only the tables named in the file
74-
will be backed up. Names are matched exactly, case-sensitive, with no pattern or
75-
regular expression matching. The table names must be fully-qualified in
76-
`databasename.tablename` format.
77-
78-
```{.bash data-prompt="$"}
79-
$ echo "mydatabase.mytable" > /tmp/tables.txt
80-
$ xtrabackup --backup --tables-file=/tmp/tables.txt
72+
names, one table name per line in the file. XtraBackup backs up only the tables named in the file and matches names exactly, case-sensitive, with no pattern or
73+
regular expression matching. Use the `databasename.tablename` format and fully-qualified table names.
74+
75+
```shell
76+
echo "mydatabase.mytable" > /tmp/tables.txt
77+
xtrabackup --backup --tables-file=/tmp/tables.txt
8178
```
8279

8380
## The `--databases` and `-–databases-file` options
8481

8582
The `--databases` option accepts a comma-separated list of database names. To include all tables in a database, add `.*` after the database name (for example, `mydb.*`). Regular expressions are not supported.
8683

87-
In addition to your selected databases, make sure to specify the `mysql`, `sys`, and `performance_schema` databases. These databases are required when restoring the databases using xtrabackup `--copy-back`.
84+
In addition to your selected databases, make sure to specify the `mysql`, `sys`, and `performance_schema` databases. You need these databases when restoring with xtrabackup `--copy-back`.
8885

8986
!!! note
9087

91-
Tables processed during the –prepare step may also be added to the backup
92-
even if they are not explicitly listed by the parameter if they were created
93-
after the backup started.
88+
A backup runs over a period of time. If a table is created while the backup is running, XtraBackup may copy that table into the backup even though you did not list that table in `--databases` or `--databases-file`, but only if (1) the table’s database is already in the scope of your filter (so the new table falls under a database you included), and (2) the table exists when the backup processes that database.
9489

95-
```{.bash data-prompt="$"}
96-
$ xtrabackup --backup --databases='mysql,sys,performance_schema,test' --target-dir=/data/backups/
90+
```shell
91+
xtrabackup --backup --databases='mysql,sys,performance_schema,test' --target-dir=/data/backups/
9792
```
9893

94+
## Filtering behavior with examples
95+
96+
Do not use `--tables` and `--databases` in the same command. The backup may not contain the data you intended: XtraBackup applies `--databases` first as a high-level filter, and that filter can override your `--tables` regex. You can end up with a backup that omits tables you needed or includes tables you did not intend to back up, which risks data loss when you restore.
97+
98+
### How filtering works
99+
100+
To understand why using `--tables` and `--databases` in the same command fails, consider the order of checks. When determining whether to back up a table, XtraBackup runs a database check first, then a table check. Use the tabs below for each step.
101+
102+
=== "Database check (`--databases`)"
103+
104+
XtraBackup checks whether the database is included or excluded.
105+
106+
* If you use `--databases`, any database not in the list is skipped immediately.
107+
* If a database is in the `--databases` list, that database is marked so that all tables in that database are included (unless `--tables-file` is also used).
108+
109+
=== "Table check (`--tables` / `--tables-file`)"
110+
111+
If the database was not skipped in the database check:
112+
113+
* If the database was selected via `--databases` (and not via `--tables-file`), all tables in that database are copied and any `--tables` regex is ignored.
114+
* If the database was selected via `--tables-file` or was not in `--databases`, XtraBackup then checks the table name against the list or regex.
115+
116+
Example environment: Database `testdb` contains tables `table1`, `table2`, and `table3`. Goal: back up `testdb.table1`, `testdb.table2`, and all system databases (`mysql`, `performance_schema`, `sys`).
117+
118+
* Case 1: `xtrabackup --backup --tables="testdb.table1" --databases="mysql"`
119+
`testdb` is not in `--databases`, so the database is skipped. No tables from `testdb` are included.
120+
121+
* Case 2: `xtrabackup --backup --tables="testdb.table1" --databases="mysql,testdb"`
122+
`testdb` is in `--databases`. XtraBackup includes all tables in `testdb` (table1, table2, and table3), ignoring the `--tables` regex.
123+
124+
### Solution: combine specific tables and whole databases
125+
126+
To back up specific tables from one database (for example, `testdb.table1`, `testdb.table2`) and full backups of other databases (for example, `mysql`, `performance_schema`, `sys`), use `--tables-file` with `--databases`, or list the specific tables in `--databases` using the `database.table` format.
127+
128+
Method 1: Using `--tables-file` (recommended)
129+
130+
Create a file listing the specific tables, one per line:
131+
132+
```text
133+
testdb.table1
134+
testdb.table2
135+
```
136+
137+
Run XtraBackup with both `--tables-file` and `--databases`. Do not list the database of those specific tables in `--databases`; `--tables-file` supplies the table list for that database. List only the databases you want in full (for example, system databases):
138+
139+
```shell
140+
xtrabackup --backup --tables-file=tables.txt --databases="mysql,performance_schema,sys" --target-dir=/data/backups/
141+
```
142+
143+
In this configuration, `--tables-file` backs up only the listed tables from `testdb`, and `--databases` backs up the system databases in full.
144+
145+
!!! note "Avoid duplication"
146+
If you use `--tables-file` to back up specific tables from a database (for example, `testdb`), do not list that database in `--databases`. Listing that database would override the partial selection and back up the entire database.
147+
148+
Method 2: Using `--databases` for everything
149+
150+
You can list specific tables in `--databases` using the `database.table` format. This backs up the system databases in full and only the listed tables from `testdb`:
151+
152+
```shell
153+
xtrabackup --backup --databases="mysql,performance_schema,sys,testdb.table1,testdb.table2" --target-dir=/data/backups/
154+
```
155+
156+
For a full backup of a single database, add `.*` after the database name (for example, `mydb.*`). See the [databases](xtrabackup-option-reference.md#databases) option reference.
157+
158+
### Earlier example (sales and mysql)
159+
160+
You want only `sales.orders` and `sales.order_items`, and also the full `mysql` database. If you use both `--tables` and `--databases`:
161+
162+
```shell
163+
xtrabackup --backup --databases='mysql,sales' --tables='^sales\.(orders|order_items)$' --target-dir=/data/backups/
164+
```
165+
166+
the backup may contain only the two `sales` tables, or all tables in `sales` and `mysql`, or something in between. The result is implementation-dependent and cannot be trusted. Do not use this combination; use `--tables-file` with `--databases` instead.
167+
99168
## The `--databases-file` option
100169

101170
The –databases-file option specifies a file that can contain multiple
102-
databases and tables in the `databasename[.tablename]` format, one element name per line in the file. Names are matched exactly, case-sensitive, with no pattern or regular expression matching.
171+
databases and tables in the `databasename[.tablename]` format, one element name per line in the file. XtraBackup matches names exactly, case-sensitive, with no pattern or regular expression matching.
103172

104173
!!! note
105174

106-
Tables processed during the –prepare step may also be added to the backup
107-
even if they are not explicitly listed by the parameter if they were created
108-
after the backup started.
175+
A backup runs over a period of time. If a table is created while the backup is running, XtraBackup may copy that table into the backup even though you did not list that table in `--databases-file`, but only if (1) the table’s database is already in the scope of your filter (so the new table falls under a database you included), and (2) the table exists when the backup processes that database.
109176

110-
The next step is to [prepare](prepare-partial-backup.md) the backup in order to restore it.
177+
Next, [prepare](prepare-partial-backup.md) the backup in order to restore the backup.

docs/xtrabackup-option-reference.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ Write core on fatal signals.
186186
187187
Usage: `--databases=#`
188188
189-
This option specifies which databases to back up.
189+
This option specifies which databases or specific tables to back up.
190190
191-
!!! note "Mutual exclusion"
191+
!!! note "Interaction with `--tables`"
192192
193-
`--tables` and `--databases` are mutually exclusive. If you use both options in the same command, XtraBackup ignores `--databases` and only uses `--tables`. Use only one of these options per backup operation.
193+
Do not use both `--tables` and `--databases` in the same command. The resulting backup may not contain the data you intended to back up and risks data loss on restore. `--databases` acts as a high-level filter applied before table-level checks; the two options conflict. Use only one per backup, or use `--tables-file` together with `--databases` to combine specific tables with full databases (see [Create a partial backup](create-partial-backup.md#filtering-behavior-with-examples)).
194194
195195
Accepted syntax:
196196
@@ -1100,9 +1100,9 @@ Usage: `--tables=name`
11001100
11011101
This option filters tables to be backed up based on their fully qualified names.
11021102
1103-
!!! note "Mutual exclusion"
1103+
!!! note "Interaction with `--databases`"
11041104
1105-
`--tables` and `--databases` are mutually exclusive. Supplying both in the same command line causes XtraBackup to ignore one of them (currently `--databases`). Use only one of the options per backup operation.
1105+
Do not use both options in the same command. The backup may not contain the data you intended to back up and risks data loss on restore. `--databases` is applied first as a high-level filter and can override `--tables`. Use only one per backup, or use `--tables-file` with `--databases` to combine specific tables with full databases. See [Create a partial backup](create-partial-backup.md#filtering-behavior-with-examples).
11061106
11071107
Accepted syntax:
11081108
@@ -1139,9 +1139,20 @@ backup. Note that this option has a higher priority than
11391139
11401140
### Backing up selected tables together with whole system databases
11411141
1142-
When you need to back up specific tables from user databases along with entire system databases (such as `mysql`, `performance_schema`, or `sys`), you must use the `--tables` option with a regular expression. This is the only way to combine specific table selection with full-database inclusion, because `--tables` and `--databases` are mutually exclusive.
1142+
When you need to back up specific tables from user databases along with entire system databases (such as `mysql`, `performance_schema`, or `sys`), you can use either of the following approaches:
11431143
1144-
Example 1: Back up specific tables plus entire mysql database
1144+
* **`--tables-file` with `--databases` (recommended):** List the fully qualified table names in a file and pass it with `--tables-file`; list the databases (e.g. `mysql`, `sys`, `performance_schema`) with `--databases`. XtraBackup will include only the tables from the file from user databases and all tables from the listed system databases. This avoids the conflicting behavior of mixing `--tables` and `--databases`.
1145+
1146+
* **`--tables` with a regular expression:** Use a single `--tables` regex to match both the specific user tables and the system database prefixes (e.g. `mysql.`, `sys.`). Do not use `--databases` in the same command.
1147+
1148+
Example (tables-file + databases): Back up entire `mysql` plus only `mydb.t1` and `mydb.t2`:
1149+
1150+
```{.bash data-prompt="$"}
1151+
$ echo -e "mydb.t1\nmydb.t2" > /tmp/tables.txt
1152+
$ xtrabackup --backup --databases='mysql,mydb' --tables-file=/tmp/tables.txt --target-dir=/data/backup/
1153+
```
1154+
1155+
Example 1: Back up specific tables plus entire mysql database (regex only)
11451156
11461157
```{.bash data-prompt="$"}
11471158
$ xtrabackup --backup --tables='^(mydb\.(t1|t2)|mysql\.)' --target-dir=/data/backup/
@@ -1171,7 +1182,7 @@ The following table lists common mistakes when using `--tables` and `--databases
11711182
11721183
| Incorrect usage | What happens |
11731184
|---|---|
1174-
| Using both `--tables` and `--databases` together | XtraBackup ignores `--databases` and only processes `--tables`. Your backup may not include the databases you expected. |
1185+
| Using both `--tables` and `--databases` together | Do not do this. The backup may not contain the data you intended to back up and risks data loss on restore. Use one option per backup or use `--tables-file` with `--databases`. |
11751186
| Using `--databases` with regular expressions | Regular expressions are not supported by `--databases`. XtraBackup treats the regular expression as a literal database name. If that database name does not exist, the backup will be empty or fail. |
11761187
| Using `--tables` without quotes for regex patterns | Without quotes, the shell may interpret special regex characters. This causes incorrect pattern matching or syntax errors. |
11771188
| Using `--databases=mydb` expecting to include all tables | Without the `.*` wildcard, `--databases=mydb` may not include all tables. Use `--databases=mydb.*` to include all tables in the database. |

0 commit comments

Comments
 (0)