§
    ôc?,  ã                   óà   — 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mZmZm	Z	m
Z
mZmZ d dlmZmZ dddœdddœfZdZ ej        e¦  «        Zdd	„Zd
„ Zd„ Zdd„Zd„ Zd„ Zd„ Z	 	 	 	 	 	 dd„ZdS )é    N)ÚenvironmentÚextractÚfeatureÚflagsÚrinfoÚstate)ÚDO_NOT_CAPTUREÚexecute_commandÚ
repositoryz1 month)ÚnameÚ	frequencyÚarchivesz{hostname}-c                 ó
  — |p3t          d„ |                      dd¦  «        pt          D ¦   «         ¦  «        }t          d„ |D ¦   «         ¦  «        }d|v r/t          |¦  «        dk    rt                               d¦  «         dS |S )	a  
    Given a consistency config with a "checks" sequence of dicts and an optional list of override
    checks, return a tuple of named checks to run.

    For example, given a retention config of:

        {'checks': ({'name': 'repository'}, {'name': 'archives'})}

    This will be returned as:

        ('repository', 'archives')

    If no "checks" option is present in the config, return the DEFAULT_CHECKS. If a checks value
    has a name of "disabled", return an empty tuple, meaning that no checks should be run.
    c              3   ó&   K  — | ]}|d          V — ŒdS )r   N© )Ú.0Úcheck_configs     ú6/usr/lib/python3/dist-packages/borgmatic/borg/check.pyú	<genexpr>zparse_checks.<locals>.<genexpr>%   s;   è è € ð "ð "àð 	�VÔð"ð "ð "ð "ð "ð "ó    ÚchecksNc              3   ó>   K  — | ]}|                      ¦   «         V — Œd S ©N)Úlower©r   Úchecks     r   r   zparse_checks.<locals>.<genexpr>)   s*   è è € Ð5Ð5 U�5—;’;‘=”=Ð5Ð5Ð5Ð5Ð5Ð5r   Údisabledé   zUMultiple checks are configured, but one of them is "disabled"; not running any checksr   )ÚtupleÚgetÚDEFAULT_CHECKSÚlenÚloggerÚwarning)Úconsistency_configÚonly_checksr   s      r   Úparse_checksr'      s¨   € ð  ð �Eð "ð "à/×3Ò3°H¸dÑCÔCÐUÅ~ð"ñ "ô "ñ ô €Fõ Ð5Ð5¨fÐ5Ñ5Ô5Ñ5Ô5€FØ�VÐÐÝˆv‰;Œ;˜Š?ˆ?Ý�NŠNØgñô ð ð ˆrà€Mr   c                 óÎ  — | sdS |                       ¦   «                              ¦   «         } | dk    rdS 	 |                      d¦  «        \  }}t          |¦  «        }n!# t          $ r t	          d| › d�¦  «        ‚w xY w|                     d¦  «        s|dz  }|dk    r|dz  }d	}n|d
k    r|dz  }d	}	 t          j        di ||i¤ŽS # t          $ r t	          d| › d�¦  «        ‚w xY w)a/  
    Given a frequency string with a number and a unit of time, return a corresponding
    datetime.timedelta instance or None if the frequency is None or "always".

    For instance, given "3 weeks", return datetime.timedelta(weeks=3)

    Raise ValueError if the given frequency cannot be parsed.
    NÚalwaysú z-Could not parse consistency check frequency 'ú'ÚsÚmonthsé   ÚdaysÚyearsim  r   )	Ústripr   ÚsplitÚintÚ
ValueErrorÚendswithÚdatetimeÚ	timedeltaÚ	TypeError)r   ÚnumberÚ	time_units      r   Úparse_frequencyr;   4   sO  € ð ð Øˆtà—’Ñ!Ô!×'Ò'Ñ)Ô)€Ià�HÒÐØˆtðWØ%ŸOšO¨CÑ0Ô0Ñˆ�	Ý�V‘”ˆˆøÝð Wð Wð WÝÐUÈÐUÐUÐUÑVÔVÐVðWøøøð ×Ò˜cÑ"Ô"ð Ø�SÑˆ	à�HÒÐØ�"‰ˆØˆ	ˆ	Ø	�gÒ	Ð	Ø�#‰ˆØˆ	ðWÝÔ!Ð8Ð8 Y°Ð$7Ð8Ð8Ð8øÝð Wð Wð WÝÐUÈÐUÐUÐUÑVÔVÐVðWøøøs   ´'A ÁA:Â3C ÃC$c                 óD  — t          |¦  «        }|rt          |¦  «        S |                     dt          ¦  «        D ]Ö}|d         }|r||vrŒt	          |                     d¦  «        ¦  «        }|sŒ6t          t          | ||¦  «        ¦  «        }	|	sŒWt          j                             ¦   «         |	|z   k     rZ|	|z   t          j                             ¦   «         z
  }
t           
                    d|› d|
› d�¦  «         |                     |¦  «         Œ×t          |¦  «        S )a¶  
    Given a location config, a consistency config with a "checks" sequence of dicts, a Borg
    repository ID, a sequence of checks, and whether to force checks to run, filter down those
    checks based on the configured "frequency" for each check as compared to its check time file.

    In other words, a check whose check time file's timestamp is too new (based on the configured
    frequency) will get cut from the returned sequence of checks. Example:

    consistency_config = {
        'checks': [
            {
                'name': 'archives',
                'frequency': '2 weeks',
            },
        ]
    }

    When this function is called with that consistency_config and "archives" in checks, "archives"
    will get filtered out of the returned result if its check time file is newer than 2 weeks old,
    indicating that it's not yet time to run that check again.

    Raise ValueError if a frequency cannot be parsed.
    r   r   r   z	Skipping z$ check due to configured frequency; z until next check)Úlistr   r    r!   r;   Úread_check_timeÚmake_check_time_pathr6   Únowr#   ÚinfoÚremove)Úlocation_configr%   Úborg_repository_idr   ÚforceÚfiltered_checksr   r   Úfrequency_deltaÚ
check_timeÚ	remainings              r   Úfilter_checks_on_frequencyrJ   [   sE  € õ4 ˜6‘l”l€Oàð &Ý�_Ñ%Ô%Ð%à*×.Ò.¨x½ÑHÔHð *ð *ˆØ˜VÔ$ˆØð 	�e 6Ð)Ð)Øå)¨,×*:Ò*:¸;Ñ*GÔ*GÑHÔHˆØð 	Øå$Ý  Ð2DÀeÑLÔLñ
ô 
ˆ
ð ð 	Øõ Ô× Ò Ñ"Ô" Z°/Ñ%AÒAÐAØ" _Ñ4µxÔ7H×7LÒ7LÑ7NÔ7NÑNˆIÝ�KŠKØc˜EÐcÐcÀyÐcÐcÐcñô ð ð ×"Ò" 5Ñ)Ô)Ð)øå�Ñ!Ô!Ð!r   c                 óÖ  — d|v rd}|dz  }nd}d|v rR|rdt          |¦  «        fnd}t          j        t          j        j        | ¦  «        r|rdd|› d	�fnd}nH|rd
|› d	�fnd}n<d}d}|rt
                               d¦  «         |rt
                               d¦  «         ||z   |z   }ddh                     t          |¦  «        ¦  «        r|S t          d„ |D ¦   «         ¦  «        |z   S )a¤  
    Given the local Borg version and a parsed sequence of checks, transform the checks into tuple of
    command-line flags.

    For example, given parsed checks of:

        ('repository',)

    This will be returned as:

        ('--repository-only',)

    However, if both "repository" and "archives" are in checks, then omit them from the returned
    flags because Borg does both checks by default. If "data" is in checks, that implies "archives".

    Additionally, if a check_last value is given and "archives" is in checks, then include a
    "--last" flag. And if a prefix value is given and "archives" is in checks, then include a
    "--match-archives" flag.
    Údata)z--verify-data)r   r   r   z--lastz--match-archiveszsh:Ú*z--glob-archiveszQIgnoring check_last option, as "archives" or "data" are not in consistency checkszYIgnoring consistency prefix option, as "archives" or "data" are not in consistency checksr   c              3   óH   K  — | ]}|d v ¯d                      |¦  «        V — ŒdS ))r   r   z	--{}-onlyN)Úformatr   s     r   r   z#make_check_flags.<locals>.<genexpr>Ç   s;   è è € ÐcÐc¨E¸uÐHbÐ?bÐ?bˆk× Ò  Ñ'Ô'Ð?bÐ?bÐ?bÐ?bÐcÐcr   )
Ústrr   Ú	availableÚFeatureÚMATCH_ARCHIVESr#   r$   ÚissubsetÚsetr   )Úlocal_borg_versionr   Ú
check_lastÚprefixÚ
data_flagsÚ
last_flagsÚmatch_archives_flagsÚcommon_flagss           r   Úmake_check_flagsr]   •   sY  € ð( �ÐÐØ'ˆ
Ø�-Ñˆˆàˆ
à�VÐÐØ4>ÐF�h¥ J¡¤Ð0Ð0ÀBˆ
ÝÔ�Wœ_Ô;Ð=OÑPÔPð 	WØLRÐ#ZÐ$6¸¸f¸¸¸Ð#HÐ#HÐXZÐ Ð àHNÐ#VÐ$5¸&°|°|°|Ð#DÐ#DÐTVÐ Ð àˆ
Ø!ÐØð 	Ý�NŠNØcñô ð ð ð 	Ý�NŠNØkñô ð ð Ð 4Ñ4°zÑA€Là�jÐ!×*Ò*­3¨v©;¬;Ñ7Ô7ð ØÐõ 	ÐcÐc°VÐcÑcÔcÑcÔcØ
ñ	ðr   c                 ó¼   — t           j                             t           j                             |                      dt
          j        ¦  «        ¦  «        d||¦  «        S )zâ
    Given a location configuration dict, a Borg repository ID, and the name of a check type
    ("repository", "archives", etc.), return a path for recording that check's time (the time of
    that check last occurring).
    Úborgmatic_source_directoryr   )ÚosÚpathÚjoinÚ
expanduserr    r   Ú"DEFAULT_BORGMATIC_SOURCE_DIRECTORY)rC   rD   Ú
check_types      r   r?   r?   Ì   sW   € õ Œ7�<Š<Ý
Œ×ÒØ×ÒØ,­eÔ.Vñô ñ	
ô 	
ð
 	ØØñ	ô 	ð 	r   c                 óø   — t                                d| › �¦  «         t          j        t          j                             | ¦  «        dd¬¦  «         t          j        | d¬¦  «                             ¦   «          dS )zP
    Record a check time of now as the modification time of the given path.
    zWriting check time at iÀ  T)ÚmodeÚexist_oki€  )rg   N)	r#   Údebugr`   Úmakedirsra   ÚdirnameÚpathlibÚPathÚtouch©ra   s    r   Úwrite_check_timerp   Þ   sk   € õ ‡L‚LÐ0¨$Ð0Ð0Ñ1Ô1Ð1å„K•”—’ Ñ%Ô%¨E¸DÐAÑAÔAÐAÝ„L�˜EÐ"Ñ"Ô"×(Ò(Ñ*Ô*Ð*Ð*Ð*r   c                 óÌ   — t                                d| › �¦  «         	 t          j                             t	          j        | ¦  «        j        ¦  «        S # t          $ r Y dS w xY w)z|
    Return the check time based on the modification time of the given path. Return None if the path
    doesn't exist.
    zReading check time from N)r#   ri   r6   Úfromtimestampr`   ÚstatÚst_mtimeÚFileNotFoundErrorro   s    r   r>   r>   è   sh   € õ
 ‡L‚LÐ2¨DÐ2Ð2Ñ3Ô3Ð3ðÝÔ ×.Ò.­r¬w°t©}¬}Ô/EÑFÔFÐFøÝð ð ð Øˆtˆtðøøøs   Ÿ5A Á
A#Á"A#Úborgc           
      óN  — 	 t          j        t          j        | ||t	          j        d¬¦  «        ||¦  «        ¦  «        d         d         }n,# t           j        t          f$ r t          d| › �¦  «        ‚w xY wt          |||t          ||	¦  «        |
¦  «        }|                     dd¦  «        }d}|                     di ¦  «                             d	d
¦  «        }t          |¦  «                             h d£¦  «        �rg|                     dd¦  «        }d}t                               t           j        ¦  «        rd}t                               t           j        ¦  «        rd}|                     dt&          ¦  «        }|d	f|rdndz   t)          ||||¦  «        z   |rd|fndz   |rdt+          |¦  «        fndz   |z   |rdndz   |r"t-          |                     d¦  «        ¦  «        ndz   t1          j        | |¦  «        z   }t5          j        |¦  «        }|s|rt9          |t:          |¬¦  «         nt9          ||¬¦  «         |D ] }t=          t?          |||¦  «        ¦  «         Œ!d|v r9tA          j!        ||| |||¦  «         t=          t?          ||d¦  «        ¦  «         dS dS )aÕ  
    Given a local or remote repository path, a storage config dict, a consistency config dict,
    local/remote commands to run, whether to include progress information, whether to attempt a
    repair, and an optional list of checks to use instead of configured checks, check the contained
    Borg archives for consistency.

    If there are no consistency checks to run, skip running them.

    Raises ValueError if the Borg repository ID cannot be determined.
    T)Újsonr   Úidz(Cannot determine Borg repository ID for rW   NÚextra_borg_optionsr   Ú >   rL   r   r   Ú	lock_waitr   )z--info)z--debugz	--show-rcrX   )z--repairz--remote-pathz--lock-wait)z
--progressr*   )Úoutput_fileÚextra_environment)r~   r   )"rx   Úloadsr   Údisplay_repository_infoÚargparseÚ	NamespaceÚJSONDecodeErrorÚKeyErrorr4   rJ   r'   r    rU   Úintersectionr#   ÚisEnabledForÚloggingÚINFOÚDEBUGÚDEFAULT_PREFIXr]   rP   r   r2   r   Úmake_repository_flagsr   Úmake_environmentr
   r	   rp   r?   r   Úextract_last_archive_dry_run)r   rC   Ústorage_configr%   rV   Ú
local_pathÚremote_pathÚprogressÚrepairr&   rE   rD   r   rW   r|   rz   Úverbosity_flagsrX   Úfull_commandÚborg_environmentr   s                        r   Úcheck_archivesr–   õ   s_  € ð.RÝ!œZÝÔ)ØØØ"ÝÔ"¨Ð-Ñ-Ô-ØØñô ñ	
ô 	
ð ô	ð ô	ÐÐøõ Ô ¥(Ð+ð Rð Rð RÝÐPÀJÐPÐPÑQÔQÐQðRøøøõ (ØØØÝÐ'¨Ñ5Ô5Øñô €Fð $×'Ò'¨°dÑ;Ô;€JØ€IØ'×+Ò+Ð,@À"ÑEÔE×IÒIÈ'ÐSUÑVÔVÐå
ˆ6�{„{×ÒÐ BÐ BÐ BÑCÔCñ #_Ø"×&Ò& {°DÑ9Ô9ˆ	àˆÝ×Ò�wœ|Ñ,Ô,ð 	*Ø)ˆOÝ×Ò�wœ}Ñ-Ô-ð 	7Ø6ˆOà#×'Ò'¨µ.ÑAÔAˆð ˜Ð!Ø &Ð.ˆ}ˆ}¨Bñ0åÐ1°6¸:ÀvÑNÔNñOð 2=ÐD� Ð-Ð-À"ñFð 3<ÐC��s 9™~œ~Ð.Ð.Àñ	Eð
 ñð #+Ð2ˆˆ°ñ4ð 8JÐQ�uÐ'×-Ò-¨cÑ2Ô2Ñ3Ô3Ð3ÈrñSõ Ô)¨*Ð6HÑIÔIñJð 	õ 'Ô7¸ÑGÔGÐð ð 	N�Xð 	NÝØ­.ÐL\ðñ ô ð ð õ ˜LÐ<LÐMÑMÔMÐMàð 	_ð 	_ˆEÝÕ1°/ÐCUÐW\Ñ]Ô]Ñ^Ô^Ð^Ð^à�FÐÐÝÔ,ØÐ.°
¸IÀzÐS^ñ	
ô 	
ð 	
õ 	Õ-¨oÐ?QÐS\Ñ]Ô]Ñ^Ô^Ð^Ð^Ð^ð	 Ðs   ‚A
A Á)A6r   )NN)rv   NNNNN)r�   r6   rx   r‡   r`   rl   Úborgmatic.borgr   r   r   r   r   r   Úborgmatic.executer	   r
   r!   rŠ   Ú	getLoggerÚ__name__r#   r'   r;   rJ   r]   r?   rp   r>   r–   r   r   r   ú<module>r›      st  ðØ €€€Ø €€€Ø €€€Ø €€€Ø 	€	€	€	Ø €€€à MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ =Ð =Ð =Ð =Ð =Ð =Ð =Ð =ð ¨	Ð2Ð2Ø iÐ0Ð0ð€ð €ð 
ˆÔ	˜8Ñ	$Ô	$€ðð ð ð ð>$Wð $Wð $WðN7"ð 7"ð 7"ðt4ð 4ð 4ð 4ðnð ð ð$+ð +ð +ð
ð 
ð 
ð& ØØØØØ
ðY_ð Y_ð Y_ð Y_ð Y_ð Y_r   