§
    ôcŒ  ã                   óx   — d dl Z d dlmZmZ d dlmZ  e j        e¦  «        Zd„ Z	d„ Z
d„ Zd„ Z	 dd„Zd	„ Zd
„ ZdS )é    N)Úexecute_commandÚexecute_command_with_processes)Údumpc                 óR   — t          j        |                      d¦  «        d¦  «        S )z]
    Make the dump path from the given location configuration and the name of this hook.
    Úborgmatic_source_directoryÚmongodb_databases)r   Úmake_database_dump_pathÚget)Úlocation_configs    ú9/usr/lib/python3/dist-packages/borgmatic/hooks/mongodb.pyÚmake_dump_pathr   	   s.   € õ Ô'Ø×ÒÐ8Ñ9Ô9Ð;Nñô ð ó    c           	      óz  — |rdnd}t                                d                     ||¦  «        ¦  «         g }| D �] }|d         }t          j        t          |¦  «        ||                     d¦  «        ¦  «        }|                     dd¦  «        }	t                                d                     ||||¦  «        ¦  «         |rŒŠt          |||	¦  «        }
|	d	k    r&t          j	        |¦  «         t          |
d
¬¦  «         ŒÇt          j        |¦  «         |                     t          |
d
d¬¦  «        ¦  «         �Œ|S )a   
    Dump the given MongoDB databases to a named pipe. The databases are supplied as a sequence of
    dicts, one dict describing each database as per the configuration schema. Use the given log
    prefix in any log entries. Use the given location configuration dict to construct the
    destination path.

    Return a sequence of subprocess.Popen instances for the dump processes ready to spew to a named
    pipe. But if this is a dry run, then don't actually dump anything and return an empty sequence.
    z) (dry run; not actually dumping anything)Ú z{}: Dumping MongoDB databases{}ÚnameÚhostnameÚformatÚarchivez'{}: Dumping MongoDB database {} to {}{}Ú	directoryT)ÚshellF)r   Úrun_to_completion)ÚloggerÚinfor   r   Úmake_database_dump_filenamer   r
   ÚdebugÚbuild_dump_commandÚ create_parent_directory_for_dumpr   Úcreate_named_pipe_for_dumpÚappend)Ú	databasesÚ
log_prefixr   Údry_runÚdry_run_labelÚ	processesÚdatabaser   Údump_filenameÚdump_formatÚcommands              r   Údump_databasesr)      s\  € ð DKÐRÐ?Ð?ÐPR€Må
‡K‚KÐ1×8Ò8¸À]ÑSÔSÑTÔTÐTà€IØð \ñ \ˆØ˜ÔˆÝÔ8Ý˜?Ñ+Ô+¨T°8·<²<À
Ñ3KÔ3Kñ
ô 
ˆð —l’l 8¨YÑ7Ô7ˆå�ŠØ5×<Ò<Ø˜D -°ñô ñ	
ô 	
ð 	
ð
 ð 	Øå$ X¨}¸kÑJÔJˆà˜+Ò%Ð%ÝÔ1°-Ñ@Ô@Ð@Ý˜G¨4Ð0Ñ0Ô0Ð0Ð0åÔ+¨MÑ:Ô:Ð:Ø×Ò�_¨W¸DÐTYÐZÑZÔZÑ[Ô[Ð[Ñ[àÐr   c                 ó   — | d         dk    }dg}|dk    r|                      d|f¦  «         d| v r|                      d| d         f¦  «         d| v r*|                      d	t          | d         ¦  «        f¦  «         d
| v r|                      d| d
         f¦  «         d| v r|                      d| d         f¦  «         d| v r|                      d| d         f¦  «         |s|                      d| d         f¦  «         d| v r.|                      | d                              d¦  «        ¦  «         |dk    r|                      dd|f¦  «         |S )zL
    Return the mongodump command from a single database configuration.
    r   ÚallÚ	mongodumpr   z--outr   ú--hostÚportú--portÚusernameú
--usernameÚpasswordú
--passwordÚauthentication_databaseú--authenticationDatabaseú--dbÚoptionsú ú	--archiveú>)ÚextendÚstrÚsplit)r%   r&   r'   Úall_databasesr(   s        r   r   r   <   s†  € ð ˜VÔ$¨Ò-€MØˆm€GØ�kÒ!Ð!Ø�Š˜ Ð/Ñ0Ô0Ð0Ø�XÐÐØ�Š˜ (¨:Ô"6Ð7Ñ8Ô8Ð8Ø�ÐÐØ�Š˜¥# h¨vÔ&6Ñ"7Ô"7Ð8Ñ9Ô9Ð9Ø�XÐÐØ�Š˜ h¨zÔ&:Ð;Ñ<Ô<Ð<Ø�XÐÐØ�Š˜ h¨zÔ&:Ð;Ñ<Ô<Ð<Ø  HÐ,Ð,Ø�ŠÐ2°HÐ=VÔ4WÐXÑYÔYÐYØð 3Ø�Š˜ ¨Ô 0Ð1Ñ2Ô2Ð2Ø�HÐÐØ�Š�x 	Ô*×0Ò0°Ñ5Ô5Ñ6Ô6Ð6Ø�kÒ!Ð!Ø�Š˜ S¨-Ð8Ñ9Ô9Ð9Ø€Nr   c                 óN   — t          j        t          |¦  «        d||¦  «         dS )a  
    Remove all database dump files for this hook regardless of the given databases. Use the log
    prefix in any log entries. Use the given location configuration dict to construct the
    destination path. If this is a dry run, then don't actually remove anything.
    ÚMongoDBN)r   Úremove_database_dumpsr   )r    r!   r   r"   s       r   rA   rA   W   s*   € õ 	Ô�~¨oÑ>Ô>À	È:ÐW^Ñ_Ô_Ð_Ð_Ð_r   c                 óJ   — t          j        t          |¦  «        |d¬¦  «        S )zß
    Given a sequence of configurations dicts, a prefix to log with, a location configuration dict,
    and a database name to match, return the corresponding glob patterns to match the database dump
    in an archive.
    Ú*)r   )r   r   r   )r    r!   r   r   s       r   Úmake_database_dump_patternrD   `   s%   € õ Ô+­N¸?Ñ,KÔ,KÈTÐ\_Ð`Ñ`Ô`Ð`r   c                 óÈ  — |rdnd}t          | ¦  «        dk    rt          d¦  «        ‚| d         }t          j        t	          |¦  «        |d         |                     d¦  «        ¦  «        }t          |||¦  «        }t                               d 	                    ||d         |¦  «        ¦  «         |rd	S t          ||r|gng t          j        |r|j        nd	¬
¦  «         d	S )a  
    Restore the given MongoDB database from an extract stream. The database is supplied as a
    one-element sequence containing a dict describing the database, as per the configuration schema.
    Use the given log prefix in any log entries. If this is a dry run, then don't actually restore
    anything. Trigger the given active extract process (an instance of subprocess.Popen) to produce
    output to consume.

    If the extract process is None, then restore the dump from the filesystem rather than from an
    extract stream.
    z+ (dry run; not actually restoring anything)r   é   z+The database configuration value is invalidr   r   r   z#{}: Restoring MongoDB database {}{}N)Úoutput_log_levelÚ
input_file)ÚlenÚ
ValueErrorr   r   r   r
   Úbuild_restore_commandr   r   r   r   ÚloggingÚDEBUGÚstdout)	Údatabase_configr!   r   r"   Úextract_processr#   r%   r&   Úrestore_commands	            r   Úrestore_database_dumprR   k   s  € ð FMÐTÐAÐAÐRT€Må
ˆ?ÑÔ˜qÒ Ð ÝÐFÑGÔGÐGà˜qÔ!€HÝÔ4Ý�Ñ'Ô'¨°&Ô)9¸8¿<º<È
Ñ;SÔ;Sñô €Mõ ,¨O¸XÀ}ÑUÔU€Oå
‡L‚LØ-×4Ò4°ZÀÈ&ÔAQÐS`ÑaÔañô ð ð ð Øˆõ #ØØ,Ð4ˆÐÐ°"Ý œØ-<ÐF�?Ô)Ð)À$ð	ñ ô ð ð ð r   c                 ó†  — dg}| r|                      d¦  «         n|                     d|f¦  «         |d         dk    r|                     dd|d         f¦  «         d|v r|                     d	|d         f¦  «         d
|v r*|                     dt          |d
         ¦  «        f¦  «         d|v r|                     d|d         f¦  «         d|v r|                     d|d         f¦  «         d|v r|                     d|d         f¦  «         d|v r.|                     |d                              d¦  «        ¦  «         |S )zO
    Return the mongorestore command from a single database configuration.
    Úmongorestorer9   z--dirr   r+   z--dropr6   r   r-   r.   r/   r0   r1   r2   r3   r4   r5   Úrestore_optionsr8   )r   r;   r<   r=   )rP   r%   r&   r(   s       r   rK   rK   ‘   sq  € ð Ð€GØð 1Ø�Š�{Ñ#Ô#Ð#Ð#à�Š˜ Ð/Ñ0Ô0Ð0Ø�Ô˜5Ò Ð Ø�Š˜ &¨(°6Ô*:Ð;Ñ<Ô<Ð<Ø�XÐÐØ�Š˜ (¨:Ô"6Ð7Ñ8Ô8Ð8Ø�ÐÐØ�Š˜¥# h¨vÔ&6Ñ"7Ô"7Ð8Ñ9Ô9Ð9Ø�XÐÐØ�Š˜ h¨zÔ&:Ð;Ñ<Ô<Ð<Ø�XÐÐØ�Š˜ h¨zÔ&:Ð;Ñ<Ô<Ð<Ø  HÐ,Ð,Ø�ŠÐ2°HÐ=VÔ4WÐXÑYÔYÐYØ˜HÐ$Ð$Ø�Š�xÐ 1Ô2×8Ò8¸Ñ=Ô=Ñ>Ô>Ð>Ø€Nr   )N)rL   Úborgmatic.executer   r   Úborgmatic.hooksr   Ú	getLoggerÚ__name__r   r   r)   r   rA   rD   rR   rK   © r   r   ú<module>r[      sÐ   ðØ €€€à MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ  Ð  Ð  Ð  Ð  Ð  à	ˆÔ	˜8Ñ	$Ô	$€ðð ð ð'ð 'ð 'ðTð ð ð6`ð `ð `ð 26ðað að að að#ð #ð #ðLð ð ð ð r   