0000002d
 ÷    ‹      ½”o¯Ò0‡ßßOQûÂwÛaÀUso7se$¹@¸cŒYJW¶†Ñ.íÁ�ŸÞÂ0—ˆš_íOŸõüž³¶ìE:,>Ï†äýâqLfß�GB€O½@ºHÛ�~Ø‰ †Jh‰Xß4M6½ÐØs(qSõÁ¡UÃsšÜ°Ã»ä†°RòÜ_	C…•LF:—;bVÌ�Êejk`i=8Y­ÀƒP©%Ô{,�îA®5k^H¹[T•ƒÆ*”ÖÁN¢ÜA–Õ{ÁE)³ŒA[Ì—‡S}¶4ùþ+ú_|¥£6_“nmÂ°$ßx¥
S45M˜ÚÄYSPÂhËŠëuX¨%¼Â˜~¦_=çã¾N'>ç*¦oñä~§4™ð�dÀ/3�žy É˜;$“«•’ùUø©…ŸÔ÷ë¦-“J'¬ªQýŒ‚W<W¦r5÷®·Þ ´çT‹ä¿ë†ïøy3fóád‘ŽæmKòÃÏéþù¥ÉŒ[©‘¤ÊJ�ÆîO®má—zéêûŸ�ädbUQ"M	ÈEò/ô·z­M£Ï;à»{Ñ=Ë”V˜e¡hƒ^…~9ÒäÚÈ¹Ê/Ù»�n?ˆ¢ ûŠt£»ÎkB®€·á›×%ÿp%Ài�08nRíÙñÎŸœÿž    B   	ˆl–Ðz¾”ÂXÔÊ‚fã"¸ÓªbÑ¿�þY Y¹[ÂÓò‘²ùÆ„„û?Å_ŠI|¥�+Wé3ž¯ÅÄ 0    	import copy
import logging
import os

import borgmatic.borg.extract
import borgmatic.borg.list
import borgmatic.borg.mount
import borgmatic.borg.rlist
import borgmatic.borg.state
import borgmatic.config.validate
import borgmatic.hooks.dispatch
import borgmatic.hooks.dump

logger = logging.getLogger(__name__)


UNSPECIFIED_HOOK = object()


def get_configured_database(
    hooks, archive_database_names, hook_name, database_name, configuration_database_name=None
):
    '''
    Find the first database with the given hook name and database name in the configured hooks
    dict and the given archive database names dict (from hook name to database names contained in
    a particular backup archive). If UNSPECIFIED_HOOK is given as the hook name, search all database
    hooks for the named database. If a configuration database name is given, use that instead of the
    database name to lookup the database in the given hooks configuration.

    Return the found database as a tuple of (found hook name, database configuration dict).
    '''
    if not configuration_database_name:
        configuration_database_name = database_name

    if hook_name == UNSPECIFIED_HOOK:
        hooks_to_search = hooks
    else:
        hooks_to_search = {hook_name: hooks[hook_name]}

    return next(
        (
            (name, hook_database)
            for (name, hook) in hooks_to_search.items()
            for hook_database in hook
            if hook_database['name'] == configuration_database_name
            and database_name in archive_database_names.get(name, [])
        ),
        (None, None),
    )


def get_configured_hook_name_and_database(hooks, database_name):
    '''
    Find the hook name and first database dict with the given database name in the configured hooks
    dict. This searches across all database hooks.
    '''


def restore_single_database(
    repository,
    location,
    storage,
    hooks,
    local_borg_version,
    global_arguments,
    local_path,
    remote_path,
    archive_name,
    hook_name,
    database,
):  # pragma: no cover
    '''
    Given (among other things) an archive name, a database hook name, and a configured database
    configuration dict, restore that database from the archive.
    '''
    logger.info(f'{repository}: Restoring database {database["name"]}')

    dump_pattern = borgmatic.hooks.dispatch.call_hooks(
        'make_database_dump_pattern',
        hooks,
        repository,
        borgmatic.hooks.dump.DATABASE_HOOK_NAMES,
        location,
        database['name'],
    )[hook_name]

    # Kick off a single database extract to stdout.
    extract_process = borgmatic.borg.extract.extract_archive(
        dry_run=global_arguments.dry_run,
        repository=repository,
        archive=archive_name,
        paths=borgmatic.hooks.dump.convert_glob_patterns_to_borg_patterns([dump_pattern]),
        location_config=location,
        storage_config=storage,
        local_borg_version=local_borg_version,
        local_path=local_path,
        remote_path=remote_path,
        destination_path='/',
        # A directory format dump isn't a single file, and therefore can't extract
        # to stdout. In this case, the extract_process return value is None.
        extract_to_stdout=bool(database.get('format') != 'directory'),
    )

    # Run a single database restore, consuming the extract stdout (if any).
    borgmatic.hooks.dispatch.call_hooks(
        'restore_database_dump',
        {hook_name: [