§
    ôc]#  ã                   ó�   — d dl Z d dlZd dlZd dlmZmZmZ d dlmZ  ej	        e
¦  «        Zd„ ZdZd„ Zd„ Zd„ Zd	„ Z	 dd
„Zd„ ZdS )é    N)Úexecute_commandÚ"execute_command_and_capture_outputÚ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Úmysql_databases)r   Úmake_database_dump_pathÚget)Úlocation_configs    ú7/usr/lib/python3/dist-packages/borgmatic/hooks/mysql.pyÚmake_dump_pathr      s.   € õ Ô'Ø×ÒÐ8Ñ9Ô9Ð;Lñô ð ó    )Úinformation_schemaÚmysqlÚperformance_schemaÚsysc                 ó,  — | d         dk    r	| d         fS dd| v r(t          | d                              d¦  «        ¦  «        ndz   d| v r
d| d         fndz   d	| v rd
t          | d	         ¦  «        fndz   d| v sd	| v rdndz   d| v r
d| d         fndz   dz   dz   }t                               d                     ||¦  «        ¦  «         t          ||¬¦  «        }t          d„ |                     ¦   «                              ¦   «         D ¦   «         ¦  «        S )a  
    Given a requested database config, return the corresponding sequence of database names to dump.
    In the case of "all", query for the names of databases on the configured host and return them,
    excluding any system databases that will cause problems during restore.
    ÚnameÚall)r   Úlist_optionsú © Úhostnameú--hostÚportú--port©z
--protocolÚtcpÚusernameú--user)z--skip-column-namesú--batch)z	--executezshow schemasz0{}: Querying for "all" MySQL databases to dump{})Úextra_environmentc              3   ó,   K  — | ]}|t           v¯|V — Œd S ©N)ÚSYSTEM_DATABASE_NAMES)Ú.0Ú	show_names     r   ú	<genexpr>z)database_names_to_dump.<locals>.<genexpr>5   s:   è è € ð ð àØÕ1Ð1Ð1ð 	à1Ð1Ð1Ð1ðð r   )	ÚtupleÚsplitÚstrÚloggerÚdebugÚformatr   ÚstripÚ
splitlines)Údatabaser#   Ú
log_prefixÚdry_run_labelÚshow_commandÚshow_outputs         r   Údatabase_names_to_dumpr7      s›  € ð �Ô˜5Ò Ð Ø˜Ô Ð"Ð"ð 	Ø9GÈ8Ð9SÐ9S�5�˜.Ô)×/Ò/°Ñ4Ô4Ñ5Ô5Ð5ÐY[ñ	]à/9¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð 17¸(Ð0BÐ0BˆH•c˜( 6Ô*Ñ+Ô+Ð,Ð,Èñ	Lð %/°(Ð$:Ð$:¸fÈÐ>PÐ>PÐ Ð ÐVXñ		Zð
 0:¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð -ñ	-ð (ñ	(ð õ ‡L‚LØ:×AÒAÀ*ÈmÑ\Ô\ñô ð õ 5ØÐ(9ðñ ô €Kõ ð ð à$×*Ò*Ñ,Ô,×7Ò7Ñ9Ô9ðñ ô ñ ô ð r   c                 óÜ  — | d         }t          j        || d         |                      d¦  «        ¦  «        }t          j                             |¦  «        r$t                               |› d|› d|› �¦  «         dS dd| v r(t          | d          	                    d¦  «        ¦  «        nd	z   |                      d
d¦  «        rdnd	z   d| v r
d| d         fnd	z   d| v rdt          | d         ¦  «        fnd	z   d| v sd| v rdnd	z   d| v r
d| d         fnd	z   dz   |z   d|fz   }	t                               |› d|› d|› |› �¦  «         |rdS t          j        |¦  «         t          |	d|d¬¦  «        S )aŒ  
    Kick off a dump for the given MySQL/MariaDB database (provided as a configuration dict) to a
    named pipe constructed from the given dump path and database names. Use the given log prefix in
    any log entries.

    Return a subprocess.Popen instance for the dump process ready to spew to a named pipe. But if
    this is a dry run, then don't actually dump anything and return None.
    r   r   z-: Skipping duplicate dump of MySQL database "z" to N)Ú	mysqldumpÚoptionsr   r   Úadd_drop_databaseT)z--add-drop-databaser   r   r   r   r    r!   )z--databasesú>z: Dumping MySQL database "F)Úshellr#   Úrun_to_completion)r   Úmake_database_dump_filenamer   ÚosÚpathÚexistsr-   Úwarningr*   r+   r,   r.   Úcreate_named_pipe_for_dumpr   )
r2   r3   Ú	dump_pathÚdatabase_namesr#   Údry_runr4   Údatabase_nameÚdump_filenameÚdump_commands
             r   Úexecute_dump_commandrK   <   s  € ð ˜VÔ$€MÝÔ4Ø�8˜FÔ# X§\¢\°*Ñ%=Ô%=ñô €Mõ 
„w‡~‚~�mÑ$Ô$ð Ý�ŠØÐkÐkÈÐkÐkÐ\iÐkÐkñ	
ô 	
ð 	
ð ˆtð 	Ø4=ÀÐ4IÐ4I�5�˜)Ô$×*Ò*¨3Ñ/Ô/Ñ0Ô0Ð0Èrñ	Sà'/§|¢|Ð4GÈÑ'NÔ'NÐVÐ#Ð#ÐTVñ	Xð 0:¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð 17¸(Ð0BÐ0BˆH•c˜( 6Ô*Ñ+Ô+Ð,Ð,Èñ		Lð
 %/°(Ð$:Ð$:¸fÈÐ>PÐ>PÐ Ð ÐVXñ	Zð 0:¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð ñ	ð ñ	ð �Ð
ñ	ð õ ‡L‚LØÐcÐc°ÐcÐcÀ]ÐcÐTaÐcÐcñô ð ð ð ØˆtåÔ# MÑ2Ô2Ð2åØ˜DÐ4EÐY^ðñ ô ð r   c                 ó6  — |rdnd}g }t                                d                     ||¦  «        ¦  «         | D ]Õ}t          |¦  «        }d|v r
d|d         ind}t	          ||||¦  «        }	|	st          d¦  «        ‚|d         d	k    r]|                     d
¦  «        rH|	D ]D}
t          j        |¦  «        }|
|d<   |                     t          ||||
f|||¦  «        ¦  «         ŒEŒ­|                     t          ||||	|||¦  «        ¦  «         ŒÖd„ |D ¦   «         S )a  
    Dump the given MySQL/MariaDB 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 MySQL databases{}ÚpasswordÚ	MYSQL_PWDNz(Cannot find any MySQL databases to dump.r   r   r/   c                 ó   — g | ]}|¯|‘ŒS r   r   )r'   Úprocesss     r   ú
<listcomp>z"dump_databases.<locals>.<listcomp>¡   s   € Ð8Ð8Ð8˜°Ð8ˆGÐ8Ð8Ð8r   )
r-   Úinfor/   r   r7   Ú
ValueErrorr   ÚcopyÚappendrK   )Ú	databasesr3   r   rG   r4   Ú	processesr2   rE   r#   Údump_database_namesÚ	dump_nameÚrenamed_databases               r   Údump_databasesr\   m   s˜  € ð DKÐRÐ?Ð?ÐPR€MØ€Iå
‡K‚KÐ/×6Ò6°zÀ=ÑQÔQÑRÔRÐRàð #ð #ˆÝ" ?Ñ3Ô3ˆ	ØCMÐQYÐCYÐCY˜[¨(°:Ô*>Ð?Ð?Ð_cÐÝ4ØÐ'¨°]ñ
ô 
Ðð #ð 	IÝÐGÑHÔHÐHà�FÔ˜uÒ$Ð$¨¯ª°hÑ)?Ô)?Ð$Ø0ð ð �	Ý#'¤9¨XÑ#6Ô#6Ð Ø+4Ð  Ñ(Ø× Ò Ý(Ø(Ø"Ø!Ø"˜Ø)ØØ%ñô ñ
ô 
ð 
ð 
ðð ×ÒÝ$ØØØØ'Ø%ØØ!ñô ñ
ô 
ð 
ð 
ð 9Ð8 9Ð8Ñ8Ô8Ð8r   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.
    ÚMySQLN)r   Úremove_database_dumpsr   )rW   r3   r   rG   s       r   r_   r_   ¤   s*   € õ 	Ô�~¨oÑ>Ô>ÀÈÐU\Ñ]Ô]Ð]Ð]Ð]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   )rW   r3   r   r   s       r   Úmake_database_dump_patternrb   ­   s%   € õ Ô+­N¸?Ñ,KÔ,KÈTÐ\_Ð`Ñ`Ô`Ð`r   c                 ó<  — |rdnd}t          | ¦  «        dk    rt          d¦  «        ‚| d         }dd|v r(t          |d                              d¦  «        ¦  «        nd	z   d
|v r
d|d
         fnd	z   d|v rdt	          |d         ¦  «        fnd	z   d
|v sd|v rdnd	z   d|v r
d|d         fnd	z   }d|v r
d|d         ind}t
                               d                     ||d         |¦  «        ¦  «         |rdS t          ||gt          j
        |j        |¬¦  «         dS )a«  
    Restore the given MySQL/MariaDB 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.
    z+ (dry run; not actually restoring anything)rM   é   z+The database configuration value is invalidr   )r   r"   Úrestore_optionsr   r   r   r   r   r   r   r    r!   rN   rO   Nz!{}: Restoring MySQL database {}{}r   )Úoutput_log_levelÚ
input_filer#   )ÚlenrT   r*   r+   r,   r-   r.   r/   r   ÚloggingÚDEBUGÚstdout)	Údatabase_configr3   r   rG   Úextract_processr4   r2   Úrestore_commandr#   s	            r   Úrestore_database_dumpro   ¸   s·  € ð FMÐTÐAÐAÐRT€Må
ˆ?ÑÔ˜qÒ Ð ÝÐFÑGÔGÐGà˜qÔ!€HàØ<MÐQYÐ<YÐ<Y�5�Ð+Ô,×2Ò2°3Ñ7Ô7Ñ8Ô8Ð8Ð_añ	cà/9¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð 17¸(Ð0BÐ0BˆH•c˜( 6Ô*Ñ+Ô+Ð,Ð,Èñ	Lð %/°(Ð$:Ð$:¸fÈÐ>PÐ>PÐ Ð ÐVXñ		Zð
 0:¸XÐ/EÐ/EˆH�h˜zÔ*Ð+Ð+È2ñ	Oð ð @JÈXÐ?UÐ?U˜ h¨zÔ&:Ð;Ð;Ð[_Ðå
‡L‚LØ+×2Ò2°:¸xÈÔ?OÐQ^Ñ_Ô_ñô ð ð ð Øˆõ #ØØ	ÐÝ œØ"Ô)Ø+ðñ ô ð ð ð r   r%   )rU   ri   r@   Úborgmatic.executer   r   r   Úborgmatic.hooksr   Ú	getLoggerÚ__name__r-   r   r&   r7   rK   r\   r_   rb   ro   r   r   r   ú<module>rt      s  ðØ €€€Ø €€€Ø 	€	€	€	ðð ð ð ð ð ð ð ð ð ð
 !Ð  Ð  Ð  Ð  Ð  à	ˆÔ	˜8Ñ	$Ô	$€ðð ð ð UÐ ðð ð ðB.ð .ð .ðb49ð 49ð 49ðn^ð ^ð ^ð 26ðað að að að&ð &ð &ð &ð &r   