§
    ôc0  ã                   óÀ   — d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Zd dl
Zd dlZ ej        e¦  «        Z e¦   «         Z	 d	d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )
é    Nc                 ó    ‡‡‡— ‰s‰Š|t           k    r| }n
|| |         i}t          ˆˆˆfd„|                     ¦   «         D ¦   «         d¦  «        S )a8  
    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).
    c              3   óx   •K  — | ]4\  }}|D ],}|d          ‰k    r‰‰                      |g ¦  «        v ¯&||fV — Œ-Œ5dS )ÚnameN)Úget)Ú.0r   ÚhookÚhook_databaseÚarchive_database_namesÚconfiguration_database_nameÚdatabase_names       €€€ú;/usr/lib/python3/dist-packages/borgmatic/actions/restore.pyú	<genexpr>z*get_configured_database.<locals>.<genexpr>)   s}   øè è € ð 	
ð 	
á��tØ!%ð	
ð 	
ð Ø˜VÔ$Ð(CÒCÐCØÐ!7×!;Ò!;¸DÀ"Ñ!EÔ!EÐEÐEð	 �=Ð!ð FÐEÐEÐEÐEð	
ð 	
ó    )NN)ÚUNSPECIFIED_HOOKÚnextÚitems)Úhooksr
   Ú	hook_namer   r   Úhooks_to_searchs    ` `` r   Úget_configured_databaser      sŠ   øøø€ ð 'ð 4Ø&3Ð#àÕ$Ò$Ð$Øˆˆà$ e¨IÔ&6Ð7ˆåð	
ð 	
ð 	
ð 	
ð 	
ð 	
à /× 5Ò 5Ñ 7Ô 7ð	
ñ 	
ô 	
ð 	ñ	ô 	ð 	r   c                 ó   — dS )zœ
    Find the hook name and first database dict with the given database name in the configured hooks
    dict. This searches across all database hooks.
    N© )r   r   s     r   Ú%get_configured_hook_name_and_databaser   4   s   € € € r   c                 ód  — t                                | › d|
d         › �¦  «         t          j        j                             d|| t          j        j        j        ||
d         ¦  «        |	         }t          j        j	         
                    |j        | |t          j        j                             |g¦  «        |||||dt          |
                     d¦  «        dk    ¦  «        ¬¦  «        }t          j        j                             d|	|
gi| t          j        j        j        ||j        |¦  «         d	S )
z¥
    Given (among other things) an archive name, a database hook name, and a configured database
    configuration dict, restore that database from the archive.
    z: Restoring database r   Úmake_database_dump_patternú/ÚformatÚ	directory)Údry_runÚ
repositoryÚarchiveÚpathsÚlocation_configÚstorage_configÚlocal_borg_versionÚ
local_pathÚremote_pathÚdestination_pathÚextract_to_stdoutÚrestore_database_dumpN)ÚloggerÚinfoÚ	borgmaticr   ÚdispatchÚ
call_hooksÚdumpÚDATABASE_HOOK_NAMESÚborgÚextractÚextract_archiver   Ú&convert_glob_patterns_to_borg_patternsÚboolr   )r    ÚlocationÚstorager   r%   Úglobal_argumentsr&   r'   Úarchive_namer   ÚdatabaseÚdump_patternÚextract_processs                r   Úrestore_single_databaser>   ;   s1  € õ" ‡K‚K�:ÐFÐF°H¸VÔ4DÐFÐFÑGÔGÐGå”?Ô+×6Ò6Ø$ØØÝŒÔÔ0ØØ�Ôñô ð ô€Lõ  ”nÔ,×<Ò<Ø Ô(ØØÝŒoÔ"×IÒIÈ<È.ÑYÔYØ ØØ-ØØØõ ˜xŸ|š|¨HÑ5Ô5¸ÒDÑEÔEð =ñ ô €Oõ" „OÔ×'Ò'ØØ	�X�JÐØÝŒÔÔ0ØØÔ Øñô ð ð ð r   c           	      óR  — t           j                             |                     dt          j        j        j        ¦  «        ¦  «                             d¦  «        }t           j                             t          j	        j
                             |d¦  «        ¦  «        }t          j        j                             | ||||||¬¦  «        }	i }
|	D ]Ú}	 |                     |t           j        j        z   d¦  «        d                              t           j        j        ¦  «        dd…         \  }}}||
                     |g ¦  «        vr*|
                     |g ¦  «                             |g¦  «         Œ¢# t$          t&          f$ r% t(                               | › d|› d	|› �¦  «         Y Œ×w xY w|
S )
aP  
    Given a local or remote repository path, a resolved archive name, a location configuration dict,
    a storage configuration dict, the local Borg version, and local and remote Borg paths, query the
    archive for the names of databases it contains and return them as a dict from hook name to a
    sequence of database names.
    Úborgmatic_source_directoryr   z*_databases/*/*)Ú	list_pathr&   r'   é   r   é   z': Ignoring invalid database dump path "z" in archive )ÚosÚpathÚ
expanduserr   r-   r2   ÚstateÚ"DEFAULT_BORGMATIC_SOURCE_DIRECTORYÚlstripr   r0   Úmake_database_dump_pathÚlistÚcapture_archive_listingÚsplitÚsepÚ
setdefaultÚextendÚ
ValueErrorÚ
IndexErrorr+   Úwarning)r    r!   r7   r8   r%   r&   r'   r@   Úparent_dump_pathÚ
dump_pathsr
   Ú	dump_pathr   Ú_r   s                  r   Úcollect_archive_database_namesrX   t   sÇ  € õ "$¤×!3Ò!3Ø�ŠØ(­)¬.Ô*>Ô*añ	
ô 	
ñ"ô "÷ ‚fˆS�k„kð	 õ
 ”w×)Ò)ÝŒÔ×4Ò4Ð5OÐQbÑcÔcñô Ðõ ”Ô$×<Ò<ØØØØØ"ØØð =ñ ô €Jð  Ðàð Yð Yˆ	ð
	YØ,5¯OªOØ*­R¬W¬[Ñ8¸!ñ-ô -àô-ç’•r”w”{Ñ#Ô# A a Cô-)Ñ)ˆY˜˜=ð Ð$:×$>Ò$>¸yÈ"Ñ$MÔ$MÐMÐMØ&×1Ò1°)¸RÑ@Ô@×GÒGÈÈÑXÔXÐXøøõ �JÐ'ð 	ð 	ð 	Ý�NŠNØÐgÐgÀiÐgÐgÐ^eÐgÐgñô ð ð ð ð	øøøð "Ð!s   ÃAE.Å.3F$Æ#F$c                 óL  — | r	t           | in	t           dgi}d|t                    v r—|t                                         d¦  «         |                     ¦   «         D ]b\  }}|                     |g ¦  «                             |¦  «         |D ]1}||t                    v r |t                                         |¦  «         Œ2Œc|t                    s|                     t           ¦  «         t          d„ |                     ¦   «         D ¦   «         ¦  «        }t          d„ |                     ¦   «         D ¦   «         ¦  «        }t          t          |¦  «        |z
  ¦  «        }|rJd 	                    d„ |D ¦   «         ¦  «        }	t          dt          |¦  «        dk    rdnd	› d
|	› d�¦  «        ‚|S )ab  
    Given a sequence of requested database names to restore and a dict of hook name to the names of
    databases found in an archive, return an expanded sequence of database names to restore,
    replacing "all" with actual database names as appropriate.

    Raise ValueError if any of the requested database names cannot be found in the archive.
    Úallc              3   ó$   K  — | ]}|D ]}|V — ŒŒd S ©Nr   ©r   Údatabase_namesr   s      r   r   z,find_databases_to_restore.<locals>.<genexpr>Ã   sG   è è € ð !ð !ØÀnð!ð !Ø>Bˆð!ð !ð !ð !ð !ð !ð !r   c              3   ó$   K  — | ]}|D ]}|V — ŒŒd S r\   r   r]   s      r   r   z,find_databases_to_restore.<locals>.<genexpr>Æ   sG   è è € ð *ð *ØÈ~ð*ð *ØGKˆð*ð *ð *ð *ð *ð *ð *r   ú, c              3   ó"   K  — | ]
}d |› d �V — ŒdS ©ú"Nr   ©r   r   s     r   r   z,find_databases_to_restore.<locals>.<genexpr>Ì   ó*   è è € Ð GÐ G°  T   Ð GÐ GÐ GÐ GÐ GÐ Gr   úCannot restore databaserB   ÚsÚ ú z missing from archive)r   Úremover   rO   rP   ÚpopÚsetÚvaluesÚsortedÚjoinrQ   Úlen)
Úrequested_database_namesr
   Úrestore_namesr   r^   r   Úcombined_restore_namesÚcombined_archive_database_namesÚmissing_namesÚjoined_namess
             r   Úfind_databases_to_restorerw   £   s  € ð $ð	)Õ	Ð3Ð4Ð4å  Ð(ð ð �Õ.Ô/Ð/Ð/ØÕ&Ô'×.Ò.¨uÑ5Ô5Ð5à+A×+GÒ+GÑ+IÔ+Ið 	Jð 	JÑ'ˆY˜Ø×$Ò$ Y°Ñ3Ô3×:Ò:¸>ÑJÔJÐJð "0ð Jð J�Ø  MÕ2BÔ$CÐCÐCØ!Õ"2Ô3×:Ò:¸=ÑIÔIÐIøðJð Õ)Ô*ð ,Ø×ÒÕ*Ñ+Ô+Ð+å ð !ð !Ø#0×#7Ò#7Ñ#9Ô#9ð!ñ !ô !ñ ô Ðõ '*ð *ð *Ø#9×#@Ò#@Ñ#BÔ#Bð*ñ *ô *ñ 'ô 'Ð#õ �3Ð5Ñ6Ô6Ð9XÑXÑYÔY€MØð 
Ø—y’yÐ GÐ G¸Ð GÑ GÔ GÑGÔGˆÝØq­S°Ñ-?Ô-?À!Ò-CÐ-C c cÈÐqÐqÈlÐqÐqÐqñ
ô 
ð 	
ð Ðr   c                 óÐ  — t          d„ t          |                      ¦   «         ¦  «        t          |                     ¦   «         ¦  «        z   D ¦   «         ¦  «        }|s|st          d¦  «        ‚t	          t          |¦  «        t          |¦  «        z
  ¦  «        }|rJd                     d„ |D ¦   «         ¦  «        }t          dt          |¦  «        dk    rdnd› d	|› d
�¦  «        ‚dS )a,  
    Given a dict from hook name to database names to restore, a dict from hook name to remaining
    database names to restore, and a sequence of found (actually restored) database names, raise
    ValueError if requested databases to restore were missing from the archive and/or configuration.
    c              3   ó$   K  — | ]}|D ]}|V — ŒŒd S r\   r   r]   s      r   r   z)ensure_databases_found.<locals>.<genexpr>Ú   sM   è è € ð !ð !àà"ð	!ð !ð ð 	ð!ð !ð !ð !ð !ð !ð !r   z"No databases were found to restorer`   c              3   ó"   K  — | ]
}d |› d �V — ŒdS rb   r   rd   s     r   r   z)ensure_databases_found.<locals>.<genexpr>æ   re   r   rf   rB   rg   rh   ri   z' missing from borgmatic's configurationN)rl   Útuplerm   rQ   rn   ro   rp   )rr   Úremaining_restore_namesÚfound_namesrs   ru   rv   s         r   Úensure_databases_foundr~   Ô   s&  € õ !ð !ð !å# M×$8Ò$8Ñ$:Ô$:Ñ;Ô;Ý
Ð'×.Ò.Ñ0Ô0Ñ
1Ô
1ñ2ð!ñ !ô !ñ ô Ðð "ð ?¨+ð ?ÝÐ=Ñ>Ô>Ð>å�3Ð5Ñ6Ô6½¸[Ñ9IÔ9IÑIÑJÔJ€MØð 
Ø—y’yÐ GÐ G¸Ð GÑ GÔ GÑGÔGˆÝð D­S°Ñ-?Ô-?À!Ò-CÐ-C c cÈð  Dð  DÈlð  Dð  Dð  Dñ
ô 
ð 	
ð
ð 
r   c	                 óò  — |j         r,t          j        j                             | |j         ¦  «        sdS t
                               d                     | |j        ¦  «        ¦  «         t          j	        j
                             d|| t          j	        j        j        ||j        ¦  «         t          j        j                             | |j        ||||¦  «        }	t%          | |	|||||¦  «        }
t'          |j        |
¦  «        }t+          ¦   «         }i }|                     ¦   «         D ]}\  }}|D ]u}t/          ||
||¦  «        \  }}|s,|                     |p|g ¦  «                             |¦  «         ŒE|                     |¦  «         t7          | ||||||||	|p||¦  «         ŒvŒ~|                     ¦   «         D ]l\  }}|D ]d}t/          ||
||d¦  «        \  }}|sŒ|                     |¦  «         t9          j        |¦  «        }||d<   t7          | ||||||||	|p||¦  «         ŒeŒmt          j	        j
                             d|| t          j	        j        j        ||j        ¦  «         t;          |||¦  «         dS )zà
    Run the "restore" action for the given repository, but only if the repository matches the
    requested repository in restore arguments.

    Raise ValueError if a configured database could not be found to restore.
    Nz'{}: Restoring databases from archive {}Úremove_database_dumpsrZ   r   )r    r-   ÚconfigÚvalidateÚrepositories_matchr+   r,   r   r!   r   r.   Úcall_hooks_even_if_unconfiguredr0   r1   r   r2   ÚrlistÚresolve_archive_namerX   rw   Ú	databasesrl   r   r   rO   ÚappendÚaddr>   Úcopyr~   )r    r7   r8   r   r%   Úrestore_argumentsr9   r&   r'   r:   r
   rr   r}   r|   r   r^   r   Úfound_hook_nameÚfound_databaser;   s                       r   Úrun_restorerŽ   ì   s  € ð" Ô#ð ­IÔ,<Ô,E×,XÒ,XØÐ%Ô0ñ-ô -ð ð 	ˆå
‡K‚KØ1×8Ò8¸ÐEVÔE^Ñ_Ô_ñô ð õ „OÔ×<Ò<ØØØÝŒÔÔ0ØØÔ ñô ð õ ”>Ô'×<Ò<ØÐ%Ô-¨wÐ8JÈJÐXcñô €Lõ <Ø�L (¨GÐ5GÈÐU`ñô Ðõ .Ð.?Ô.IÐKaÑbÔb€MÝ‘%”%€KØ Ðà%2×%8Ò%8Ñ%:Ô%:ð ð Ñ!ˆ	�>Ø+ð 	ð 	ˆMÝ.EØÐ-¨y¸-ñ/ô /Ñ+ˆO˜^ð "ð Ø'×2Ò2°?Ð3OÀiÐQSÑTÔT×[Ò[Ø!ñô ð ð à�OŠO˜MÑ*Ô*Ð*Ý#ØØØØØ"Ø ØØØØÐ, 9Øñô ð ð ð	ð8 &=×%BÒ%BÑ%DÔ%Dð ð Ñ!ˆ	�>Ø+ð 	ð 	ˆMÝ.EØÐ-¨y¸-Èñ/ô /Ñ+ˆO˜^ð "ð Øà�OŠO˜MÑ*Ô*Ð*Ý”y Ñ0Ô0ˆHØ,ˆH�VÑå#ØØØØØ"Ø ØØØØÐ, 9Øñô ð ð ð	õ4 „OÔ×<Ò<ØØØÝŒÔÔ0ØØÔ ñô ð õ ˜=Ð*AÀ;ÑOÔOÐOÐOÐOr   r\   )rŠ   ÚloggingrD   Úborgmatic.borg.extractr-   Úborgmatic.borg.listÚborgmatic.borg.mountÚborgmatic.borg.rlistÚborgmatic.borg.stateÚborgmatic.config.validateÚborgmatic.hooks.dispatchÚborgmatic.hooks.dumpÚ	getLoggerÚ__name__r+   Úobjectr   r   r   r>   rX   rw   r~   rŽ   r   r   r   ú<module>r›      s-  ðØ €€€Ø €€€Ø 	€	€	€	à Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø  Ð  Ð  Ð  Ø Ð Ð Ð Ø Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ð �6‘8”8Ð ð Z^ðð ð ð ð@ð ð ð6ð 6ð 6ðr,"ð ,"ð ,"ð^.ð .ð .ðb
ð 
ð 
ð0mPð mPð mPð mPð mPr   