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

This commit is contained in:
Dan Helfman 2020-05-26 08:59:04 -07:00
parent 602ad9e7ee
commit 65472c8de2
3 changed files with 18 additions and 2 deletions

1
NEWS
View file

@ -3,6 +3,7 @@
formats, the "directory" dump format does not stream directly to/from Borg. 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 * #316: Fix hang when streaming a database dump to Borg with implicit duplicate source directories
by deduplicating them first. 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 * Improve documentation around the installation process. Specifically, making borgmatic commands
runnable via the system PATH and offering a global install option. runnable via the system PATH and offering a global install option.

View file

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

View file

@ -198,6 +198,19 @@ def test_dump_databases_runs_mysqldump_for_all_databases():
assert module.dump_databases(databases, 'test.yaml', {}, dry_run=False) == [process] 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(): def test_restore_database_dump_runs_mysql_to_restore():
database_config = [{'name': 'foo'}] database_config = [{'name': 'foo'}]
extract_process = flexmock(stdout=flexmock()) extract_process = flexmock(stdout=flexmock())