浏览代码

Fix error message when there are no MySQL databases to dump for "all" databases (#319).

Dan Helfman 5 年之前
父节点
当前提交
65472c8de2
共有 3 个文件被更改,包括 18 次插入2 次删除
  1. 1 0
      NEWS
  2. 4 2
      borgmatic/hooks/mysql.py
  3. 13 0
      tests/unit/hooks/test_mysql.py

+ 1 - 0
NEWS

@@ -3,6 +3,7 @@
    formats, the "directory" dump format does not stream directly to/from Borg.
  * #316: Fix hang when streaming a database dump to Borg with implicit duplicate source directories
    by deduplicating them first.
+ * #319: Fix error message when there are no MySQL databases to dump for "all" databases.
  * Improve documentation around the installation process. Specifically, making borgmatic commands
    runnable via the system PATH and offering a global install option.
 

+ 4 - 2
borgmatic/hooks/mysql.py

@@ -73,9 +73,11 @@ def dump_databases(databases, log_prefix, location_config, dry_run):
             make_dump_path(location_config), requested_name, database.get('hostname')
         )
         extra_environment = {'MYSQL_PWD': database['password']} if 'password' in database else None
-        dump_command_names = database_names_to_dump(
+        dump_database_names = database_names_to_dump(
             database, extra_environment, log_prefix, dry_run_label
         )
+        if not dump_database_names:
+            raise ValueError('Cannot find any MySQL databases to dump.')
 
         dump_command = (
             ('mysqldump',)
@@ -86,7 +88,7 @@ def dump_databases(databases, log_prefix, location_config, dry_run):
             + (('--user', database['username']) if 'username' in database else ())
             + (tuple(database['options'].split(' ')) if 'options' in database else ())
             + ('--databases',)
-            + dump_command_names
+            + dump_database_names
             # Use shell redirection rather than execute_command(output_file=open(...)) to prevent
             # the open() call on a named pipe from hanging the main borgmatic process.
             + ('>', dump_filename)

+ 13 - 0
tests/unit/hooks/test_mysql.py

@@ -198,6 +198,19 @@ def test_dump_databases_runs_mysqldump_for_all_databases():
     assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process]
 
 
+def test_dump_databases_errors_for_missing_all_databases():
+    databases = [{'name': 'all'}]
+    process = flexmock()
+    flexmock(module).should_receive('make_dump_path').and_return('')
+    flexmock(module.dump).should_receive('make_database_dump_filename').and_return(
+        'databases/localhost/all'
+    )
+    flexmock(module).should_receive('database_names_to_dump').and_return(())
+
+    with pytest.raises(ValueError):
+        assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process]
+
+
 def test_restore_database_dump_runs_mysql_to_restore():
     database_config = [{'name': 'foo'}]
     extract_process = flexmock(stdout=flexmock())