浏览代码

For the MariaDB and MySQL database hooks, creates a consistent snapshot by dumping all tables in a single transaction (#1193).

Dan Helfman 2 天之前
父节点
当前提交
6ae9b973fc

+ 2 - 0
NEWS

@@ -10,6 +10,8 @@
    command-line flags for database commands.
    command-line flags for database commands.
  * #1193: For the MariaDB and MySQL database hooks, add a "socket_path" option for Unix socket
  * #1193: For the MariaDB and MySQL database hooks, add a "socket_path" option for Unix socket
    database connections.
    database connections.
+ * #1193: For the MariaDB and MySQL database hooks, creates a consistent snapshot by dumping all
+   tables in a single transaction.
  * #1194: Fix for an incorrect diff command shown when running the "generate config" action with a
  * #1194: Fix for an incorrect diff command shown when running the "generate config" action with a
    source configuration file. 
    source configuration file. 
  * #1195: Fix a regression in the ZFS, LVM, and Btrfs hooks in which snapshotted paths ignored
  * #1195: Fix a regression in the ZFS, LVM, and Btrfs hooks in which snapshotted paths ignored

+ 1 - 0
borgmatic/hooks/data_source/mariadb.py

@@ -227,6 +227,7 @@ def execute_dump_command(
         )
         )
         + extra_options
         + extra_options
         + (('--add-drop-database',) if database.get('add_drop_database', True) else ())
         + (('--add-drop-database',) if database.get('add_drop_database', True) else ())
+        + ('--single-transaction',)
         + (('--host', hostname) if hostname else ())
         + (('--host', hostname) if hostname else ())
         + (('--port', str(database['port'])) if 'port' in database else ())
         + (('--port', str(database['port'])) if 'port' in database else ())
         + (('--protocol', 'tcp') if hostname or 'port' in database else ())
         + (('--protocol', 'tcp') if hostname or 'port' in database else ())

+ 1 - 0
borgmatic/hooks/data_source/mysql.py

@@ -158,6 +158,7 @@ def execute_dump_command(
         )
         )
         + extra_options
         + extra_options
         + (('--add-drop-database',) if database.get('add_drop_database', True) else ())
         + (('--add-drop-database',) if database.get('add_drop_database', True) else ())
+        + ('--single-transaction',)
         + (('--host', hostname) if hostname else ())
         + (('--host', hostname) if hostname else ())
         + (('--port', str(database['port'])) if 'port' in database else ())
         + (('--port', str(database['port'])) if 'port' in database else ())
         + (('--protocol', 'tcp') if hostname or 'port' in database else ())
         + (('--protocol', 'tcp') if hostname or 'port' in database else ())

+ 6 - 1
docs/how-to/backup-your-databases.md

@@ -659,9 +659,14 @@ configuration. Here's an example with MariaDB:
 ```yaml
 ```yaml
 mariadb_databases:
 mariadb_databases:
     - name: posts
     - name: posts
-      options: "--single-transaction --quick"
+      options: "--single-transaction"
 ```
 ```
 
 
+<span class="minilink minilink-addedin">New in version 2.0.13</span> borgmatic
+passes `--single-transaction` to MariaDB/MySQL by default, and you no longer
+need to set that in `options:`.
+
+
 ### borgmatic hangs during backup
 ### borgmatic hangs during backup
 
 
 See Limitations above about `read_special`. You may need to exclude certain
 See Limitations above about `read_special`. You may need to exclude certain

+ 9 - 0
tests/unit/hooks/data_source/test_mariadb.py

@@ -837,6 +837,7 @@ def test_execute_dump_command_runs_mariadb_dump():
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -880,6 +881,7 @@ def test_execute_dump_command_with_environment_password_transport_skips_defaults
         (
         (
             'mariadb-dump',
             'mariadb-dump',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--user',
             '--user',
             'root',
             'root',
             '--databases',
             '--databases',
@@ -929,6 +931,7 @@ def test_execute_dump_command_runs_mariadb_dump_without_add_drop_database():
         (
         (
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -979,6 +982,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_hostname_and_port():
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--host',
             '--host',
             'database.example.org',
             'database.example.org',
             '--port',
             '--port',
@@ -1033,6 +1037,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_tls():
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--ssl',
             '--ssl',
             '--databases',
             '--databases',
             'foo',
             'foo',
@@ -1082,6 +1087,7 @@ def test_execute_dump_command_runs_mariadb_dump_without_tls():
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--skip-ssl',
             '--skip-ssl',
             '--databases',
             '--databases',
             'foo',
             'foo',
@@ -1131,6 +1137,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_username_and_password():
             'mariadb-dump',
             'mariadb-dump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -1180,6 +1187,7 @@ def test_execute_dump_command_runs_mariadb_dump_with_options():
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--stuff=such',
             '--stuff=such',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -1229,6 +1237,7 @@ def test_execute_dump_command_runs_non_default_mariadb_dump_with_options():
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--stuff=such',
             '--stuff=such',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',

+ 9 - 0
tests/unit/hooks/data_source/test_mysql.py

@@ -717,6 +717,7 @@ def test_execute_dump_command_runs_mysqldump():
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -764,6 +765,7 @@ def test_execute_dump_command_with_environment_password_transport_skips_defaults
         (
         (
             'mysqldump',
             'mysqldump',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--user',
             '--user',
             'root',
             'root',
             '--databases',
             '--databases',
@@ -813,6 +815,7 @@ def test_execute_dump_command_runs_mysqldump_without_add_drop_database():
         (
         (
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -863,6 +866,7 @@ def test_execute_dump_command_runs_mysqldump_with_hostname_and_port():
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--host',
             '--host',
             'database.example.org',
             'database.example.org',
             '--port',
             '--port',
@@ -917,6 +921,7 @@ def test_execute_dump_command_runs_mysqldump_with_tls():
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--ssl',
             '--ssl',
             '--databases',
             '--databases',
             'foo',
             'foo',
@@ -966,6 +971,7 @@ def test_execute_dump_command_runs_mysqldump_without_tls():
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--skip-ssl',
             '--skip-ssl',
             '--databases',
             '--databases',
             'foo',
             'foo',
@@ -1015,6 +1021,7 @@ def test_execute_dump_command_runs_mysqldump_with_username_and_password():
             'mysqldump',
             'mysqldump',
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -1064,6 +1071,7 @@ def test_execute_dump_command_runs_mysqldump_with_options():
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--stuff=such',
             '--stuff=such',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',
@@ -1112,6 +1120,7 @@ def test_execute_dump_command_runs_non_default_mysqldump():
             'custom_mysqldump',  # Custom MySQL dump command
             'custom_mysqldump',  # Custom MySQL dump command
             '--defaults-extra-file=/dev/fd/99',
             '--defaults-extra-file=/dev/fd/99',
             '--add-drop-database',
             '--add-drop-database',
+            '--single-transaction',
             '--databases',
             '--databases',
             'foo',
             'foo',
             '--result-file',
             '--result-file',