Current File : //usr/lib64/python3.6/site-packages/borg/__pycache__/archiver.cpython-36.pyc
3

up�d/�@s�ddlZddlZ�y2ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlmZmZddl	mZddlmZm Z e�Zddl!Z!ddl"m#Z#dd	l"m$Z$dd
l"m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-dd
l(m.Z.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5ddl6Tddl7m8Z8ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?ddl@mAZAddl$mBZBmCZCmDZDmEZEddl$mFZFmGZGmHZHddl$mIZImJZJmKZKmLZLmMZMddl$mNZNmOZOmPZPmQZQmRZRmSZSddl$mTZTmUZUmVZVddl$mWZWmXZXmYZYmZZZddl$m[Z[m\Z\m]Z]m^Z^ddl$m_Z_m`Z`maZaddl$mbZbddl$mcZcddl$mdZdddl$meZeddl$mfZfdd l$mgZgmhZhdd!l$miZimjZjmkZkmlZlmmZmdd"l$mnZndd#l$moZompZpmqZqmrZrdd$l$msZsdd%l$mtZtdd&l$muZumvZvdd'l$mwZwdd(l$mxZxdd)l$myZymzZzdd*l$m{Z{dd+l$m|Z|dd,l$m}Z}m~Z~dd-l$mZm�Z�dd.l$m�Z�dd/l�m�Z�dd0l�m�Z�m�Z�m�Z�m�Z�dd1l�m�Z�dd2l�m�Z�m�Z�dd3l�m�Z�m�Z�m�Z�dd4l�m�Z�m�Z�m�Z�dd5l�m�Z�m�Z�m�Z�m�Z�m�Z�dd6l�m�Z�dd7l�m�Z�m�Z�Wn(e�k
�rlej��ej�d8�YnXeDd8k�s�t�d9��d:Z�d;Z�d<d=�Z�dQd@dA�Z�dBdC�Z�dDdE�Z�dFdG�Z�GdHdI�dI�Z�dJdK�Z�dLdM�Z�dNdO�Z�e�dPk�r�e��dS)R�N)�	unhexlify�hexlify)�contextmanager)�datetime�	timedelta)�zip_longest�)�
create_logger�
setup_logging)�__version__)�helpers)�shellpattern)�crc32)�Archive�ArchiveChecker�ArchiveRecreater�
Statistics�
is_special)�BackupError�
BackupOSError�	backup_io�has_link)�Cache�
assert_secure�SecurityManager)�*)�CompressionSpec)�key_creator�key_argument_names�tam_required_file�tam_required�RepoKey�
PassphraseKey)�
KeyManager)�EXIT_SUCCESS�EXIT_WARNING�
EXIT_ERROR�EXIT_SIGNAL_BASE)�Error�NoManifestError�set_ec)�positive_int_validator�location_validator�archivename_validator�
ChunkerParams�Location)�
PrefixSpec�GlobSpec�CommentSpec�
SortBySpec�HUMAN_SORT_KEYS�FilesCacheMode)�
BaseFormatter�
ItemFormatter�ArchiveFormatter)�format_timedelta�format_file_size�parse_file_size�format_archive)�safe_encode�remove_surrogates�
bin_to_hex�prepare_dump_dict)�interval�prune_within�prune_split)�	timestamp)�
get_cache_dir)�Manifest)�hardlinkable)�
StableDict)�check_python�check_extension_modules)�
dir_is_tagged�is_slow_msgpack�is_supported_msgpack�yes�sysinfo)�	log_multi)�signal_handler�raising_signal_handler�SigHup�SigTerm)�ErrorIgnoringTextIOWrapper)�ProgressIndicatorPercent)�basic_json_data�
json_print)�replace_placeholders)�ChunkIteratorFileWrapper)�popen_with_error_handling�prepare_subprocess_env)�	dash_open)�umount)�msgpack�msgpack_fallback)�uid2user�	gid2group)�safe_decode)�rst_to_terminal)�ArgparsePatternAction�ArgparseExcludeFileAction�ArgparsePatternFileAction�parse_exclude_pattern)�PatternMatcher)�Item�ArchiveItem)�	get_flags�get_process_id�SyncFile)�RepositoryServer�RemoteRepository�cache_if_remote)�
Repository�LIST_SCAN_LIMIT�TAG_PUT�
TAG_DELETE�
TAG_COMMIT)�selftest)�AtticRepositoryUpgrader�BorgRepositoryUpgrader�zZEXIT_ERROR is not 2, as expected - fix assert AND exception handler right above this line.zN                       Original size      Compressed size    Deduplicated sizezCUsing a pure-python msgpack! This will result in lower performance.cs<t|t�rt�|�St|ttf�r8t�fdd�|D��S|S)zSIf bool is passed, return it. If str is passed, retrieve named attribute from args.c3s|]}t�|�VqdS)N)�getattr)�.0�item)�args�� /usr/lib64/python3.6/archiver.py�	<genexpr>hszargument.<locals>.<genexpr>)�
isinstance�strr{�list�tuple�any)r~Zstr_or_boolr)r~r��argumentcs


r�FTc	
	sz�r4�s�r4�dkrtd��t��tk	rVtd��n"�dk	rLtdt�����rVtj�|����������f	dd�}	|	S)u�
    Method decorator for subcommand-handling methods: do_XYZ(self, args, repository, …)

    If a parameter (where allowed) is a str the attribute named of args is used instead.
    :param fake: (str or bool) use None instead of repository, don't do anything else
    :param create: create repository
    :param lock: lock repository
    :param exclusive: (str or bool) lock repository exclusively (for writing)
    :param manifest: load manifest and key, pass them as keyword arguments
    :param cache: open cache, pass it as keyword argument (implies manifest)
    :param secure: do assert_secure after loading manifest
    :param compatibility: mandatory if not create and (manifest or cache), specifies mandatory feature categories to check
    Nz=with_repository decorator used without compatibility argumentzFwith_repository decorator compatibility argument must be of type tuplezFwith_repository called with compatibility argument but would not checkcs,tj������������	f
dd��}|S)Nc
s�t|d��}|j}t|dd�}t|dd�}t|dd�}t|���ArZ�||fddi|��S|jdkr�t|j��t|��|j||||d�}n"t|j�t|��|j||||d	�}|���s���rt	j
|��\|d
<|d<d|kr�|jj|d_�	�rt
||d
|j���rlt||d|d
t|d
d�t|dd�t|dd�|jt|dt�d��}	�||f||	d�|��SQRXn�||fd|i|��SWdQRXdS)N�lock�append_onlyF�
storage_quota�make_parent_dirs�
repositoryZssh)�create�	exclusive�	lock_waitr�r�r�r~)r�r�r�r�r�r�r��manifest�key�compression�cache_files�ignore_inode�progress�files_cache_mode)�do_filesr�r�r��
cache_mode)r��cache)r{�locationr��protorpZomit_archiver�rr�pathrF�loadr�Z
compressorrrZFILES_CACHE_MODE_DISABLED)
�selfr~�kwargsr�r�r�r�r�r�Zcache_)
�_lockr��
compatibilityr�r��fake�invert_faker��method�securerr��wrapper�s:




 z3with_repository.<locals>.decorator.<locals>.wrapper)�	functools�wraps)r�r�)	r�r�r�r�r�r�r�r�r�)r�r��	decorator�s(!z"with_repository.<locals>.decorator)�AssertionError�typer��reprrF�NO_OPERATION_CHECK)
r�r�r�r�r�r�r�r�r�r�r)	r�r�r�r�r�r�r�r�r�r��with_repositoryls
	#r�cstj���fdd��}|S)Nc
sht||||jjt|dd�t|dd�t|dd�t|dd�|jd�|j|jd�}�||f||||d�|��S)	N�
numeric_ownerF�
nobsdflags�noacls�noxattrsr�)r�r�r�r�r��consider_part_files�log_json)r�r�r��archive)rr�r�r{�getr�r�)r�r~r�r�r�r�r�)r�rr�r��s



zwith_archive.<locals>.wrapper)r�r�)r�r�r)r�r��with_archive�s
r�cCs&t|�}|td�kr"tjd|��|S)N�10Mz3quota is too small (%s). At least 10M are required.)r;�argparseZArgumentTypeError)r�Zparsedrrr��parse_storage_quota�sr�cCs2x$dD]}t||d�}|dk	r|SqWtd��dS)N�func�
fallback_func�fallback2_funcz"expected func attributes not found)r�r�r�)r{�	Exception)r~�namer�rrr��get_func�s

r�c@s*eZdZd�dd�Zdd�Zdd�Zdd	�Zed
d��Zedd
��Z	dd�Z
edddd�dd��Zeddd�dd��Z
eejjfd�dd��Zdd�Zeddddd�dd��Zeddddd�d d!��Zedd"�d#d$��Zd%d&�Zed'dejjfd(�d�d)d*��Zd�d+d,�Zed-d.��Zeejjfd�ed/d0���Zeejjfd�ed1d2���Zd3d4�Zeejjfd�ed5d6���Z eddejjfd7�ed8d9���Z!eddd�d:d;��Z"d<d=�Z#d>d?�Z$d@dA�Z%eejjfd�dBdC��Z&dDdE�Z'eejjfd�dFdG��Z(dHdI�Z)dJdK�Z*edejjfdL�dMdN��Z+dOdP�Z,dQdR�Z-edejj.fdS�dTdU��Z/ed�ddddY�d�dZd[��Z0eddejjfd\�d]d^��Z1eddd_�d`da��Z2eddd�dbdc��Z3ddde�Z4eej5d�dfdg��Z6eej5d�dhdi��Z7eej5d�djdk��Z8edd"�dldm��Z9edd"�dndo��Z:edd"�dpdq��Z;eddd_�drds��Z<eddd_�dtdu��Z=edddej5dv�dwdx��Z>eddd_�dydz��Z?d{d|�Z@eddd}�d~d��ZAeBjC�ZDeEjFd��eDd�<eEjFd��eDd�<eEjFd��eDd�<d�d��ZGd�d��ZHeHZId�d��ZJGd�d��d��ZKd�d��ZLd�d��ZMd�d�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRdS)��ArchiverNcCst|_||_||_dS)N)r$�	exit_coder��prog)r�r�r�rrr��__init__�szArchiver.__init__cGs$|r||p|}t|_tj|�dS)N)r&r��logger�error)r��msgr~rrr��print_error�szArchiver.print_errorcGs$|r||p|}t|_tj|�dS)N)r%r�r��warning)r�r�r~rrr��
print_warning�szArchiver.print_warningcCs^|jrZ|jdks||jkrZ|jrBttjd|t|�d��tjd�nt	j
d�jd|t|��dS)NZfile_status)r��statusr�)�filezborg.output.listz%1s %s)�output_list�
output_filterr��print�json�dumpsr>�sys�stderr�logging�	getLogger�info)r�r�r�rrr��print_file_status�szArchiver.print_file_statusc
Cs�t�}d}}d}}x�||s^t||�}||krJ||oHt||�|kSt|�}t|�}d}||s�t||�}||kr�||o�t||�|kSt|�}t|�}d}t||||�}	||||	�||||	�kr�dS||	7}||	7}qWdS)zSCompare two chunk iterators (like returned by :meth:`.DownloadPipeline.fetch_many`)rFN)�object�next�
memoryview�len�min)
�chunks1�chunks2�endZalenZaiZblenZbi�a�bZslicelenrrr��compare_chunk_contents�s.

 zArchiver.compare_chunk_contentscCst�}|j|�|j|�|S)N)ri�add_inclexclZadd_includepaths)Zinclexcl_patternsZ
include_paths�matcherrrr��
build_matchers

zArchiver.build_matchercCs t|j|j|j|jd�j�tS)z@Start in server mode. This command is usually not used manually.)�restrict_to_paths�restrict_to_repositoriesr�r�)ror�r�r�r��server$)r�r~rrr��do_serveszArchiver.do_serveTF)r�r�r�cCs�|jj�}tjd|�yt||�}Wn ttfk
rF|j�tSXt	||�}||_
|j�|j�t
|||dd��WdQRX|jr�t|�}t|d�j�tjdtj|��|jdkr�tjd�|jS)	zInitialize an empty repositoryzInitializing repository at "%s"F)Zwarn_if_unencryptedN�wa�
By default repositories initialized with this version will produce security
errors if written to with an older version (up to and including Borg 1.0.8).

If you want to use these older versions, you can disable the check by running:
borg upgrade --disable-tam %s

See https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability for details about the security implications.�	plaintexta)
IMPORTANT: you will need both KEY AND PASSPHRASE to access this repo!
If you used a repokey mode, the key is stored in the repo, but you should back it up separately.
Use "borg key export" to export the key, optionally in printable format.
Write down the passphrase. Store both at safe place(s).
)r��canonical_pathr�r�r�EOFError�KeyboardInterrupt�destroyr%rFr��write�commitrr r�open�closer��shlex�quote�NAMEr�)r�r~r�r�r�r��tam_filerrr��do_init s.



zArchiver.do_init)r�r�cCs�|jr"d}t|dddddd�s"tS|jrVt|j|j|j|jdk	|j	f�rV|j
d	�tS|jsr|j|j|j
d
�srtS|jdk	r�|jd|_	|jr�t�j||j|jj|j|j|jp�d|j	|j|j
d
�	r�tStS)zCheck repository consistencyz�This is a potentially dangerous function.
check --repair might lead to data loss (for kinds of corruption it is not
capable of dealing with). BE VERY CAREFUL!

Type 'YES' if you understand this and want to continue: z	Aborting.zInvalid answer, aborting.�YESFZ!BORG_CHECK_I_KNOW_WHAT_I_AM_DOING)�	false_msg�invalid_msg�truish�retry�env_var_overrideNzT--repository-only contradicts --first, --last, --prefix and --verify-data arguments.)�repair�
save_spacer�ts)r�r��first�last�sort_by�glob�verify_datar)r�)r�rNr&�	repo_onlyr�rrr�prefix�
glob_archivesr��
archives_only�checkrr%rr�r�rr$)r�r~r�r�rrr��do_checkGs*

zArchiver.do_check)r�cCsFt|d�std�tS|j�tjd�t|d�rBtjd|j��tS)z%Change repository key file passphrase�change_passphrasez?This repository is not encrypted, cannot change the passphrase.zKey updated�find_keyzKey location: %s)�hasattrr�r&r
r�r�rr$)r�r~r�r�r�rrr��do_change_passphraseds


zArchiver.do_change_passphrasecCstjd�|j|�S)Nzq"borg change-passphrase" is deprecated and will be removed in Borg 1.2.
Use "borg key change-passphrase" instead.)r�r�r)r�r~rrr��do_change_passphrase_deprecatedqs
z(Archiver.do_change_passphrase_deprecated)r�r�r�r�cCstt|�}|j�|jr$|j|j�nLy$|jr:|j|j�n|j|j�Wn&tk
rn|j	dj
|j��tSXtS)z$Export the repository key for backupz$'{}' must be a file, not a directory)
r#Zload_keyblob�paperZexport_paperkeyr��qrZ	export_qr�export�IsADirectoryErrorr��formatr&r$)r�r~r��managerrrr��
do_key_exportvszArchiver.do_key_exportcCs~t|�}|jr.|jr"|jd�tS|j|�nL|jsB|jd�tS|jdkrptjj|j�rp|jd|j�tS|j|�t	S)z%Import the repository key from backupz.with --paper import from file is not supportedz&input file to import key from expected�-zinput file does not exist: )
r#rr�r�r&Zimport_paperkey�os�existsZimport_keyfiler$)r�r~r�rrrr��
do_key_import�s


zArchiver.do_key_import)r�cCsd|jtj�}tj||�}t|�}||_|j|_|j	|_	|j
|_
|j|_|j|_|j
�tjd�tS)zMigrate passphrase -> repokeyzKey updated)r�rF�MANIFEST_IDr"Zdetectr!�target�idZ
repository_idZenc_keyZenc_hmac_keyZid_keyZ
chunk_seedr
r�r�r$)r�r~r�Z
manifest_dataZkey_oldZkey_newrrr��do_migrate_to_repokey�s
zArchiver.do_migrate_to_repokeycs&�fdd�}tdd��}dtjkr,d d!g}nd"d#d$d%d&d'g}x�|D]�\}}}}||j|||��}	||jj�|	�\}
}}}
WdQRX||d}t|�}|r�dnd}d}t|d|||
||||
f�t|d|||||||f�t|d|||||||f�t|d|||
||||
f�qBWdS)(z4Benchmark Create, Read, Update, Delete for archives.c
s�|d}d}tj�}�j�jd|d|d|g��}tj�}||}|dksNt��j�jd||d|g��}�j�jd|dg��}	||	ko�dkns�t�tj�}�j�jd||d	|g��}tj�}||}
�j�jd|d	g��}	||	ko�dkn�st�tj�}�j�jd
d|dg��}tj�}||}|dk�sHt�tj�}�j�jd|dg��}tj�}||}|dk�s�t�||
||fS)Nz::borg-benchmark-crudz--compression=noner�z--files-cache=disabled�1r�2�delete�3�extractz	--dry-run)�time�	monotonic�	do_create�
parse_argsr��	do_delete�
do_extract)
�repor�r�r�Zt_start�rcZt_end�	dt_createZrc1Zrc2�	dt_update�
dt_extract�	dt_delete)r�rr��measurement_run�s6z3Archiver.do_benchmark_crud.<locals>.measurement_runcss�z~tjj|d�}tj|�xZt|�D]N}tjj|d|�}|sFd|ntj|�}t|dd��}|j|�WdQRXq$W|VWdtj	|�XdS)Nzborg-test-datazfile_%d�T)Zbinary)
rr��join�makedirs�range�urandomrnr��shutilZrmtree)r��count�size�random�iZfname�data�fdrrr��
test_files�s

z.Archiver.do_benchmark_crud.<locals>.test_filesZ_BORG_BENCHMARK_CRUD_TEST�Z-TESTrF�R-TESTT�Z-BIG�
���R-BIG�Z-MEDIUM���@B�R-MEDIUM�Z-SMALL�'�R-SMALLNg��.Ar;zall-zeroz-%s-%-10s %9.2f MB/s (%d * %s %s files: %.2fs)�C�R�U�Dr)r@rrF)rArrT)rBrCrDF)rErCrDT)rFrGrHF)rIrGrHT)rJrKrKF)rLrKrKT)rr�environr�r�r�r:r�)r�r~r2r?Ztestsr�r9r:r;r�r.r/r0r1Z
total_size_MBZfile_size_formattedZcontentZfmtr)r�r��do_benchmark_crud�s."
""zArchiver.do_benchmark_crud�dry_run)r�r�r�c
stdd���j�j������fdd�}�j�_�j�_�j�_�j�tj�}t	j
�}tjd�j
j��s�t||��j�j�j�j�j�jd�	�X}t||��j
j|d�j�j�j�j�j�j�j�j�j�j ||�j!d�}	||	|�WdQRXn
|dd��j"S)	zCreate new archiveT)�fallbackc-sbt�}y"tjt��}|j|j|jf�Wntk
r<YnX�jj	s�y$tj�jj
�}|j|j|jf�Wntk
r~YnXtjd��x>�j
D�]2}|dk�r$�j}�j}�j}�j}��sy|j|||||�}Wn6tk
�r}	zd}�jd||	�WYdd}	~	XnXnd}�j||�q�tj
j|�}ytj|dd�}Wn4tk
�rv}	z�jd||	�w�WYdd}	~	XnX�j�r�|j}
nd}
�j||��j�j�j|||
�j�|d�|j|j|jf�q�W��s^|j�j�jd��j �r�|j!j"d	d
��j!�j#O_!�j!�r^�j#�r2t$t%�|d|id��n,t&t't(|�t't)t(|j!�t(|�t't*j+d
�d�dS)NzProcessing files ...r�Ez%s: %sF)�follow_symlinks)�read_specialrS�st)�commentrDT)�finalr�)r��extrazborg.output.stats)r�),�setr�statrE�add�st_ino�st_dev�OSErrorr��hostr�r��debug�paths�
stdin_name�
stdin_mode�
stdin_user�stdin_groupZ
process_stdinrr�r��normpath�one_file_system�_process�exclude_caches�exclude_if_present�keep_exclude_tagsrW�saverYrDr��statsZ
show_progressr�rXrWrP�DASHESr��STATS_HEADERr�r�)r�r��skip_inodesrXr��mode�user�groupr��e�restrict_dev)r~rSr�r�r�rr��create_innersr

"
z(Archiver.do_create.<locals>.create_innerzCreating archive at "%s")r�r�r�Zpermit_adhoc_cacher�r�)r�r��checkpoint_intervalr��noatime�noctime�nobirthtimer�r�r�r��chunker_params�startZstart_monotonicr�N)#rir��patternsr�r��exclude_nodumprSrZutcnowr&r'r�r�r�Z	processedrr�r�r��
no_cache_syncr�r�rr�rzr�r{r|r}r�r�r�r~r�r�)
r�r~r�r�r�ryZt0Zt0_monotonicr�r�r)r~rSr�r�r�r�r(�s.
C

zArchiver.do_createc
)Cs��y�d}
|j|�r>|dkr�td��tj|dd�}WdQRXnT|jd|�|jsTdS|dkr~td��tj|dd�}WdQRXtj|j�}
|
s�dS|j|j	f|kr�dS|	dkp�|j	|	k}d}|j
r�td��&t||�tj@r�|jd|�dSWdQRXtj
|j��r|�s�|j|||�}�nvtj|j��r|�r�t|||�}|�r�|
�s�|�r�|�s`|j||�x.|D]&}|j|||||||||	|
|d��qfW|jd|�dS|�s�|
�s�|j||�}|�r�td��tj|�}WdQRXx<|D]4}tjj|j�}|j|||||||||	|
|d��q�W�nttj|j��r�|�s�|
�sF|j||�}nVytj|�}Wntk
�rnd}YnXt|j�}|�r�|j|||�}n|j||�}�n�tj|j��r�|�s�|
�s�|j||�}n|j|||�}n�tj|j��r|�s�|
�s|j||d	�}n|j|||�}n�tj|j��rL|�s�|
�s<|j||d
�}n|j|||�}nFtj|j��r^dStj |j��rpdStj!|j��r�dS|j"d|�dSWn6t#k
�r�}z|j"d||�d
}WYdd}~XnX|dk�r�|�s�d}nd}|
�s�|j||�dS)z�
        Process *path* recursively according to the various parameters.

        *st* (if given) is a *os.stat_result* object for *path*.

        This should only raise on critical errors. Per-item errors must be handled within this method.
        FNr])rV�x�flags)rWrS�scandir�cr�zUnknown file type: %sz%s: %srU�?r)$�matchrrr]r�Zrecurse_dir�S_ISDIR�st_moder_r`r�rl�	UF_NODUMP�S_ISREG�process_filerKZprocess_dirrkrZscandir_inorderr�ri�S_ISLNKZprocess_symlinkrar�S_ISFIFOZprocess_fifo�S_ISCHRZprocess_dev�S_ISBLK�S_ISSOCK�S_ISDOOR�S_ISPORTr�r)r�r�r�r�rlrmrnrsr�rxrWrSrXZrecurse_excluded_dirZrecurser�Z	tag_pathsZtag_pathZentriesZdirentriZ	st_targetZspecialrwrrr�rkYs�










zArchiver._processcs(�r���fdd�}n��fdd�}|S)Ncs8�j|j�o(tjj|jjtj��d��}�||�|S)N)r�r�r�sepr4�split)r}�matched)r��peek_and_store_hardlink_masters�strip_componentsrr��item_filter�s*
z*Archiver.build_filter.<locals>.item_filtercs�j|j�}�||�|S)N)r�r�)r}r�)r�r�rr�r��s
r)r�r�r�r�r)r�r�r�r��build_filter�szArchiver.build_filtercs0tj�dkr,tjd�tjjd!�r,tjd�|j|j|j�}|j	}|j
}|j}	|j}
|j
}|j}g}
|j�pp|��s|tr�ind	���fd
d�}|j|||�}|r�tdd
dd�}|jd�t�fdd�|j|�D��}||_nd	}�x�|j|�d�d�D�]h}|j}|�r*tjj|jtj�|d	��|_|j�s�xx|
�r�|jj|
d"j��r�|
jd#�}y|j||
d�Wn8tk
�r�}z|jdt |j�|�WYd	d	}~XnX�q4W|�r�t!j"d�j#t |j��y^|	�r�|j|d|d�nBt$j%|j&��r|
j'|�|j||
dd�n|j||
|�|||d�Wn:tt(fk
�r`}z|jdt |�|�WYd	d	}~XnX�q�W|�rv|j)�|j�s�tt*|
�ddd�}xj|
�r�|j+�|
jd$�}y|j||
d�Wn8tk
�r�}z|jdt |j�|�WYd	d	}~XnX�q�Wx|j,�D]}|jd |��qW|�r*|j)�|j-S)%zExtract archive contents�asciiz_Warning: File system encoding is "ascii", extracting non-ascii filenames will not be supported.�linux�freebsd�netbsd�openbsd�darwinz^Hint: You likely need to fix your locale setup. E.g. install locales and use: LANG=en_US.UTF-8NcsJts�rF|rFt|j�rF|jdd�rFd|krF|jd�df�|jd�<dS)N�hardlink_masterT�source�chunksr�)rrGrtr�)r}r�)�hardlink_masters�partial_extractrr�r�s	z<Archiver.do_extract.<locals>.peek_and_store_hardlink_mastersz%5.1f%% Extracting: %sg�������?r%)r��step�msgidz^Calculating total archive size for the progress indicator (might take long for large archives)c3s|]}|j��VqdS)N)�get_size)r|r})r�rr�r�sz&Archiver.do_extract.<locals>.<genexpr>T)r��preloadr�r)�stdoutz%s: %szborg.output.list)rS�piF)r�Z
restore_attrs)r��sparser�Zstripped_components�
original_pathr�z%Setting directory permissions %3.0f%%zextract.permissions)�totalr�r�z#Include pattern '%s' never matched.)r�r�r�r�r����r�r�).r��getfilesystemencodingr�r��platform�
startswithr�r�rdr�r�rSr�r�r��emptyrr�rV�output�sum�
iter_itemsr�r�rr�r4r��pop�extract_itemrr�r>r�r�r�r]r�rt�appendr�finishr��show�get_unmatched_include_patternsr�)r�r~r�r�r�r�r�r�r�rSr�r�r��dirsr��filterr��extracted_sizer}�	orig_pathZdir_itemrw�patternr)r�r�r�r+�s~




,
*

,zArchiver.do_extractcCs6|j|_d}|jdkrX|jjd�r(d}n"|jjd�r:d}n|jjd�rJd}tjd	|�n|j}t|jd
�}|jdk}|r�|}	|}
tdd
�}t|t	j
|	d|d�}|s�tS|j}d}tj
|dtjd�}
|j|||
�|
j�|r�|j�|�r0tjd�|j�}|�rtjd|�t|_ntjd|�|
�r0|	j�|jS)z$Export archive contents as a tarballN�autoz.tar.gzZgzipz.tar.bz2Zbzip2z.tar.xzZxzz'Automatically determined tar filter: %s�wbrT)�systemz--tar-filter: )�stdinr�Z
log_prefix�envzw|)Zfileobjrtrz/Done creating tar, waiting for filter to die...zA--tar-filter exited with code %d, output file is likely unusable!zfilter exited with code %d)r��
tar_filter�tarfile�endswithr�rcr]r\r[�
subprocess�PIPEr&r�r�Z
GNU_FORMAT�_export_tarr��waitr�r�)r�r~r�r�r�r�r�Z	tarstreamZtarstream_closeZ	filteroutZfilterout_closer�Z
filterproc�tarr-rrr��
do_export_tarFsL





zArchiver.do_export_tarcsl�j|j|j�}|j}|j}|j�|j�p.���r8ind���fdd�}�j||��}|r�tdddd���j	d�t
�fdd	��j|�D��}	|	�_nd���fd
d������fdd
�}
xz�j|�d�d�D]d}|j
}�r�tjj|jtj��d��|_
|
||�\}
}|
r�|�r(tjd�jt|��|j|
|�q�W��rF�j�x|j�D]}�jd|��qPW�jS)NcsD�r@|r@t|j�r@|jdd�r@d|kr@|jd�df�|jd�<dS)Nr�Tr�r�r�)rGrtr�)r}r�)r�r�rr�r��sz=Archiver._export_tar.<locals>.peek_and_store_hardlink_mastersz%5.1f%% Processing: %sg�������?r%)r�r�r�zCalculating sizec3s|]}|j��VqdS)N)r�)r|r})r�rr�r��sz'Archiver._export_tar.<locals>.<genexpr>csL�jjdd�|jD�dd�}�r@t|j�g�t|��fdd��St|�SdS)zY
            Return a file-like object that reads from the chunks of *item*.
            cSsg|]\}}}|�qSrr)r|Zchunk_id�_rrr��
<listcomp>�szEArchiver._export_tar.<locals>.item_content_stream.<locals>.<listcomp>T)Zis_preloadedcs�jt|��d�S)N)Zincreaser�)r�r�)Z
read_bytes)r�r�rr��<lambda>�szCArchiver._export_tar.<locals>.item_content_stream.<locals>.<lambda>N)�pipeline�
fetch_manyr�r>r�rZ)r}Zchunk_iterator)r�r�)r�r��item_content_stream�sz1Archiver._export_tar.<locals>.item_content_streamcsd}tj�}|j|_|jd|_tj|j�|_|j|_|j	|_	|j
pFd|_|jpRd|_
d|_tj|j�}|tjk�r.tj|_d|k�rtjj|jjtj��d��}�dkr�|}n�j|jd|f�\}}|r�tj|_||_n<|dk	�r,||_|j�|_�|�}d|jf�|jd��p|<n|j�|_�|�}n�|tjk�rDtj|_n�|tjk�rbtj |_|j|_n�|tj!k�r�tj"|_tj#|j$�|_%tj&|j$�|_'nl|tj(k�r�tj)|_tj#|j$�|_%tj&|j$�|_'n:|tj*k�r�tj+|_n$�j,dt-|j�|�t.t/�d|fS||fS)ad
            Transform a Borg *item* into a tarfile.TarInfo object.

            Return a tuple (tarinfo, stream), where stream may be a file-like object that represents
            the file contents, if any, and is None otherwise. When *tarinfo* is None, the *item*
            cannot be represented as a TarInfo object and should be skipped.
            Nge��A�r�z+%s: unsupported file type %o for tar export)0r�ZTarInfor�r��mtimer]�S_IMODErt�uid�gidru�unamervZgname�linkname�S_IFMT�S_IFREGZREGTYPEr�rr�r4r�r�r�ZLNKTYPEr�r�r:�S_IFDIRZDIRTYPE�S_IFLNKZSYMTYPE�S_IFBLKZBLKTYPE�majorZrdevZdevmajor�minorZdevminor�S_IFCHRZCHRTYPE�S_IFIFOZFIFOTYPEr�r>r*r%)r}r��stream�tarinfoZmodebitsr�r�r�)r�r�r�r�rr��item_to_tarinfo�s^







z-Archiver._export_tar.<locals>.item_to_tarinfoT)r�r�r�zborg.output.listz#Include pattern '%s' never matched.)r�r�rdr�r�r�r�r�rVr�r�r�r�r�rr�r4r�r�r�r�r>Zaddfiler�r�r�r�)r�r~r�r�r�r�r�r�r�r�r�r}r�r�r�r�r)r�r�r�r�r�r�r�r�r��s>

L
zArchiver._export_tarc	sT�fdd��d&dd���fdd��
dd	��d
d��dd
��	�	fdd�������fdd��
��
�fdd���
fdd���fdd��d'������	����f
dd�	�dd��dd������fdd �}|�t|||�j�jd!���jjd"d��jjd"d#�k�p�j���s�jd$��j�j�j	�}|��|�x|j
�D]}�jd%|��q8W�jS)(zDiff contents of two archivescs$|jj|�}|jj|�}�j||�S)N)r�r�r�)�
chunk_ids1�
chunk_ids2�archive1�archive2r�r�)r�rr��fetch_and_compare_chunks!sz2Archiver.do_diff.<locals>.fetch_and_compare_chunksNcs>|jd�rd}n*�dk	r2t�fdd�|jD��}n|j�}|S)N�deletedc3s|]}|j�kr|jVqdS)N)rr:)r|�chunk)�consider_idsrr�r�+sz;Archiver.do_diff.<locals>.sum_chunk_size.<locals>.<genexpr>)r�r�r�r�)r}r�r:r)r�r��sum_chunk_size&s
z(Archiver.do_diff.<locals>.sum_chunk_sizecs"�jr|j|jfS|j|jfSdS)N)r�r�r�rurv)r})r~rr��	get_owner0sz#Archiver.do_diff.<locals>.get_ownercSsd|krtj|j�SdgSdS)Nrt)r]�filemodert)r}rrr��get_mode6sz"Archiver.do_diff.<locals>.get_modecSst|j�o|jd�|kS)Nr�)rGrtr�)r}r�rrr��has_hardlink_master<sz-Archiver.do_diff.<locals>.has_hardlink_mastercSsX|jd�r*|jd�r*d|}d|i|fS|jd�rT|jd�rTd|}d|i|fSdS)Nr�zremoved r�zadded )r�)�item1�item2Z	item_typeZchgrrr��compare_presence?sz*Archiver.do_diff.<locals>.compare_presencecsD�||d�}|dk	r|Sd|kr@d|kr@|j|jkr@ddidfSdS)N�linkr�r�zchanged link)r�)r�r�Zpd)r�rr��compare_linkGs
z&Archiver.do_diff.<locals>.compare_linkcsp|jd�|jd�krdS�r(|j|jkS�|��|�kr<dSdd�|jD�}dd�|jD�}�||���SdS)Nr�TcSsg|]
}|j�qSr)r)r|r�rrr�r�\sz>Archiver.do_diff.<locals>.contents_changed.<locals>.<listcomp>cSsg|]
}|j�qSr)r)r|r�rrr�r�]s)r�r�)r�r�r�r�)r�r��can_compare_chunk_idsr�r�rr��contents_changedQsz*Archiver.do_diff.<locals>.contents_changedc
s��||�r�|jd�r4�|�}d|d�djt|��fS|jd�r^�|�}d|d�djt|��fS�snddidfSd	d
�|jD�}dd
�|jD�}||}||}�||�}�||�}	d||	d�d
jt|ddd�t|	ddd��fSdS)Nr��added)r�r:zadded {:>13}�removedzremoved {:>11}r��modifiedcSsh|]
}|j�qSr)r)r|r�rrr��	<setcomp>jsz<Archiver.do_diff.<locals>.compare_content.<locals>.<setcomp>cSsh|]
}|j�qSr)r)r|r�rrr�rks)r�r�r�z{:>9} {:>9}rT)Z	precisionZsign)r�rr:r�)
r�r�r�Zszr�r�Z	added_idsZremoved_idsr�r�)r�r�r�rr��compare_content`s$





z)Archiver.do_diff.<locals>.compare_contentcsL�|�\}}�|�\}}||ks(||krHd||||d�dj||||�fSdS)N�owner)r�Zold_userZ	old_groupZnew_userZ	new_groupz[{}:{} -> {}:{}])r)r�r�Zuser1Zgroup1Zuser2Zgroup2)r�rr��
compare_ownerts
z'Archiver.do_diff.<locals>.compare_ownercs8|j|jkr4�|�}�|�}d||d�dj||�fSdS)Nrt)r�Zold_modeZnew_modez
[{} -> {}])rtr)r�r�Zmode1Zmode2)r�rr��compare_mode{sz&Archiver.do_diff.<locals>.compare_modeFcs�g}�||�r||jd}�||�r4||jd}�|�ddksT�|�ddkrd|j�||��d|kr�d|kr�|j�|||���|�ddks��|�ddkr�|j�||d���|�ddks؈|�ddkr�|j�||d���|�dd	k�s�|�dd	k�r |j�||d
���|�ddk�sD�|�ddk�rV|j�||d��|�s||j�||��|j�||��d
d�|D�}|�r�t|�|f}�j�r�|j|�n�j�rˆ|�n�	|�dS)z�
            Compare two items with identical paths.
            :param deleted: Whether one of the items has been deleted
            rr�lr��dZ	directoryr�Zblkdevr�Zchrdev�sZfifocSsg|]}|r|�qSrr)r|r�rrr�r��sz;Archiver.do_diff.<locals>.compare_items.<locals>.<listcomp>N)r�r�r>�sort�
json_lines)r�r�r�r�r�r��changesZoutput_line)
r~rr�rrr�r�r��print_json_output�print_text_outputrr��
compare_items�s8

   $$
z'Archiver.do_diff.<locals>.compare_itemscSs,|\}}tdjdjdd�|D��|��dS)Nz	{:<19} {}� cSsg|]\}}|�qSrr)r|�j�txtrrr�r��sz?Archiver.do_diff.<locals>.print_text_output.<locals>.<listcomp>)r�rr4)�liner��diffrrr�r
�sz+Archiver.do_diff.<locals>.print_text_outputcSs*|\}}ttj|dd�|D�d���dS)NcSsg|]\}}|�qSrr)r|rrrrr�r��sz?Archiver.do_diff.<locals>.print_json_output.<locals>.<listcomp>)r�r)r�r�r�)rr�rrrr�r�sz+Archiver.do_diff.<locals>.print_json_outputc	s��fdd��dd����fdd��������fdd�}tj�}tj�}g�i�g�x�t|j�fd	d
��|j�fdd
���D]�\}}|r�|r�|j|jkr�|||�q||r�|j|jd�}|r�|||�n
|||j<|r||j|jd�}|r�|||�q||||j<q|Wtdgd
d�}	x<|j�D]0}
|
j}||	_�|	|
���||	|
�dd��qWx<|j�D]0}|j}||	_�||	���|||	�dd��qVWx@�D]8\}}�|��s�t��|��s�t���|j||���q�W�j	�r؈	n�
}
xt
��D]}|
|��q�WdS)Ncsd|kpt|j�p|j�kS)Nr�)rGrtr�)r})r�rr��hardlink_master_seen�szHArchiver.do_diff.<locals>.compare_archives.<locals>.hardlink_master_seencSs|jdd�od|kot|j�S)Nr�Tr�)r�rGrt)r}rrr��is_hardlink_master�szFArchiver.do_diff.<locals>.compare_archives.<locals>.is_hardlink_mastercs"�|�s�|�r||f�|j<dS)N)r�)r�r�)r�rrr��update_hardlink_masters�szKArchiver.do_diff.<locals>.compare_archives.<locals>.update_hardlink_masterscsD�||��|�s�|�r.�j||f�n��|j||��dS)N)r�r�)r�r�)r�deferredrr�r�rrr��compare_or_defer�s
zDArchiver.do_diff.<locals>.compare_archives.<locals>.compare_or_defercs�j|j�S)N)r�r�)r})r�rr�r��sz<Archiver.do_diff.<locals>.compare_archives.<locals>.<lambda>cs�j|j�S)N)r�r�)r})r�rr�r��sTr)r�r�rt)r�)�collections�OrderedDictrr�r�r�rj�valuesr�r
�sorted)r�r�r�rZorphans_archive1Zorphans_archive2r�r�Zmatching_orphanZdeleted_itemr�r�r�Zprint_outputr)r~rrr
)rrr�rr�r�rr��compare_archives�s\



z*Archiver.do_diff.<locals>.compare_archives)r�r~Tz�--chunker-params might be different between archives, diff will be slow.
If you know for certain that they are the same, pass --same-chunker-params to override this check.z#Include pattern '%s' never matched.)N)F)rr�r��metadatar��same_chunker_paramsr�r�r�rdr�r�)	r�r~r�r�r�r�rr�r�r)r�r�r~r�rrr�rrr�r�r�r�r�r�rr
r�r�r��do_diffs6


 0G

zArchiver.do_diff)r�r�r�cCs*|j|j�|j�|j�|j�|jS)zRename an existing archive)�renamer�r�r�r�)r�r~r�r�r�r�r�rrr��	do_renames
zArchiver.do_renamecCsft|j|j|jdk	|jf�}|jjp(|j}|rB|rB|jd�|j	S|sJ|rV|j
||�S|j||�SdS)z)Delete an existing repository or archivesNzFMixing archive filters and explicitly named archives is not supported.)r�rrrr	r�r��archivesr�r��_delete_archives�_delete_repository)r�r~r�Zarchive_filter_specifiedZexplicit_archives_specifiedrrr�r*s
zArchiver.do_deletecCs�|j}tj|tjjf�\}}|jjs*|jrVt|j�}|jjrL|j	d|jj�t
|�}n$t
dd�|jj|�D��}|sz|jS|j
dk�rVd}x�t|d�D]x\}	}
y|jj|
�}Wn2tk
r�t|_tjdj|
|	t|���Yq�Xd}|r�d	nd
}tj|jt|�|	t|���q�W|�r$tjd�n,|�rF|j�|j�tjd�n
tjd
�|jSt�}
t||||j|jd���"}|�r�dnd}d}d}x�t|d�D]�\}	}
y|j|
}Wn.tk
�r�tj|j|
|	t|���YnVXtj|jt|�|	t|���|�s�t||||
||jd�}|j |
|j|j
d�|d7}�q�W|dk�r`|j�|j|j!d�|j�|j"�r�t#t$t%|
j&jd|
d�t'|�t$t(j)d�d�WdQRX|jS)zDelete archivesrcss|]}|jVqdS)N)r�)r|r�rrr�r�7sz,Archiver._delete_archives.<locals>.<genexpr>rzFrzArchive {} not found ({}/{}).TzWould delete: {} ({}/{})zDeleted archive: {} ({}/{})zFinished dry-run.z5Done. Run "borg check --repair" to clean up the mess.zAborted.)r�r�z Would delete archive: {} ({}/{})zDeleting archive: {} ({}/{}))r�r�)r��forced)rz
Deleted data:)�labelrpzborg.output.stats)r�N)*rSrFr��	Operation�DELETEr�r�r#r��insertr��list_consideringr�r&�	enumerater��KeyErrorr%r�r�rr�r�r<r�r�rrr�r�rr�r#rrprPrqrr�summaryr�r�r�)r�r~r�rSr�r�r#�
archive_namesr�r<�archive_nameZcurrent_archiver�rpr�Z
msg_deleteZ
msg_not_foundZdelete_count�archive_infor�rrr�r$+sp

 


zArchiver._delete_archivescCs�|j}|j�s�|jdk�rXt|j�}|jj�}g}y0tj|tj	�\}}t
|j�}	|jdj
|	��Wn"tk
r�d}	|jd�YnX|jt�|jdj
|��|jdj
|��|jd�|jd�|	dk	�r|	dk�rx2|jjd	gd
�D]}
|jt|
��q�Wn
|jd�n
|jd�|jt�|jd
�dj|�}t|dddddd��sXt|_|jS|�s||j�tjd�tj|�n
tjd�|�s�tj|�tjd�n
tjd�|jS)zDelete a repositoryrz`You requested to completely DELETE the following repository *including* {} archives it contains:NzdYou requested to completely DELETE the following repository *including* all archives it may contain:zRepository ID: {}zLocation: {}r�z	Archives:r)rz/This repository seems to not have any archives.zXThis repository seems to have no manifest, so we can't tell anything about its contents.z8Type 'YES' if you understand this and want to continue: �
z	Aborting.zInvalid answer, aborting.r�FZ"BORG_DELETE_I_KNOW_WHAT_I_AM_DOING)r�r�r�r�r�zRepository deleted.zWould delete repository.zCache deleted.zWould delete cache.)r�)rS�
cache_onlyr&r?r�	_locationr�rFr�r�r�r#r�rr)rqr�r<r4rNr&r�r�r�r�rr)r�r~r�rSrr�r�r�r�Z
n_archivesr1rrr�r%qsT
















zArchiver._delete_repositorycCs�yddl}Wn4tk
r@}z|jdt|��|jSd}~XnXtjj|j�sptj	|jtj
tjBtjB�r�|jd|j�|jS|j
|�S)z:Mount archive or an entire repository as a FUSE filesystemrNzGborg mount not available: loading FUSE support failed [ImportError: %s]z+%s: Mountpoint must be a writable directory)Z	borg.fuse�ImportErrorr�r�r�rr��isdir�
mountpoint�access�R_OK�W_OK�X_OK�	_do_mount)r�r~�borgrwrrr��do_mount�s.zArchiver.do_mountcCsxddlm}t||d��T}||||||�}tjd�y|j|j|j|j�Wnt	k
rft
|_YnXWdQRX|jS)Nr)�FuseOperations)Zdecrypted_cachezMounting filesystem)Zfuser?rqr�r��mountr7�options�
foreground�RuntimeErrorr&r�)r�r~r�r�r�r?Zcached_repoZ
operationsrrr�r<�s
zArchiver._do_mountcCs
t|j�S)zun-mount the FUSE filesystem)r^r7)r�r~rrr��	do_umount�szArchiver.do_umountcCsX|jjr.|jr|jd�|jS|j||||�S|jrD|jd�|jS|j||||�SdS)z#List archive or repository contentszKThe --json option is only valid for listing archives, not archive contents.zQThe --json-lines option is only valid for listing archive contents, not archives.N)r�r�r�r�r��
_list_archiver
�_list_repository)r�r~r�r�r�rrr��do_list�s

zArchiver.do_listc	s�|j�j�j���jdk	r"�j�n�jr.d�nd�������fdd�}tj��rzt���|jd��}||�WdQRXn
|dd�|j	S)Nz
{path}{NL}z<{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}cs\t����jj|�jd�}t|��jd�}x,|j�fdd��D]}tjj	|j
|��q>WdS)N)r�r�)r
cs�j|j�S)N)r�r�)r})r�rr�r��sz=Archiver._list_archive.<locals>._list_inner.<locals>.<lambda>)rr�r�r�r7r
r�r�r�r��format_item)r�r��	formatterr})r~rr�r�r�r�rr��_list_inner�s

z+Archiver._list_archive.<locals>._list_inner)r�)r�)
r�r�rdr�shortr7Zformat_needs_cacherr�r�)r�r~r�r�r�rJr�r)r~rr�r�r�r�r�rE�s
	

zArchiver._list_archivec	Cs�|jdk	r|j}n|jrd}nd}t|||||jd�}g}x>|jj|�D].}|jrd|j|j|��qHtj	j
|j|��qHW|jr�tt
|d|id��|jS)Nz
{archive}{NL}z{archive:<36} {time} [{id}]{NL})r�r#)r[)rrKr8r�r#r+r�Z
get_item_datar�r�r�rHrXrWr�)	r�r~r�r�r�rrI�output_datar1rrr�rF�s
zArchiver._list_repository)r�r�cCsJt|jj|j|j|jdk	|jf�r4|j|||||�S|j|||||�SdS)z,Show archive details such as disk space usedN)	r�r�r�rrrr	�_info_archives�_info_repository)r�r~r�r�r�r�rrr��do_infos"zArchiver.do_infoc
	Csdd�}|jjr|jjf}ntdd�|jj|�D��}g}x�t|d�D]�\}	}
t||||
||jd�}|j�}|j	r~|j
|�nHtt|dd��|d<||d	�|d	<t
tjd
�j�jfd|i|���|jr�P|j	rFt|�|	rFt
�qFW|j	�r
tt||d|id
��|jS)NcSstdjdd�|D���S)Nrcss|]}tj|�VqdS)N)r�r�)r|r�rrr�r�szBArchiver._info_archives.<locals>.format_cmdline.<locals>.<genexpr>)r>r4)�cmdlinerrr��format_cmdlinesz/Archiver._info_archives.<locals>.format_cmdlinecss|]}|jVqdS)N)r�)r|r�rrr�r�sz*Archiver._info_archives.<locals>.<genexpr>r)r�r�Zduration)ZsecondsZcommand_lineaF
                Archive name: {name}
                Archive fingerprint: {id}
                Comment: {comment}
                Hostname: {hostname}
                Username: {username}
                Time (start): {start}
                Time (end): {end}
                Duration: {duration}
                Number of files: {stats[nfiles]}
                Command line: {command_line}
                Utilization of maximum supported archive size: {limits[max_archive_size]:.0%}
                ------------------------------------------------------------------------------
                                       Original size      Compressed size    Deduplicated size
                This archive:   {stats[original_size]:>20s} {stats[compressed_size]:>20s} {stats[deduplicated_size]:>20s}
                {cache}
                r�r#)r�r[)r�r�r�r#r+r,rr�r�r�r�r9rr��textwrap�dedent�striprr�r�rXrW)
r�r~r�r�r�r�rQr/rLr<r0r�r�rrr�rMs.

zArchiver._info_archivescCs�t||d|jjid�}|jr&t|�n�d}|jd
kr>|d7}n|d|j7}|jjd�rh|d	|j�7}||d
<tt	j
d�j�jft
|j�|jj�d�|���tt�tt�tt|��|jS)NZsecurity_dir)r�r[zEncrypted: r��
authenticatedZNozYes (%s)zkey filez
Key file: %s�
encryptionz�
            Repository ID: {id}
            Location: {location}
            {encryption}
            Cache: {cache.path}
            Security dir: {security_dir}
            )rr�)r�rU)rWZsecurity_manager�dirr�rXr�r�rr�rRrSrTrr?rr4r�rqrrr�r�)r�r~r�r�r�r�r�rVrrr�rNCs(



zArchiver._info_repository)r�r�cs:t|j|j|j|j|j|j|j|jf�s8|j	d�|j
S|jdk	rN|jd|_d}|j
j|jd|dgdd�}tjd	|�j��fd
d�|D��|r��r�|d�dkr��dd
�}ng}t����fdd�|D�}g}	|jr�|	t||j�7}	|j�r
|	t|d|j|	�7}	|j�r&|	t|d|j|	�7}	|j�rB|	t|d|j|	�7}	|j�r^|	t|d|j|	�7}	|j�rz|	t|d|j|	�7}	|j�r�|	t|d|j|	�7}	|j�r�|	t|d|j|	�7}	t|��Bt|	�t|�B}
t�}t||||jd���F}tjd�}
|j�rt|
�}d}tt|
�ddd�}x�|D]�}||
k�r�|j�|j�rZ|j�r�|
jdt |��nF|j�r�|d
7}|
jdt |�||f�t!||||j"|�j#||j$d�n|j�r |
jdt |���q W|j%�|
�r�|j�r�|j&�|j'|j(d�|j'�|j)�r*t*t+t,|j-j.d |d!�t/|�t+tjd"�d#�WdQRX|j
S)$z6Prune repository archives according to specified rulesz�At least one of the "keep-within", "keep-last", "keep-secondly", "keep-minutely", "keep-hourly", "keep-daily", "keep-weekly", "keep-monthly" or "keep-yearly" settings must be specified.Nrz\.checkpoint(\.\d+)?z(%s)?\ZrT)rZ	match_endr�reversez(%s)\Zcsg|]}�|j�r|�qSr)r�)r|�arch)�
is_checkpointrr�r�ssz%Archiver.do_prune.<locals>.<listcomp>rrcsg|]}|�kr|�qSrr)r|rY)�checkpointsrr�r�|sz%Y-%m-%d %H:%M:%Sz%Y-%m-%d %H:%Mz%Y-%m-%d %Hz%Y-%m-%dz%G-%Vz%Y-%mz%Y)r�zborg.output.listzPruning archives %3.0f%%�prune)r�r�r�zWould prune:     %szPruning archive: %s (%d/%d))r&zKeeping archive: %s)rz
Deleted data:)r'rpzborg.output.stats)r�)0r��secondly�minutely�hourly�daily�weekly�monthly�yearly�withinr�r�rr	r#r��re�compile�searchr\rBrCrrr�r�r�r�r�rVr�rSr�r<rr�r#r&r�r�r�rrprPrqrrr.rr�)r�r~r�r�r�Z
checkpoint_reZarchives_checkpointsZkeep_checkpointsr#ZkeepZ	to_deleterpr�Zlist_loggerZ
to_delete_lenZarchives_deletedr�r�r)r[rZr��do_prunecs�





 zArchiver.do_prune�tam�disable_tam�archives_tam)r�r�r�r�cCs�|j�r>tj|tjjf|jd�\}}t|||���}t�}x�|jj	dgd�D]�}|j
}t|�}	|j|�}
|j
||
�}|j|dd�\}}
}|
�st|d�}dd�|jD�|_|j|j�dd	�}|j|�}|j|||�|j||�||jf|j|j<td
|	t|�f�qLtd|	�qLW|j�|j�|j�WdQRX�nR|j�r>tj|tjjf|jd�\}}|j�s~|jjd
d��r�td�x&|jj	dgd�D]}tt|���q�Wd|jd
<|j�|j�|j�rt |d��rd|_|j!|j"�td�t |d��rtd|j#��t|��s�t$|�}t%|d�j&�td��nR|j'�r�tj|tj(dd�\}}t|��rtt)j*t$|��|j�r�t |d��r�d|_|j!|j"�td�t |d��r�td|j#��d|jd
<|j�|j�n�t+|j,j-dd�}y|j.|j/|j0|j1d�Wn0t2k
�r2}ztd|�WYdd}~XnXt3|j,j-dd�}y|j.|j/|j0|j1d�Wn0t2k
�r�}ztd|�WYdd}~XnX|j4S)z,upgrade a repository from a previous version)Zforce_tam_not_requiredr)rT)Z
internal_dictcSsg|]}t|��qSr)rc)r|�argrrr�r��sz'Archiver.do_upgrade.<locals>.<listcomp>sarchive)�contextzAdded archive TAM:   %s -> [%s]zArchive TAM present: %sNstam_requiredFzManifest contents:r
zKey updatedrz
Key location:r�zUpdated security database)r�)�inplacer�zwarning: %s)5rkrFr�r(�CHECK�forcerrr#r�rr<r��decryptZunpack_and_verify_archiverkrPZpack_and_authenticate_metadataZas_dictZid_hashZ	add_chunkZchunk_decrefrr�r�r?r�r�riZtam_verified�configr rr
Z_passphraserrr�r�rjr�r�unlinkrxr�r��upgraderSrnr��NotImplementedErrorryr�)r�r~r�r�r�r�rpr�Z
archive_idZarchive_formatted�cdatar=r�Zverifiedr�Znew_archive_idr1r�r,rwrrr��
do_upgrade�s�







zArchiver.do_upgrade)r�r�r�cCsR|j|j|j�}|j|_|j|_|jdk}|jdk}t||||||j|j|j	|j
|j|||j|j
|j|j|j|jd�}	|jjr�|jj}
|	j|
�r�|jd|
�|jS|	j|
|j|j�s�|jd�nl|jdk	r�|jd�|jSxP|jjdgd	�D]<}|j}
|	j|
��rq�td
|
�|	j|
|j�s�tjd|
�q�W|j�sL|j �|j!�|j!�|jS)zRe-create archives�never�always)
rlrmrnr~r��
recompress�always_recompressr�rpZfile_status_printerrzrSrDz;Refusing to work on temporary archive of prior recreate: %sz~Nothing to do. Archive was not processed.
Specify at least one pattern, PATH, --comment, re-compression or re-chunking option.Nz(--target: Need to specify single archiver)rZ
Processingz=Skipped archive %s: Nothing to do. Archive was not processed.)"r�r�rdr�r�rzrrlrmrnr~r�r�rpr�rzrSrDr�r�Zis_temporary_archiver�r��recreaterYrr#r�r�r�r�r�r�r�)r�r~r�r�r�r�r�rzr{Z	recreaterr�r�rrr��do_recreate�sF





zArchiver.do_recreate)r�r�c
Cs`|jtj�}|jtj|�t|d�r.|jj�tdd�}ztj	|j
g|j|d�S|j�XdS)z:run a user specified command with the repository lock held�ioT)r�)r�N)
r�rFr�putrr~Z
close_segmentr\r�Zcall�commandr~r�)r�r~r�r=r�rrr��do_with_lock)s



zArchiver.do_with_lockcsddd�}ddd�}�fdd�}|js~|jdkr@|jd	�|jSy|jjd
�\}}Wn(tk
r||jrndppd}|j}YnX|jr�tj�tj	j
f�\}}	t�||j�t
�|	||jd
�}
�z.|jr�|
jj�|
jj}|
jj}|}
n�j}�fdd�}|}
|j�rB|
||dd�|j||�t|j|��dk�r:|j|�|�n�|j�rT||�n�|j�r�|
|||j�||j�k�r�|j|�|j|||j�|�nNyt|j||��Wn8tjtjfk
�r�}zt|t j!d�t"Sd}~XnXt#S|j�r�|
j$�XdS)z@get, set, and delete values in a repository or cache config fileNTcSs<|dkrtd��|dkrJ|rHyt|�Wntk
rFtd�d�YnXn�|dkr�|r�yt|�Wntk
r�td�d�YnX|dkr�t|�td�kr�td	��n |dkr�t|�tkr�td
t��nr|dkr�|r�|dkr�td��nT|dk�r0|�r8yt|�}Wntd�d�YnXt|�dk�r8td��ntd��dS)Nr�zInvalid section�segments_per_dirz
Invalid value�max_segment_size�additional_free_spacer�r�z"Invalid value: storage_quota < 10Mz%Invalid value: max_segment_size >= %dr��0r!rz$Invalid value, must be 64 hex digits� zInvalid name)r�)r�)r�r�r�)r�)r�r!)r)�
ValueError�intr;�MAX_SEGMENT_SIZE_LIMITrr�)�sectionr��value�check_valueZbin_idrrr��
repo_validateKs@



z)Archiver.do_config.<locals>.repo_validatecSs2|dkrtd��|dkr&|r.t|�ntd��dS)Nr�zInvalid section�previous_locationzInvalid name)r�)r�)r�r/)r�r�r�r�rrr��cache_validatens
z*Archiver.do_config.<locals>.cache_validatecs~dtt�tt�d�j�jd�}td�xRdD]J}|jd|d
d�}|dkrf|j|�}|dkrftd|��td||f�q,WdS)Nr!r�)�versionr�r�r�r�r�z[repository]r�r�r�r�r�r�rr�F)rTzFThe repository config is missing the %s key which has no default valuez%s = %s)r�r�r�r�r�r�r)r�ZDEFAULT_SEGMENTS_PER_DIRr�r�r�r�r�r()rrZdefault_valuesr�r�)r�rr��list_configws 

z'Archiver.do_config.<locals>.list_configz No config key name was provided.�.r�r�)r�cs�j�j�j�S)N)Zsave_configr�rrr)r�rr�r��sz$Archiver.do_config.<locals>.<lambda>F)r�r)r�)NT)NT)%r�r�r�r�r�r�r�rFr�r(�WRITErr�rZcache_configZ_configrorrr#Z
remove_optionr�rAZremove_sectionr�ZsectionsZadd_sectionr\r�r��configparserZ
NoOptionErrorZNoSectionErrorr�r�r%r$r�)r�r~r�r�r�r�r�r�r�r�r�rrroZvalidaterwr)r�r��	do_configGs^
#
	





zArchiver.do_configcCs&tt��tdtj�tdt��tS)z6display system information for debugging / bug reportszCRC implementation:zProcess ID:)r�rOr�__name__rmr$)r�r~rrr��
do_debug_info�s
zArchiver.do_debug_infoc
Cs�t||||jj|jd�}xdt|jj�D]T\}}|j||j|��}d|t	|�f}	t
d|	�t|	d��}
|
j|�WdQRXq&Wt
d�t
S)zAdump (decrypted, decompressed) archive items metadata (not: data))r�z
%06d_%s.items�Dumpingr�NzDone.)rr�r�r�r,r�itemsrqr�r?r�r�r�r$)r�r~r�r�r�r�r<�item_idr=�filenamer>rrr��do_debug_dump_archive_items�s

z$Archiver.do_debug_dump_archive_itemscs�y|jj�t�jj��Wn"tk
r<tj�jj��YnXd��fdd�������fdd�}t�j	d��}||�WdQRXt
S)z)dump decoded archive metadata (not: data)�cstjtj|�d�d�d�S)N)�indentr)r)rRr�r�r�)r)r�rr��	do_indent�sz1Archiver.do_debug_dump_archive.<locals>.do_indentcs6|jd�|jdtj�jj�d�|jd�|j�t����|jd��j�d�j�d��}tj	|t
dd�}|jd�|j�t|���|jd�|jd	�tjd
t
d�}d}xd|d
D]X}�j|�j|��}|j|�x6|D].}t|�}|r�d
}n
|jd�|j�|��q�Wq�W|jd�|jd�dS)Nz{
z
    "_name": z,
z    "_manifest_entry":
sid�surrogateescape)�object_hook�unicode_errorsz
    "_meta":
z    "_items": [
F)�use_listr�Tsitemsr2z    ]
}
)
r�r�r�r�r�r@rqr�r_�unpackbrHZUnpackerZfeed)r>r=Zarchive_org_dictZunpackerrr�r})�archive_meta_origr~r�r�r�rr�r��s0









z.Archiver.do_debug_dump_archive.<locals>.outputr�N)r#Zget_raw_dictr=r�r�r-rZDoesNotExistr]r�r$)r�r~r�r�r�r�r>r)r�r~r�r�r�r�r��do_debug_dump_archive�s zArchiver.do_debug_dump_archivecCsT|jd|j|j��}ttj|tdd��}t|jd��}t	j
||dd�WdQRXtS)z dump decoded repository manifestNr�)r�r�r�r�)r�)rqr�rr@r`r�rHr]r�r��dumpr$)r�r~r�r�r�r=�metar>rrr��do_debug_dump_manifests
zArchiver.do_debug_dump_manifestc	s`ddlm}d
�fdd�	}|jr�x.|j�D]"\}}}}}	|tkr*|||��Pq*Wd}
xz|j�D]n\}}}}}	|tkr�||
||d||	d�n:|tkr�||
|dd	||	d�n|tkr�||
ddd
||	d�|
d7}
q^Wn�|jddd�}|j|d�}|||��d}d}
xR|j	t
|d�}
|
�sP|
d}x,|
D]$}|j|�}||
||�|
d7}
�q&W�qWtd�tS)zOdump (decrypted, decompressed) repo objects, repo index MUST be current/correctr)�key_factoryNc	s�|dk	r(|tjkr|nd}�j||�}nd}|dkr8dnd|}|dk	rTdt|�nd}	|dk	rldt|�nd}
|dk	r�dt|�nd}d||	|
||f}td|�t|d��}
|
j|�WdQRXdS)N�r�r�z%08d%s%s%s%s.objr�r�)rFrrqr�r?r�r�r�)r<rrv�tag�segment�offset�give_idr=Ztag_strZsegment_strZ
offset_strZid_strr�r>)r�rr��decrypt_dumps
z6Archiver.do_debug_dump_repo_objs.<locals>.decrypt_dumprr)r�r�r��delr�)�limit�markerzDone.)NNNr�)
�
crypto.keyr��ghostZscan_low_levelrtrurvr�r��scanrsr�r$)r�r~r�r�r�rrvr�r�r�r<�idsr��resultr)r�r��do_debug_dump_repo_objss@



z Archiver.do_debug_dump_repo_objscs2d��fdd�}|j}yF|jd�r4t|dd��}n&|jd�rR|dd�jd�}ntd	��Wnttfk
rxd}YnX|s�|jd
�tSddlm	}|j
ddd
�}|j|d�}|||�}d}	d}
d}d}�xT|jt
|	d
�}
|
s�P|
d}	�x0|
D�]&}|j|�}|tjk�r|nd}|j||�}|
t|�dd�|dt|�d�}||k�r�|
t|�d�d�|dt|�d��}|j|�}d||j�|j�f}|||||�|j|�}|�r�|j|�}d||j�|f}|||||�||}}
|d7}|ddkr�td|�q�Wq�Wtd�tS)zMsearch for byte sequences in repo objects, repo index MUST be current/correctr�c	sZ||�|�}||t|�|t|���}td||j�|j�|j�|||f�dS)Nz%s: %s %s %s == %r %r %r)r�r��hex)r��wantedr=r�Zbefore�after)rmrr��
print_findingQs z9Archiver.do_debug_search_repo_objs.<locals>.print_findingzhex:r�Nzstr:zutf-8zunsupported search termz6search term needs to be hex:123abc or str:foobar styler)r�)r�r�rr�z
%d %s | %sz	%d %s #%di'z%d objects processed.zDone.r�)r�r�r�encoder��UnicodeEncodeErrorr�r&r�r�r�r�r�rsrFrrqr��findr�r9r�r$)r�r~r�r�r�r�r�rvr�r�Z	last_dataZlast_idr<r�rr�r=Z
boundary_datar�r�r9r)rmr��do_debug_search_repo_objsLs`





*
2



z"Archiver.do_debug_search_repo_objscCs�|j}yt|�}Wn tk
r2td|�YnbXy|j|�}Wn"tjk
rdtd|�Yn0Xt|jd��}|j	|�WdQRXtd|�t
S)z>get object contents from the repository and write it into filezobject id %s is invalid.zobject %s not found.r�Nzobject %s fetched.)rrr�r�r�rr�ObjectNotFoundr�r�r�r$)r�r~r��hex_idrr=�frrr��do_debug_get_obj�szArchiver.do_debug_get_objcCsdxV|jD]L}t|d��}|j�}WdQRXtj|�}|j|j�|�td|j��qW|j	�t
S)z(put file(s) contents into the repository�rbNzobject %s put.)rdr��read�hashlibZsha256rZdigestr�Z	hexdigestr�r$)r�r~r�r�r�r=�hrrr��do_debug_put_obj�s
zArchiver.do_debug_put_objcCs�d}x~|jD]t}yt|�}Wn tk
r<td|�YqXy|j|�d}td|�Wqtjk
r~td|�YqXqW|r�|j�td�tS)z3delete the objects with the given IDs from the repoFzobject id %s is invalid.Tzobject %s deleted.zobject %s not found.zDone.)	r�rr�r�r#rrr�r�r$)r�r~r�rr�rrrr��do_debug_delete_obj�s 
zArchiver.do_debug_delete_obj)r�r�r�r�c	Cs�x�|jD]v}yt|�}Wn tk
r8td|�YqXy"|j|d}td||f�Wqtk
r|td|�YqXqWtS)z4display refcounts for the objects with the given IDszobject id %s is invalid.rz4object %s has %d referrers [info from chunks cache].z-object %s not found [info from chunks cache].)r�rr�r�r�r-r$)	r�r~r�r�r�r�r�rZrefcountrrr��do_debug_refcount_obj�szArchiver.do_debug_refcount_objcCsd|js|j|j��z@t|j|j|jd�}t|jd��}t	j
||dd�WdQRXWd|j�XtS)zdump repository hints)�segments�compact�storage_quota_user�r�)r�N)
Z_active_txnZprepare_txnZget_transaction_id�dictr�r�r�r]r�r�r�Zrollbackr$)r�r~r�Zhintsr>rrr��do_debug_dump_hints�s

zArchiver.do_debug_dump_hintscCsLddl}|j�4|j�"|jtj|jddd�|j�WdQRXWdQRXtS)z&convert Borg profile to Python profilerNFzutf-8)r��encoding)�marshalr��inputr�r_�unpackr$)r�r~r�rrr��do_debug_convert_profile�s0z!Archiver.do_debug_convert_profile)r�r�cCs|j�tj|�|jS)zCBreak the repository lock (e.g. in case it was left by a dead borg.)Z
break_lockrr�)r�r~r�rrr��
do_break_lock�s
zArchiver.do_break_locka-
        The path/filenames used as input for the pattern matching start from the
        currently active recursion root. You usually give the recursion root(s)
        when invoking borg and these can be either relative or absolute paths.

        So, when you give `relative/` as root, the paths going into the matcher
        will look like `relative/.../file.ext`. When you give `/absolute/` as
        root, they will look like `/absolute/.../file.ext`. This is meant when
        we talk about "full path" below.

        File paths in Borg archives are always stored normalized and relative.
        This means that e.g. ``borg create /path/to/repo ../some/path`` will
        store all files as `some/path/.../file.ext` and ``borg create
        /path/to/repo /home/user`` will store all files as
        `home/user/.../file.ext`. Therefore, always use relative paths in your
        patterns when matching archive content in commands like ``extract`` or
        ``mount``. Starting with Borg 1.2 this behaviour will be changed to
        accept both absolute and relative paths.

        A directory exclusion pattern can end either with or without a slash ('/').
        If it ends with a slash, such as `some/path/`, the directory will be
        included but not its content. If it does not end with a slash, such as
        `some/path`, both the directory and content will be excluded.

        File patterns support these styles: fnmatch, shell, regular expressions,
        path prefixes and path full-matches. By default, fnmatch is used for
        ``--exclude`` patterns and shell-style is used for the ``--pattern`` option.

        If followed by a colon (':') the first two characters of a pattern are
        used as a style selector. Explicit style selection is necessary when a
        non-default style is desired or when the desired pattern starts with
        two alphanumeric characters followed by a colon (i.e. `aa:something/*`).

        `Fnmatch <https://docs.python.org/3/library/fnmatch.html>`_, selector `fm:`
            This is the default style for ``--exclude`` and ``--exclude-from``.
            These patterns use a variant of shell pattern syntax, with '\*' matching
            any number of characters, '?' matching any single character, '[...]'
            matching any single character specified, including ranges, and '[!...]'
            matching any character not specified. For the purpose of these patterns,
            the path separator (backslash for Windows and '/' on other systems) is not
            treated specially. Wrap meta-characters in brackets for a literal
            match (i.e. `[?]` to match the literal character `?`). For a path
            to match a pattern, the full path must match, or it must match
            from the start of the full path to just before a path separator. Except
            for the root path, paths will never end in the path separator when
            matching is attempted.  Thus, if a given pattern ends in a path
            separator, a '\*' is appended before matching is attempted.

        Shell-style patterns, selector `sh:`
            This is the default style for ``--pattern`` and ``--patterns-from``.
            Like fnmatch patterns these are similar to shell patterns. The difference
            is that the pattern may include `**/` for matching zero or more directory
            levels, `*` for matching zero or more arbitrary characters with the
            exception of any path separator.

        Regular expressions, selector `re:`
            Regular expressions similar to those found in Perl are supported. Unlike
            shell patterns regular expressions are not required to match the full
            path and any substring match is sufficient. It is strongly recommended to
            anchor patterns to the start ('^'), to the end ('$') or both. Path
            separators (backslash for Windows and '/' on other systems) in paths are
            always normalized to a forward slash ('/') before applying a pattern. The
            regular expression syntax is described in the `Python documentation for
            the re module <https://docs.python.org/3/library/re.html>`_.

        Path prefix, selector `pp:`
            This pattern style is useful to match whole sub-directories. The pattern
            `pp:root/somedir` matches `root/somedir` and everything therein.

        Path full-match, selector `pf:`
            This pattern style is (only) useful to match full paths.
            This is kind of a pseudo pattern as it can not have any variable or
            unspecified parts - the full path must be given.
            `pf:root/file.ext` matches `root/file.ext` only.

            Implementation note: this is implemented via very time-efficient O(1)
            hashtable lookups (this means you can have huge amounts of such patterns
            without impacting performance much).
            Due to that, this kind of pattern does not respect any context or order.
            If you use such a pattern to include a file, it will always be included
            (if the directory recursion encounters it).
            Other include/exclude patterns that would normally match will be ignored.
            Same logic applies for exclude.

        .. note::

            `re:`, `sh:` and `fm:` patterns are all implemented on top of the Python SRE
            engine. It is very easy to formulate patterns for each of these types which
            requires an inordinate amount of time to match paths. If untrusted users
            are able to supply patterns, ensure they cannot supply `re:` patterns.
            Further, ensure that `sh:` and `fm:` patterns only contain a handful of
            wildcards at most.

        Exclusions can be passed via the command line option ``--exclude``. When used
        from within a shell, the patterns should be quoted to protect them from
        expansion.

        The ``--exclude-from`` option permits loading exclusion patterns from a text
        file with one pattern per line. Lines empty or starting with the number sign
        ('#') after removing whitespace on both ends are ignored. The optional style
        selector prefix is also supported for patterns loaded from a file. Due to
        whitespace removal, paths with whitespace at the beginning or end can only be
        excluded using regular expressions.

        To test your exclusion patterns without performing an actual backup you can
        run ``borg create --list --dry-run ...``.

        Examples::

            # Exclude '/home/user/file.o' but not '/home/user/file.odt':
            $ borg create -e '*.o' backup /

            # Exclude '/home/user/junk' and '/home/user/subdir/junk' but
            # not '/home/user/importantjunk' or '/etc/junk':
            $ borg create -e '/home/*/junk' backup /

            # Exclude the contents of '/home/user/cache' but not the directory itself:
            $ borg create -e /home/user/cache/ backup /

            # The file '/home/user/cache/important' is *not* backed up:
            $ borg create -e /home/user/cache/ backup / /home/user/cache/important

            # The contents of directories in '/home' are not backed up when their name
            # ends in '.tmp'
            $ borg create --exclude 're:^/home/[^/]+\.tmp/' backup /

            # Load exclusions from file
            $ cat >exclude.txt <<EOF
            # Comment line
            /home/*/junk
            *.tmp
            fm:aa:something/*
            re:^/home/[^/]+\.tmp/
            sh:/home/*/.thumbnails
            # Example with spaces, no need to escape as it is processed by borg
            some file with spaces.txt
            EOF
            $ borg create --exclude-from exclude.txt backup /

        A more general and easier to use way to define filename matching patterns exists
        with the ``--pattern`` and ``--patterns-from`` options. Using these, you may
        specify the backup roots (starting points) and patterns for inclusion/exclusion.
        A root path starts with the prefix `R`, followed by a path (a plain path, not a
        file pattern). An include rule starts with the prefix +, an exclude rule starts
        with the prefix -, an exclude-norecurse rule starts with !, all followed by a pattern.

        .. note::

            Via ``--pattern`` or ``--patterns-from`` you can define BOTH inclusion and exclusion
            of files using pattern prefixes ``+`` and ``-``. With ``--exclude`` and
            ``--exclude-from`` ONLY excludes are defined.

        Inclusion patterns are useful to include paths that are contained in an excluded
        path. The first matching pattern is used so if an include pattern matches before
        an exclude pattern, the file is backed up. If an exclude-norecurse pattern matches
        a directory, it won't recurse into it and won't discover any potential matches for
        include rules below that directory.

        .. note::

            It's possible that a sub-directory/file is matched while parent directories are not.
            In that case, parent directories are not backed up thus their user, group, permission,
            etc. can not be restored.

        Note that the default pattern style for ``--pattern`` and ``--patterns-from`` is
        shell style (`sh:`), so those patterns behave similar to rsync include/exclude
        patterns. The pattern style can be set via the `P` prefix.

        Patterns (``--pattern``) and excludes (``--exclude``) from the command line are
        considered first (in the order of appearance). Then patterns from ``--patterns-from``
        are added. Exclusion patterns from ``--exclude-from`` files are appended last.

        Examples::

            # backup pics, but not the ones from 2018, except the good ones:
            # note: using = is essential to avoid cmdline argument parsing issues.
            borg create --pattern=+pics/2018/good --pattern=-pics/2018 repo::arch pics

            # use a file with patterns:
            borg create --patterns-from patterns.lst repo::arch

        The patterns.lst file could look like that::

            # "sh:" pattern style is the default, so the following line is not needed:
            P sh
            R /
            # can be rebuild
            - /home/*/.cache
            # they're downloads for a reason
            - /home/*/Downloads
            # susan is a nice person
            # include susans home
            + /home/susan
            # also back up this exact file
            + pf:/home/bobby/specialfile.txt
            # don't backup the other home directories
            - /home/*
            # don't even look in /proc
            ! /proc

        You can specify recursion roots either on the command line or in a patternfile::

            # these two commands do the same thing
            borg create --exclude /home/bobby/junk repo::arch /home/bobby /home/susan
            borg create --patterns-from patternfile.lst repo::arch

        The patternfile::

            # note that excludes use fm: by default and patternfiles use sh: by default.
            # therefore, we need to specify fm: to have the same exact behavior.
            P fm
            R /home/bobby
            R /home/susan

            - /home/bobby/junk

        This allows you to share the same patterns between multiple repositories
        without needing to specify them on the command line.

r�a5	
        Repository (or Archive) URLs, ``--prefix``, ``--glob-archives``, ``--comment``
        and ``--remote-path`` values support these placeholders:

        {hostname}
            The (short) hostname of the machine.

        {fqdn}
            The full name of the machine.

        {reverse-fqdn}
            The full name of the machine in reverse domain name notation.

        {now}
            The current local date and time, by default in ISO-8601 format.
            You can also supply your own `format string <https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}

        {utcnow}
            The current UTC date and time, by default in ISO-8601 format.
            You can also supply your own `format string <https://docs.python.org/3.7/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}

        {user}
            The user name (or UID, if no name is available) of the user running borg.

        {pid}
            The current process ID.

        {borgversion}
            The version of borg, e.g.: 1.0.8rc1

        {borgmajor}
            The version of borg, only the major version, e.g.: 1

        {borgminor}
            The version of borg, only major and minor version, e.g.: 1.0

        {borgpatch}
            The version of borg, only major, minor and patch version, e.g.: 1.0.8

        If literal curly braces need to be used, double them for escaping::

            borg create /path/to/repo::{{literal_text}}

        Examples::

            borg create /path/to/repo::{hostname}-{user}-{utcnow} ...
            borg create /path/to/repo::{hostname}-{now:%Y-%m-%d_%H:%M:%S} ...
            borg prune --prefix '{hostname}-' ...

        .. note::
            systemd uses a difficult, non-standard syntax for command lines in unit files (refer to
            the `systemd.unit(5)` manual page).

            When invoking borg from unit files, pay particular attention to escaping,
            especially when using the now/utcnow placeholders, since systemd performs its own
            %-based variable replacement even in quoted text. To avoid interference from systemd,
            double all percent signs (``{hostname}-{now:%Y-%m-%d_%H:%M:%S}``
            becomes ``{hostname}-{now:%%Y-%%m-%%d_%%H:%%M:%%S}``).

Zplaceholdersa�

        It is no problem to mix different compression methods in one repo,
        deduplication is done on the source data chunks (not on the compressed
        or encrypted data).

        If some specific chunk was once compressed and stored into the repo, creating
        another backup that also uses this chunk will not change the stored chunk.
        So if you use different compression specs for the backups, whichever stores a
        chunk first determines its compression. See also borg recreate.

        Compression is lz4 by default. If you want something else, you have to specify what you want.

        Valid compression specifiers are:

        none
            Do not compress.

        lz4
            Use lz4 compression. Very high speed, very low compression. (default)

        zstd[,L]
            Use zstd ("zstandard") compression, a modern wide-range algorithm.
            If you do not explicitely give the compression level L (ranging from 1
            to 22), it will use level 3.
            Archives compressed with zstd are not compatible with borg < 1.1.4.

        zlib[,L]
            Use zlib ("gz") compression. Medium speed, medium compression.
            If you do not explicitely give the compression level L (ranging from 0
            to 9), it will use level 6.
            Giving level 0 (means "no compression", but still has zlib protocol
            overhead) is usually pointless, you better use "none" compression.

        lzma[,L]
            Use lzma ("xz") compression. Low speed, high compression.
            If you do not explicitely give the compression level L (ranging from 0
            to 9), it will use level 6.
            Giving levels above 6 is pointless and counterproductive because it does
            not compress better due to the buffer size used by borg - but it wastes
            lots of CPU cycles and RAM.

        auto,C[,L]
            Use a built-in heuristic to decide per chunk whether to compress or not.
            The heuristic tries with lz4 whether the data is compressible.
            For incompressible data, it will not use compression (uses "none").
            For compressible data, it uses the given C[,L] compression - with C[,L]
            being any valid compression specifier.

        Examples::

            borg create --compression lz4 REPO::ARCHIVE data
            borg create --compression zstd REPO::ARCHIVE data
            borg create --compression zstd,10 REPO::ARCHIVE data
            borg create --compression zlib REPO::ARCHIVE data
            borg create --compression zlib,1 REPO::ARCHIVE data
            borg create --compression auto,lzma,6 REPO::ARCHIVE data
            borg create --compression auto,lzma ...

r�cCs�|js|j�n�|j|jkr2tt|j|j��n�|j|kr�|jrTt||jj�q�|jrvd||j_||jj�q�||jj�nhg}|d|jg7}|dg7}|ddjt	|j
���g7}|ddjt	|jj
���g7}|jdj|��|jS)NzNo help available on %s.zTry one of the following:z    Commands: %sz, z    Topics: %sr2)
�topic�
print_help�helptextr�rd�epilog_only�epilog�
usage_onlyr4r�keysr�r�)r��parserZcommandsr~Z	msg_linesrrr��do_helpA
s$


zArchiver.do_helpcCs|j�tS)zdisplay infos about subcommand)r�r$)r�r�r~rrr��do_subcommand_helpW
szArchiver.do_subcommand_helpcCsrdd
ddg}x`t|dd��D]L\}}xB|D]:\}}}|j|�r,|dk	rX|j||�||<t|tjd�q,WqW|S)N�
--list-format�--format�EWarning: "--list-format" has been deprecated. Use "--format" instead.�--keep-tag-files�--keep-exclude-tags�SWarning: "--keep-tag-files" has been deprecated. Use "--keep-exclude-tags" instead.�--ignore-inode�jWarning: "--ignore-inode" has been deprecated. Use "--files-cache=ctime,size" or "...=mtime,size" instead.�--no-files-cache�VWarning: "--no-files-cache" has been deprecated. Use "--files-cache=disabled" instead.)r�)r�r�r�)r�r�r�)r�Nr�)r�Nr�)r,r��replacer�r�r�)r�r~Zdeprecationsr<rlZold_name�new_namer�rrr��preprocess_args^
s
zArchiver.preprocess_argsc@s2eZdZdZdd�Zddd�Zejd�dd	�Zd
S)zArchiver.CommonOptionsa�
        Support class to allow specifying common options directly after the top-level command.

        Normally options can only be specified on the parser defining them, which means
        that generally speaking *all* options go after all sub-commands. This is annoying
        for common options in scripts, e.g. --remote-path or logging options.

        This class allows adding the same set of options to both the top-level parser
        and the final sub-command parsers (but not intermediary sub-commands, at least for now).

        It does so by giving every option's target name ("dest") a suffix indicating its level
        -- no two options in the parser hierarchy can have the same target --
        then, after parsing the command line, multiple definitions are resolved.

        Defaults are handled by only setting them on the top-level parser and setting
        a sentinel object in all sub-parsers, which then allows to discern which parser
        supplied the option.
        cCs(||_||_t�|_t�|_t�|_dS)a�
            *define_common_options* should be a callable taking one argument, which
            will be a argparse.Parser.add_argument-like function.

            *define_common_options* will be called multiple times, and should call
            the passed function to define common options exactly the same way each time.

            *suffix_precedence* should be a tuple of the suffixes that will be used.
            It is ordered from lowest precedence to highest precedence:
            An option specified on the parser belonging to index 0 is overridden if the
            same option is specified on any parser with a higher index.
            N)�define_common_options�suffix_precedencer��common_optionsr\�append_optionsr��default_sentinel)r�r�r�rrr�r��
s

zArchiver.CommonOptions.__init__Fcs8��jkst�����fdd�}|jd���j|�dS)a�
            Add common options to *parser*.

            *provide_defaults* must only be True exactly once in a parser hierarchy,
            at the top level, and False on all lower levels. The default is chosen
            accordingly.

            *suffix* indicates the suffix to use internally. It also indicates
            which precedence the *parser* has for common options. See *suffix_precedence*
            of __init__.
            cs�d|kr�|jdd�|ddks$t�|ddk}|rZ�jj|d�|d	gksttd
��n�jj�t��j|d�|d�7<�s�|d||d<|s��j|d	<�j||�dS)N�dest�action�store�help�store_const�
store_true�store_falser��defaultzCThe default is explicitly constructed as an empty list in resolve())r�r�r�r�r�r�)�
setdefaultr�r�r^r�r\r��add_argument)r~r�Z	is_append)�common_group�provide_defaultsr��suffixrr�r��
s
z=Archiver.CommonOptions.add_common_group.<locals>.add_argumentzCommon optionsN)r�r��add_argument_groupr�)r�r�rr�r�r)r�r�r�rr��add_common_group�
s
z'Archiver.CommonOptions.add_common_group)r~c

Cs�xz|jD]p}xj|jj|g�D]X}||}|}t|||j�}||jk	rPt|||�yt||�Wqtk
rrYqXqWqWx\|jD]R}g}x<|jD]2}||}||kr�t||�}	t||�|j	|	�q�Wt|||�q�WdS)zd
            Resolve the multiple definitions of each common option to the final value.
            N)
r�r�r�r{r��setattr�delattr�AttributeErrorr��extend)
r�r~rr�Zmap_fromZmap_tor�Zoption_valueZextend_fromrrrr��resolve�
s(


zArchiver.CommonOptions.resolveN)F)	r��
__module__�__qualname__�__doc__r�rr�Z	Namespacerrrrr��
CommonOptionsn
s
(rc7
s�ddddddd���fdd	�}d
d�}ddd
�dd���fdd�}ddd�dd�}tj|jddd�}|jtj|j|�ggd�|j|�d7d�|_|j	dddd t
d!d"�|jj|ddd#�tjd|jd$�}|jggd%�|jj|d�tjd|jd$�}|jggd%�|jj|d�|d&�}|jd'k�rJ|jj
|_||_tj|_d(|_|}	n.|jd)d*d+�}
|
jd,|gd|jj
|tjd(d-�}	|	j|jd.�|	j	d/d0t�d1d2�|	j	d3d4td5d2�|	j	d6d7d8d9d:d;�|	j	d<d=td>d?�||	�|	j	d@dAdBtdCdD�||	ddE�|jd'k�r
|S|dF�}|
jdG|gd|jj
|tjdHd-�}	|	j|jd.�|	j	dIdAdJdKdLdM�|	j	dNdAdOdKdPdM�|	j	dQdRd9dSd;�|	j	dTdUdVtddWdX�|dY�}|
jdZ|gd|jj
|tjd[d-�}	|	j|jd.�|	j	d/d\d]d^tdd_�d`da�|	j	dbdcdddedt�dfdg�|	j	dQdRd9dhd;�|	j	dTdUdVdtdidj�|	j	dkdld9dmd;�|dn�}
|
jdo|gd|jj
|
tjdpd-�}	|	j|jd.�|	j	d/d0d]d^t�dqda�|	j	drdsd9dtd;�|	j	dudvd9dwd;�|	j	dxdyd9dzd;�|	j	d{d|d9d}d;�|	j	d~dd9d�d;�||	�|
jd�|gdd�d^tjd�d-�}	|	jd)d*d+�}|	jtj|j|	�d��|d��}|jd�|gd|jj
|tjd�d-�}	|	j|jd.�|	j	d/d\d]d^tdd_�d��|	j	d�dAd]td�dD�|	j	d�d�d9d�d;�|	j	d�d�d9d�d;�|d��}|jd�|gd|jj
|tjd�d-�}	|	j|jd.�|	j	d/d\d]d^tdd_�d��|	j	d�dAd]td�dD�|	j	d�d�d9d�d;�|d��}|jd�|gd|jj
|tjd�d-�}	|	j|jd.�|	j	d/d\d]d^tdd_�d��|
jd�|gd|jj
|tjd�d-�}	|	j|j d.�|	j	d/d\d]d^tdd_�d��|d��}|jd�|gd|j!j
|tjd�d-�}	|	j|j!d.�|	j	d/d\d]d^tdd_�d��|d��}|
jd�|gd|j"j
|tjd�d-�}	|	j|j"d.�|	j	d�d�d�d9d�d;�|	j	d�d�d�d9d�d;�|	j	d�d�d9d�d;�|	j	d�d�d�d�d��|	j	d�d9d�d��|	j	d�d�d9d�d;�|	j	d�d�d�d�d;�|	j	d�d�d�d�d�d��|	j	d�d�d�t#dƒd�d��|	j	d�d�d�t$dƒd�d��|	j	d�d�d�d�d̄t%d�dX�||	dd΍}|j	d�d�d9d�d;�|	j&d҃}|j	d�d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�d�d9d�d;�|j	d�ddd�t't(d�t(dX�|j	d�d�d9d�d;�|	j&d��}|j	d�d�d�t)d^d�d��|j	d�d�d�t*dd�dX�|j	d��d�d�dt+�d�ddX�|j	�d�d�dt,t-�dt-dX�|j	�d	�d
�d�dt.t.�d
��ddX�|	j	d/�dtdd_��dd2�|	j	d@dAdBt�ddD�|�d�}|
j�d|gd|j/j
|tj�dd-�}	|	j|j/d.�|	j	d�d�d9d�d;�|	j	d�d�d�d9�dd;�|	j	d�d�d9�dd;�|	j	d�d�d9�dd;�|	j	d�d�d9�dd;�|	j	d�d�d9�dd;�|	j	�d�dd9�dd;�|	j	�d�dd9�dd;�|	j	d/�dtdd_��d d2�|	j	d@dAdBtdCdD�||	ddE�|�d!�}|
j�d"|gd|j0j
|tj�d#d-�}	|	j|j0d.�|	j	�d$�d%�d&�d'�d(�|	j	d�d�d9d�d;�|	j	d/�dtdd_��d)d2�|	j	�d*�d+�d,�d-�|	j	d@dAdBtdCdD�||	ddE�|�d.�}|
j�d/|gd|j1j
|tj�d0d-�}	|	j|j1d.�|	j	d�d�d9�d1d;�|	j	�d2�d3d9�d4d;�|	j	�d5�d6d9�d7d;�|	j	�d8d9�d9d��|	j	d/�d:tdd_��d;d2�|	j	�d<�d=t2��d>d2�|	j	d@dAdBt�d?dD�||	�|�d@�}|
j�dA|gd|j3j
|tj�dBd-�}	|	j|j3d.�|	j	d/�dtdd_��dCd2�|	j	�dD�dEt2��dFd2�|�dG�}|
j�dH|gd|j4j
|tj�dId-�}	|	j|j4d.�|	j	d�d�d�d9�dJd;�|	j	d�d�d�d9�dKd;�|	j	�dL�dMd9�dNd;�|	j	�dO�dP�dQddR�dS�|	j	d~dd9d�d;�|	j	d/d0d]d^t��dTda�|	j	�dU�ddB�dV�dW�||	�|�dX�t5j6�t7j8�dY�t9j6�t7j8�dZ�t:j6�}|
j�d[|gd|j;j
|tj�d\d-�}	|	j|j;d.�|	j	�d]�d^d9�d_d;�|	j	�d`�da�db�dc�ddd��|	j	d�d9�ded��|	j	�d8d9�dfd��|	j	d/d0d]d^t��dgda�|	j	d@dAdBt�dhdD�||	�||	�|�di�}|
j�dj|gd|j<j
|tj�dkd-�}	|	j|j<d.�|	j	d3d4t�dld2�|�dm�}|
j�dn|gd|j=j
|tj�dod-�}	|	j|j=d.�|	j	d/d0d]d^t��dpda�|	j	d�d9�dqd��||	�|�dr�}|
j�ds|gd|j>j
|tj�dtd-�}	|	j|j>d.�|	j	d/d\d]d^tdd_��duda�|�dv�} |
j�dw|gd|j?j
| tj�dxd-�}	|	j|j?d.�|	j	d�d�d�d9�dJd;�|	j	�dO�dPd9�dyd;�|	j	d�d�d�d9�dKd;�|	j	d�d�d9�dzd;�|	j	�d{�d|�d}t@�d~�d�|	j	�d��d��d�t+dd��d��|	j	�d��d�t+dd��d��|	j	�d��d��d�t+dd��d��|	j	�d��d��d�t+dd��d��|	j	�d��d��d�t+dd��d��|	j	�d��d��d�t+dd��d��|	j	�d��d��d�t+dd��d��||	ddd�|	j	d~dd9d�d;�|	j	d/d\d]d^tdd_��d�da�|�d��}!|
j�d�|gd|jAj
|!tj�d�d-�}	|	j|jAd.�|	j	d�d�d�d9�dJd;�|	j	�d��d�d9�d�d;�|	j	�dO�d�d9�d�d;�|	j	�d��d�d9�d�d;�|	j	�d��d�d9�d�d;�|	j	�d��d�d9�d�d;�|	j	d/d\d]d^tdd_��d�da�|�d��}"|
j�d�|gd|jBj
|"tj|jBj
d-�}	|	j|jBd.�|	j	d�d�d9d�d;�|	j	d�d�d��d�d��|	j	d�d�d�d9�d�d;�|	j	d�d�d�d9�d�d;�||	dd΍|	j&d��}|j	�d��d��d�dt2��d��d��|j	d��d�dt+�d�d�d�d��|j	d�d�d�t)dd�d��|j	d�d�d�t*d�d�dX�|j	�d	�d
�d�dt.t.�d
��ddX�|j	�d�dd�d�d]�d��d��d8�d��d��|j	�d�d�dt,t-�d�t-dX�|	j	d/d0d]d^t��d�da�|	j	d@dAdBt�d�dD�|�dŃ}#|
j�d�|gd|jCj
|#tj�d�d-�}	|	j|jCd.�|	j	d/d\tdd_��d�d2�|	j	�dɐdʐdːd-�|	j	�d̐d�tjD�dΐdW�|�dσ}$|
j�d�|gd|jEj
|$tj�d�d-�}	|	j|jEd.�|	j	d��dҐd�d9�d�d;�|	jF�}%|%j	�d��dՐdHd9�d�d;�|%j	�d�d��d[d9�d�d;�|	j	d/d\d]d^td�dِdڍ�d�da�|	j	�dDd�d]�dܐdW�|	j	�dݐd�d]�dߐdW�|
j�d�|gd�d�d�}	|	j	�d�d�d9�d�|	j	�d�d�d9�d�|	jtj|jG||
jH�d.�|	j	�d�d�td]�d�d�|�d�}&|
j�d�|gd�d�|&tj�d�d-�}	|	jd)d*d+�}'|	jtj|j|	�d��|�d�}(|'j�dn|gd|jIj
|(tj�d�d-�}	|	j|jId.�|�d�})|'j�d�|gd|jJj
|)tj�d�d-�}	|	j|jJd.�|	j	d/�dtdd_��d�d2�|�d��}*|'j�d�|gd|jKj
|*tj�d�d-�}	|	j|jKd.�|	j	d/�dtdd_��d�d2�|	j	d�dAt�d�d2�|�d��}+|'j�d�|gd|jLj
|+tj�d�d-�}	|	j|jLd.�|	j	d/d\tdd_��d�d2�|	j	d�dAt�d�d2�|�d��},|'j�d�|gd|jMj
|,tj�d�d-�}	|	j|jMd.�|	j	d/d\tdd_��d�d2�|	j	�d�dd9�dd;�|�d�}-|'j�d|gd|jNj
|-tj�dd-�}	|	j|jNd.�|	j	d/d\tdd_��dd2�|	j	�d�dt�d	d2�|�d
�}.|'j�d|gd|jOj
|.tj�dd-�}	|	j|jOd.�|	j	d/d\tdd_��d
d2�|	j	�d�dt�dd2�|	j	d�dAt�dd2�|�d�}/|'j�d|gd|jPj
|/tj�dd-�}	|	j|jPd.�|	j	d/d\tdd_��d
d2�|	j	d@dA�dt�ddD�|�d�}0|'j�d|gd|jQj
|0tj�dd-�}	|	j|jQd.�|	j	d/d\tdd_��d
d2�|	j	�d�d�dt�ddD�|�d�}1|'j�d|gd|jRj
|1tj�dd-�}	|	j|jRd.�|	j	d/d\tdd_��d
d2�|	j	�d�d�dt�d dD�|�d!�}2|'j�d"|gd|jSj
|2tj�d#d-�}	|	j|jSd.�|	j	d/d\tdd_��d�d2�|	j	d�dAt�d�d2�|�d$�}3|'j�d%|gd|jTj
|3tj�d&d-�}	|	j|jTd.�|	j	�d'�d(tjU�d)��d*d2�|	j	�d+�d,tjU�d-��d.d2�|�d/�}4|
j�d0|gd�d1|4tj�d1d-�}	|	jd)d*d+�}5|	jtj|j|	�d��|�d2�}6|5j�d3|gd|jVj
|6tj�d4d-�}	|	j|jVd.�|	j	d/d\tdd_��d5d2�|	j	d�dA�d6�d-�|S(9Nu;"I am seeing ‘A’ (added) status for a unchanged file!?"z"Item flags"z"borg help patterns"z"borg help placeholders"z:Internals -> Data structures and file formats -> Key fileszborg key export --help)Za_status_oddityZlist_item_flagsZ
borg_patternsZborg_placeholdersZ	key_filesZborg_key_exportcshtj|�j�}y
tj}Wntk
r0d}YnX|dkrHdd�|D�}dj|�}|dkrdt|��}|S)N�command-line�build_usagecSsg|]}|jd�s|�qS)z.. man)r�)r|rrrr�r�szAArchiver.build_parser.<locals>.process_epilog.<locals>.<listcomp>r2)rr
)rRrS�
splitlinesr=Zdoc_moderr4rd)r�rt)�rst_plain_text_referencesrr��process_epilog�
s



z-Archiver.build_parser.<locals>.process_epilogc
Ssf|ddddd�|dddd	d
dd�|d
dddd
dd�|dddd
d
dd�|ddddddd
dd�|ddddd
dd�|ddddgdd�|d d!d"d#d$d%�|d&d'd#d(d%�|d)d*d+td,d-d.�|d/d0d1tjd2d3�|d4d5d#d6d%�|d7d8d#d9d%�|d:d;d<d=d>�td?d.�|d@dAdBdCdD�|dEdFdGtdHdI�|dJdKd#dLd%�|dMdNdOddPdQ�|dRdSdTdUdD�dS)VNz-hz--helpr�zshow this help message and exit)r�r�z
--critical�	log_levelr�Zcriticalr�zwork on log level CRITICAL)r�r��constr�r�z--errorr�zwork on log level ERRORz	--warningz#work on log level WARNING (default)z--infoz-vz	--verboser�zwork on log level INFOz--debugrcz,enable debug output, work on log level DEBUGz
--debug-topic�TOPIC�debug_topicsr�z�enable TOPIC debugging (can be specified multiple times). The logger path is borg.debug.<TOPIC> if TOPIC is not fully qualified.)�metavarr�r�r�r�z-pz
--progressr�r�zshow progress information)r�r�r�z
--log-jsonr�z>Output one JSON object per log line instead of formatted text.z--lock-wait�SECONDSr�rzRwait at most SECONDS for acquiring a repository/cache lock (default: %(default)d).)rr�r�r�r�z
--bypass-lockr�r�zBypass locking mechanism)r�r�r�r�z--show-version�show_versionzshow/log the borg versionz	--show-rc�show_rczshow/log the return code (rc)z--umask�M�umaskcSs
t|d�S)N�)r�)rrrr�r�'szFArchiver.build_parser.<locals>.define_common_options.<locals>.<lambda>z9set umask to M (local and remote, default: %(default)04o)z
--remote-path�PATHZremote_pathz;use PATH as borg executable on the remote (default: "borg"))rr�r�z--remote-ratelimitZRATEZremote_ratelimitzGset remote network upload rate limit in kiByte/s (default: 0=unlimited))rr�r�r�z--consider-part-filesr�z>treat part files like normal files (e.g. to list/extract them)z--debug-profile�FILE�
debug_profilez�Write execution profile in Borg format into FILE. For local use a Python-compatible file can be generated by suffixing FILE with ".pyprof".)rr�r�r�z--rshZRSHZrshzHUse this command to connect to the 'borg serve' process (default: 'ssh'))r�r�ZSUPPRESSZ
UMASK_DEFAULT)Zadd_common_optionrrr�r�sV



z4Archiver.build_parser.<locals>.define_common_optionsF)�	tag_filesr�c	Ss�|ddddtddd�|dd	td
d�|ddtd
d�|ddtdd�|r�|ddddd�|ddddtdd�|dddddd�|r�|dd d!td"d#d$�dS)%Nz-ez	--excludeZPATTERNr�r�zexclude paths matching PATTERN)rr�r�r�r�z--exclude-fromZEXCLUDEFILEz4read exclude patterns from EXCLUDEFILE, one per line)rr�r�z	--patternz&include/exclude paths matching PATTERNz--patterns-fromZPATTERNFILEz<read include/exclude patterns from PATTERNFILE, one per linez--exclude-cachesrlr�z_exclude directories that contain a CACHEDIR.TAG file (http://www.bford.info/cachedir/spec.html))r�r�r�z--exclude-if-presentr�rmzYexclude directories that are tagged by containing a filesystem object with the given NAME)rr�r�r�r�z--keep-exclude-tagsz--keep-tag-filesrnzyif tag objects are specified with ``--exclude-if-present``, don't omit the tag objects themselves from the backup archivez--strip-components�NUMBERr�rziRemove the specified number of leading path elements. Paths with fewer elements will be silently skipped.)rr�r�r�r�)rhrfrergr�r�)Z
add_optionrr�rrr��define_exclude_and_patterns5s*
z:Archiver.build_parser.<locals>.define_exclude_and_patternscs|jd�}�|jf|�|S)NzExclusion options)rr�)�	subparserr��
exclude_group)r!rr��define_exclusion_groupRs
z5Archiver.build_parser.<locals>.define_exclusion_groupT)r�
first_lastc	Ss�|jdd�}|j�}|jddddtddd�|jd	d
ddtdd
d�|rpd}|jdddt|djdjt�|�d�|r�|j�}|jddddt	dd�|jddddt	dd�dS)NzArchive filtersz5Archive filters can be applied to repository targets.z-Pz--prefixZPREFIXrz6only consider archive names starting with this prefix.)rr�r�r�r�z-az--glob-archivesZGLOBr	z�only consider archive names matching the glob. sh: rules apply, see "borg help patterns". ``--prefix`` and ``--glob-archives`` are mutually exclusive.rDz	--sort-byZKEYSrzHComma-separated list of sorting keys; valid keys are: {}; default is: {}z, z--first�Nrrz:consider first N archives after other filters were applied)rr�r�r�r�z--lastrz9consider last N archives after other filters were applied)
r�add_mutually_exclusive_groupr�r0r1r3rr4r4r+)r"rr%Z
filters_grouprvZsort_by_defaultrrr��define_archive_filters_groupWs(
z;Archiver.build_parser.<locals>.define_archive_filters_groupzBorg - Deduplicated Backups)r��description�add_help)r�rdr��_maincommand�_midcommand�_subcommand)r�z-Vz	--versionr�z	%(prog)s zshow version number and exit)r�r�r�)r�)r*r�)rdr�a�
        This command mounts an archive as a FUSE filesystem. This can be useful for
        browsing an archive or restoring individual files. Unless the ``--foreground``
        option is given the command will run in the background until the filesystem
        is ``umounted``.

        The command ``borgfs`` provides a wrapper for ``borg mount``. This can also be
        used in fstab entries:
        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto 0 0``

        To allow a regular user to use fstab entries, add the ``user`` option:
        ``/path/to/repo /mnt/point fuse.borgfs defaults,noauto,user 0 0``

        For FUSE configuration and mount options, see the mount.fuse(8) manual page.

        Borg's default behavior is to use the archived user and group names of each
        file and map them to the system's respective user and group ids.
        Alternatively, using ``numeric-ids`` will instead use the archived user and
        group ids without any mapping.

        The ``uid`` and ``gid`` mount options (implemented by Borg) can be used to
        override the user and group ids of all files (i.e., ``borg mount -o
        uid=1000,gid=1000``).

        The man page references ``user_id`` and ``group_id`` mount options
        (implemented by fuse) which specify the user and group id of the mount owner
        (aka, the user who does the mounting). It is set automatically by libfuse (or
        the filesystem if libfuse is not used). However, you should not specify these
        manually. Unlike the ``uid`` and ``gid`` mount options which affect all files,
        ``user_id`` and ``group_id`` affect the user and group id of the mounted
        (base) directory.

        Additional mount options supported by borg:

        - versions: when used with a repository mount, this gives a merged, versioned
          view of the files in the archives. EXPERIMENTAL, layout may change in future.
        - allow_damaged_files: by default damaged files (where missing chunks were
          replaced with runs of zeros by borg check ``--repair``) are not readable and
          return EIO (I/O error). Set this option to read such files.
        - ignore_permissions: for security reasons the "default_permissions" mount
          option is internally enforced by borg. "ignore_permissions" can be given to
          not enforce "default_permissions".

        The BORG_MOUNT_DATA_CACHE_ENTRIES environment variable is meant for advanced users
        to tweak the performance. It sets the number of cached data chunks; additional
        memory usage can be up to ~8 MiB times this number. The default is the number
        of CPU cores.

        When the daemonized process receives a signal or crashes, it does not unmount.
        Unmounting in these cases could cause an active rsync or similar process
        to unintentionally delete data.

        When running in the foreground ^C/SIGINT unmounts cleanly, but other
        signals or crashes do not.
        Zborgfszmount repositoryzrequired argumentsz	<command>)�titlerr@)�parentsr*r)r��formatter_classr�)r�r�ZREPOSITORY_OR_ARCHIVEzrepository or archive to mount)rr�r�r7Z
MOUNTPOINTzwhere to mount filesystemz-fz--foregroundrBr�z$stay in foreground, do not daemonize)r�r�r�z-orAzExtra mount options)r�r�r�rdrrz(paths to extract; patterns are supported)r�nargsr�r�)r�zm
        This command starts a repository server process. This command is usually not used manually.
        r�zstart repository server processz--restrict-to-pathr�r�z�restrict repository access to PATH. Can be specified multiple times to allow the client access to several directories. Access to all sub-directories is granted implicitly; PATH doesn't need to directly point to a repository.)rr�r�r�z--restrict-to-repositoryr�a�restrict repository access. Only the repository located at PATH (no sub-directories are considered) is accessible. Can be specified multiple times to allow the client access to several repositories. Unlike ``--restrict-to-path`` sub-directories are not accessible; PATH needs to directly point at a repository location. PATH may be an empty directory or the last element of PATH may not exist, in which case the client may initialize a repository there.z
--append-onlyr�z0only allow appending to repository segment filesz--storage-quotaZQUOTAr�z�Override storage quota of the repository (e.g. 5G, 1.5T). When a new repository is initialized, sets the storage quota on the new repository as well. Default: no quota.)rr�r�r�r�a/
        This command initializes an empty repository. A repository is a filesystem
        directory containing the deduplicated data from zero or more archives.

        Encryption mode TLDR
        ++++++++++++++++++++

        The encryption mode can only be configured when creating a new repository -
        you can neither configure it on a per-archive basis nor change the
        encryption mode of an existing repository.

        Use ``repokey``::

            borg init --encryption repokey /path/to/repo

        Or ``repokey-blake2`` depending on which is faster on your client machines (see below)::

            borg init --encryption repokey-blake2 /path/to/repo

        Borg will:

        1. Ask you to come up with a passphrase.
        2. Create a borg key (which contains 3 random secrets. See :ref:`key_files`).
        3. Encrypt the key with your passphrase.
        4. Store the encrypted borg key inside the repository directory (in the repo config).
           This is why it is essential to use a secure passphrase.
        5. Encrypt and sign your backups to prevent anyone from reading or forging them unless they
           have the key and know the passphrase. Make sure to keep a backup of
           your key **outside** the repository - do not lock yourself out by
           "leaving your keys inside your car" (see :ref:`borg_key_export`).
           For remote backups the encryption is done locally - the remote machine
           never sees your passphrase, your unencrypted key or your unencrypted files.
           Chunking and id generation are also based on your key to improve
           your privacy.
        6. Use the key when extracting files to decrypt them and to verify that the contents of
           the backups have not been accidentally or maliciously altered.

        Picking a passphrase
        ++++++++++++++++++++

        Make sure you use a good passphrase. Not too short, not too simple. The real
        encryption / decryption key is encrypted with / locked by your passphrase.
        If an attacker gets your key, he can't unlock and use it without knowing the
        passphrase.

        Be careful with special or non-ascii characters in your passphrase:

        - Borg processes the passphrase as unicode (and encodes it as utf-8),
          so it does not have problems dealing with even the strangest characters.
        - BUT: that does not necessarily apply to your OS / VM / keyboard configuration.

        So better use a long passphrase made from simple ascii chars than one that
        includes non-ascii stuff or characters that are hard/impossible to enter on
        a different keyboard layout.

        You can change your passphrase for existing repos at any time, it won't affect
        the encryption/decryption key or other secrets.

        More encryption modes
        +++++++++++++++++++++

        Only use ``--encryption none`` if you are OK with anyone who has access to
        your repository being able to read your backups and tamper with their
        contents without you noticing.

        If you want "passphrase and having-the-key" security, use ``--encryption keyfile``.
        The key will be stored in your home directory (in ``~/.config/borg/keys``).

        If you do **not** want to encrypt the contents of your backups, but still
        want to detect malicious tampering use ``--encryption authenticated``.
        To normally work with ``authenticated`` repos, you will need the passphrase, but
        there is an emergency workaround, see ``BORG_WORKAROUNDS=authenticated_no_key`` docs.

        If ``BLAKE2b`` is faster than ``SHA-256`` on your hardware, use ``--encryption authenticated-blake2``,
        ``--encryption repokey-blake2`` or ``--encryption keyfile-blake2``. Note: for remote backups
        the hashing is done on your local machine.

        .. nanorst: inline-fill

        +----------+---------------+------------------------+--------------------------+
        | Hash/MAC | Not encrypted | Not encrypted,         | Encrypted (AEAD w/ AES)  |
        |          | no auth       | but authenticated      | and authenticated        |
        +----------+---------------+------------------------+--------------------------+
        | SHA-256  | none          | `authenticated`        | repokey                  |
        |          |               |                        | keyfile                  |
        +----------+---------------+------------------------+--------------------------+
        | BLAKE2b  | n/a           | `authenticated-blake2` | `repokey-blake2`         |
        |          |               |                        | `keyfile-blake2`         |
        +----------+---------------+------------------------+--------------------------+

        .. nanorst: inline-replace

        Modes `marked like this` in the above table are new in Borg 1.1 and are not
        backwards-compatible with Borg 1.0.x.

        On modern Intel/AMD CPUs (except very cheap ones), AES is usually
        hardware-accelerated.
        BLAKE2b is faster than SHA256 on Intel/AMD 64-bit CPUs
        (except AMD Ryzen and future CPUs with SHA extensions),
        which makes `authenticated-blake2` faster than `none` and `authenticated`.

        On modern ARM CPUs, NEON provides hardware acceleration for SHA256 making it faster
        than BLAKE2b-256 there. NEON accelerates AES as well.

        Hardware acceleration is always used automatically when available.

        `repokey` and `keyfile` use AES-CTR-256 for encryption and HMAC-SHA256 for
        authentication in an encrypt-then-MAC (EtM) construction. The chunk ID hash
        is HMAC-SHA256 as well (with a separate key).
        These modes are compatible with Borg 1.0.x.

        `repokey-blake2` and `keyfile-blake2` are also authenticated encryption modes,
        but use BLAKE2b-256 instead of HMAC-SHA256 for authentication. The chunk ID
        hash is a keyed BLAKE2b-256 hash.
        These modes are new and *not* compatible with Borg 1.0.x.

        `authenticated` mode uses no encryption, but authenticates repository contents
        through the same HMAC-SHA256 hash as the `repokey` and `keyfile` modes (it uses it
        as the chunk ID hash). The key is stored like `repokey`.
        This mode is new and *not* compatible with Borg 1.0.x.

        `authenticated-blake2` is like `authenticated`, but uses the keyed BLAKE2b-256 hash
        from the other blake2 modes.
        This mode is new and *not* compatible with Borg 1.0.x.

        `none` mode uses no encryption and no authentication. It uses SHA256 as chunk
        ID hash. This mode is not recommended, you should rather consider using an authenticated
        or authenticated/encrypted mode. This mode has possible denial-of-service issues
        when running ``borg create`` on contents controlled by an attacker.
        Use it only for new repositories where no encryption is wanted **and** when compatibility
        with 1.0.x is important. If compatibility with 1.0.x is not important, use
        `authenticated-blake2` or `authenticated` instead.
        This mode is compatible with Borg 1.0.x.
        Zinitzinitialize empty repositoryZ
REPOSITORYr�r�)r�zrepository to create)rr1r�r�r�z-ez--encryptionZMODErVz)select encryption key mode **(required)**)rr�Zrequired�choicesr�z%create an append-only mode repositoryzKSet storage quota of the new repository (e.g. 5G, 1.5T). Default: no quota.)rr�r�r�r�z--make-parent-dirsr�zOcreate the parent directories of the repository directory, if they are missing.a%
        The check command verifies the consistency of a repository and the corresponding archives.

        check --repair is a potentially dangerous function and might lead to data loss
        (for kinds of corruption it is not capable of dealing with). BE VERY CAREFUL!

        Pursuant to the previous warning it is also highly recommended to test the
        reliability of the hardware running this software with stress testing software
        such as memory testers. Unreliable hardware can also lead to data loss especially
        when this command is run in repair mode.

        First, the underlying repository data files are checked:

        - For all segments, the segment magic header is checked.
        - For all objects stored in the segments, all metadata (e.g. CRC and size) and
          all data is read. The read data is checked by size and CRC. Bit rot and other
          types of accidental damage can be detected this way.
        - In repair mode, if an integrity error is detected in a segment, try to recover
          as many objects from the segment as possible.
        - In repair mode, make sure that the index is consistent with the data stored in
          the segments.
        - If checking a remote repo via ``ssh:``, the repo check is executed on the server
          without causing significant network traffic.
        - The repository check can be skipped using the ``--archives-only`` option.

        Second, the consistency and correctness of the archive metadata is verified:

        - Is the repo manifest present? If not, it is rebuilt from archive metadata
          chunks (this requires reading and decrypting of all metadata and data).
        - Check if archive metadata chunk is present; if not, remove archive from manifest.
        - For all files (items) in the archive, for all chunks referenced by these
          files, check if chunk is present. In repair mode, if a chunk is not present,
          replace it with a same-size replacement chunk of zeroes. If a previously lost
          chunk reappears (e.g. via a later backup), in repair mode the all-zero replacement
          chunk will be replaced by the correct chunk. This requires reading of archive and
          file metadata, but not data.
        - In repair mode, when all the archives were checked, orphaned chunks are deleted
          from the repo. One cause of orphaned chunks are input file related errors (like
          read errors) in the archive creation process.
        - In verify-data mode, a complete cryptographic verification of the archive data
          integrity is performed. This conflicts with ``--repository-only`` as this mode
          only makes sense if the archive checks are enabled. The full details of this mode
          are documented below.
        - If checking a remote repo via ``ssh:``, the archive check is executed on the
          client machine because it requires decryption, and this is always done client-side
          as key access is needed.
        - The archive checks can be time consuming; they can be skipped using the
          ``--repository-only`` option.

        The ``--verify-data`` option will perform a full integrity verification (as opposed to
        checking the CRC32 of the segment) of data, which means reading the data from the
        repository, decrypting and decompressing it. This is a cryptographic verification,
        which will detect (accidental) corruption. For encrypted repositories it is
        tamper-resistant as well, unless the attacker has access to the keys. It is also very
        slow.
        rzverify repositoryz-repository or archive to check consistency ofz--repository-onlyrzonly perform repository checksz--archives-onlyr
zonly perform archives checksz
--verify-datarz`perform cryptographic archive data integrity verification (conflicts with ``--repository-only``)z--repairr�z+attempt to repair any inconsistencies foundz--save-spacerz!work slower, but using less spacer�z+Manage a keyfile or repokey of a repositoryzmanage repository key)r�a�
        If repository encryption is used, the repository is inaccessible
        without the key. This command allows to backup this essential key.
        Note that the backup produced does not include the passphrase itself
        (i.e. the exported key stays encrypted). In order to regain access to a
        repository, one needs both the exported key and the original passphrase.

        There are two backup formats. The normal backup format is suitable for
        digital storage as a file. The ``--paper`` backup format is optimized
        for printing and typing in while importing, with per line checks to
        reduce problems with manual input.

        For repositories using keyfile encryption the key is saved locally
        on the system that is capable of doing backups. To guard against loss
        of this key, the key needs to be backed up independently of the main
        data backup.

        For repositories using the repokey encryption the key is saved in the
        repository in the config file. A backup is thus not strictly needed,
        but guards against the repository becoming inaccessible if the file
        is damaged for some reason.

        Examples::

            borg key export /path/to/repo > encrypted-key-backup
            borg key export --paper /path/to/repo > encrypted-key-backup.txt
            borg key export --qr-html /path/to/repo > encrypted-key-backup.html
            # Or pass the output file as an argument instead of redirecting stdout:
            borg key export /path/to/repo encrypted-key-backup
            borg key export --paper /path/to/repo encrypted-key-backup.txt
            borg key export --qr-html /path/to/repo encrypted-key-backup.html


        rz export repository key for backup)rr1r�r�r�zwhere to store the backupz--paperrz8Create an export suitable for printing and later type-inz	--qr-htmlrzFCreate an html file suitable for printing and later type-in or qr scanaN
        This command allows to restore a key previously backed up with the
        export command.

        If the ``--paper`` option is given, the import will be an interactive
        process in which each line is checked for plausibility before
        proceeding to the next line. For this format PATH must not be given.
        �importz!import repository key from backupz+path to the backup ('-' to read from stdin)z8interactively import from a backup done with ``--paper``a�
        The key files used for repository encryption are optionally passphrase
        protected. This command can be used to change this passphrase.

        Please note that this command only changes the passphrase, but not any
        secret protected by it (like e.g. encryption/MAC keys or chunker seed).
        Thus, changing the passphrase after passphrase and borg key got compromised
        does not protect future (nor past) backups to the same repository.
        zchange-passphrasezchange repository passphrasea�
        This command migrates a repository from passphrase mode (removed in Borg 1.0)
        to repokey mode.

        You will be first asked for the repository passphrase (to open it in passphrase
        mode). This is the same passphrase as you used to use for this repo before 1.0.

        It will then derive the different secrets from this passphrase.

        Then you will be asked for a new passphrase (twice, for safety). This
        passphrase will be used to protect the repokey (which contains these same
        secrets in encrypted form). You may use the same passphrase as you used to
        use, but you may also use a different one.

        After migrating to repokey mode, you can change the passphrase at any time.
        But please note: the secrets will always stay the same and they could always
        be derived from your (old) passphrase-mode passphrase.
        zmigrate-to-repokeyz-migrate passphrase-mode repository to repokeya�"
        This command creates a backup archive containing all files found while recursively
        traversing all paths specified. Paths are added to the archive as they are given,
        that means if relative paths are desired, the command has to be run from the correct
        directory.

        When giving '-' as path, borg will read data from standard input and create a
        file 'stdin' in the created archive from that data. See section *Reading from
        stdin* below for details.

        The archive will consume almost no disk space for files or parts of files that
        have already been stored in other archives.

        The archive name needs to be unique. It must not end in '.checkpoint' or
        '.checkpoint.N' (with N being a number), because these names are used for
        checkpoints and treated in special ways.

        In the archive name, you may use the following placeholders:
        {now}, {utcnow}, {fqdn}, {hostname}, {user} and some others.

        Backup speed is increased by not reprocessing files that are already part of
        existing archives and weren't modified. The detection of unmodified files is
        done by comparing multiple file metadata values with previous values kept in
        the files cache.

        This comparison can operate in different modes as given by ``--files-cache``:

        - ctime,size,inode (default)
        - mtime,size,inode (default behaviour of borg versions older than 1.1.0rc4)
        - ctime,size (ignore the inode number)
        - mtime,size (ignore the inode number)
        - rechunk,ctime (all files are considered modified - rechunk, cache ctime)
        - rechunk,mtime (all files are considered modified - rechunk, cache mtime)
        - disabled (disable the files cache, all files considered modified - rechunk)

        inode number: better safety, but often unstable on network filesystems

        Normally, detecting file modifications will take inode information into
        consideration to improve the reliability of file change detection.
        This is problematic for files located on sshfs and similar network file
        systems which do not provide stable inode numbers, such files will always
        be considered modified. You can use modes without `inode` in this case to
        improve performance, but reliability of change detection might be reduced.

        ctime vs. mtime: safety vs. speed

        - ctime is a rather safe way to detect changes to a file (metadata and contents)
          as it can not be set from userspace. But, a metadata-only change will already
          update the ctime, so there might be some unnecessary chunking/hashing even
          without content changes. Some filesystems do not support ctime (change time).
          E.g. doing a chown or chmod to a file will change its ctime.
        - mtime usually works and only updates if file contents were changed. But mtime
          can be arbitrarily set from userspace, e.g. to set mtime back to the same value
          it had before a content change happened. This can be used maliciously as well as
          well-meant, but in both cases mtime based cache modes can be problematic.

        The mount points of filesystems or filesystem snapshots should be the same for every
        creation of a new archive to ensure fast operation. This is because the file cache that
        is used to determine changed files quickly uses absolute filenames.
        If this is not possible, consider creating a bind mount to a stable location.

        The ``--progress`` option shows (from left to right) Original, Compressed and Deduplicated
        (O, C and D, respectively), then the Number of files (N) processed so far, followed by
        the currently processed path.

        When using ``--stats``, you will get some statistics about how much data was
        added - the "This Archive" deduplicated size there is most interesting as that is
        how much your repository will grow. Please note that the "All archives" stats refer to
        the state after creation. Also, the ``--stats`` and ``--dry-run`` options are mutually
        exclusive because the data is not actually compressed and deduplicated during a dry run.

        For more help on include/exclude patterns, see the :ref:`borg_patterns` command output.

        For more help on placeholders, see the :ref:`borg_placeholders` command output.

        .. man NOTES

        The ``--exclude`` patterns are not like tar. In tar ``--exclude`` .bundler/gems will
        exclude foo/.bundler/gems. In borg it will not, you need to use ``--exclude``
        '\*/.bundler/gems' to get the same effect.

        In addition to using ``--exclude`` patterns, it is possible to use
        ``--exclude-if-present`` to specify the name of a filesystem object (e.g. a file
        or folder name) which, when contained within another folder, will prevent the
        containing folder from being backed up.  By default, the containing folder and
        all of its contents will be omitted from the backup.  If, however, you wish to
        only include the objects specified by ``--exclude-if-present`` in your backup,
        and not include any other contents of the containing folder, this can be enabled
        through using the ``--keep-exclude-tags`` option.

        The ``-x`` or ``--one-file-system`` option excludes directories, that are mountpoints (and everything in them).
        It detects mountpoints by comparing the device number from the output of ``stat()`` of the directory and its
        parent directory. Specifically, it excludes directories for which ``stat()`` reports a device number different
        from the device number of their parent. Be aware that in Linux (and possibly elsewhere) there are directories
        with device number different from their parent, which the kernel does not consider a mountpoint and also the
        other way around. Examples are bind mounts (possibly same device number, but always a mountpoint) and ALL
        subvolumes of a btrfs (different device number from parent but not necessarily a mountpoint). Therefore when
        using ``--one-file-system``, one should make doubly sure that the backup works as intended especially when using
        btrfs. This is even more important, if the btrfs layout was created by someone else, e.g. a distribution
        installer.


        .. _list_item_flags:

        Item flags
        ++++++++++

        ``--list`` outputs a list of all files, directories and other
        file system items it considered (no matter whether they had content changes
        or not). For each item, it prefixes a single-letter flag that indicates type
        and/or status of the item.

        If you are interested only in a subset of that output, you can give e.g.
        ``--filter=AME`` and it will only show regular files with A, M or E status (see
        below).

        A uppercase character represents the status of a regular file relative to the
        "files" cache (not relative to the repo -- this is an issue if the files cache
        is not used). Metadata is stored in any case and for 'A' and 'M' also new data
        chunks are stored. For 'U' all data chunks refer to already existing chunks.

        - 'A' = regular file, added (see also :ref:`a_status_oddity` in the FAQ)
        - 'M' = regular file, modified
        - 'U' = regular file, unchanged
        - 'E' = regular file, an error happened while accessing/reading *this* file

        A lowercase character means a file type other than a regular file,
        borg usually just stores their metadata:

        - 'd' = directory
        - 'b' = block device
        - 'c' = char device
        - 'h' = regular file, hardlink (to already seen inodes)
        - 's' = symlink
        - 'f' = fifo

        Other flags used include:

        - 'i' = backup data was read from standard input (stdin)
        - '-' = dry run, item was *not* backed up
        - 'x' = excluded, item was *not* backed up
        - '?' = missing status code (if you see this, please file a bug report!)

        Reading from stdin
        ++++++++++++++++++

        To read from stdin, specify ``-`` as path and pipe directly to borg::

            backup-vm --id myvm --stdout | borg create REPO::ARCHIVE -

        Note that piping to borg creates an archive even if the command piping
        to borg exits with a failure. In this case, **one can end up with
        truncated output being backed up**.

        Reading from stdin yields just a stream of data without file metadata
        associated with it, and the files cache is not needed at all. So it is
        safe to disable it via ``--no-files-cache`` and speed up backup
        creation a bit.

        By default, the content read from stdin is stored in a file called 'stdin'.
        Use ``--stdin-name`` to change the name.
        r�z
create backupz-nz	--dry-runrSzdo not create a backup archivez-sz--statsrpz(print statistics for the created archivez--listr�z/output verbose list of items (files, dirs, ...)z--filterZSTATUSCHARSr�zEonly display items with the given status characters (see description))rr�r�z--jsonz*output stats as JSON. Implies ``--stats``.)r�r�z--no-cache-syncr�zNexperimental: do not synchronize the cache. Implies not using the files cache.z--no-files-cacher�r�zIdo not load/update the file metadata cache used to detect unchanged filesz--stdin-namer�rer�z5use NAME in archive for stdin data (default: "stdin"))rr�r�r�z--stdin-userZUSERrgrz>set user USER in archive for stdin data (default: %(default)r)z
--stdin-groupZGROUPrhz@set group GROUP in archive for stdin data (default: %(default)r)z--stdin-moderrfcSs
t|d�S)Nr)r�)rrrr�r�$sz'Archiver.build_parser.<locals>.<lambda>z@set mode to M in archive for stdin data (default: %(default)04o))rz--exclude-nodumpr�zexclude files flagged NODUMPzFilesystem optionsz-xz--one-file-systemrjz�stay in the same file system and do not store mount points of other file systems.  This might behave different from your expectations, see the docs.z--numeric-ownerr�z-only store numeric user and group identifiersz	--noatimer{zdo not store atime into archivez	--noctimer|zdo not store ctime into archivez
--nobirthtimer}z3do not store birthtime (creation date) into archivez--nobsdflagsr�zDdo not read and store bsdflags (e.g. NODUMP, IMMUTABLE) into archivez--noaclsr�z'do not read and store ACLs into archivez
--noxattrsr�z)do not read and store xattrs into archivez--ignore-inoder�zLignore inode data in the file metadata cache used to detect unchanged files.z
--files-cacher�z(operate files cache in MODE. default: %sz--read-specialrWz�open and read block and char device files as well as FIFOs as if they were regular files. Also follows symlinks pointing to these kinds of files.zArchive optionsz	--commentrY�COMMENTz!add a comment text to the archive)r�rr�r�r�z--timestampZ	TIMESTAMPrDz�manually specify the archive creation date/time (UTC, yyyy-mm-ddThh:mm:ss format). Alternatively, give a reference file/directory.z-cz--checkpoint-intervalrrziz6write checkpoint every SECONDS seconds (Default: 1800)z--chunker-paramsZPARAMSr~zuspecify the chunker parameters (CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE). default: %d,%d,%d,%dz-Cz
--compressionZCOMPRESSIONr�Zlz4z`select compression algorithm, see the output of the "borg help compression" command for details.ZARCHIVEz?name of archive to create (must be also a valid directory name)zpaths to archivea�
        This command extracts the contents of an archive. By default the entire
        archive is extracted but a subset of files and directories can be selected
        by passing a list of ``PATHs`` as arguments. The file selection can further
        be restricted by using the ``--exclude`` option.

        For more help on include/exclude patterns, see the :ref:`borg_patterns` command output.

        By using ``--dry-run``, you can do all extraction steps except actually writing the
        output data: reading metadata and data chunks from the repo, checking the hash/hmac,
        decrypting, decompressing.

        ``--progress`` can be slower than no progress display, since it makes one additional
        pass over the archive metadata.

        .. note::

            Currently, extract always writes into the current working directory ("."),
            so make sure you ``cd`` to the right place before calling ``borg extract``.

            When parent directories are not extracted (because of using file/directory selection
            or any other reason), borg can not restore parent directories' metadata, e.g. owner,
            group, permission, etc.
        r%zextract archive contentsz do not actually change any filesz,only obey numeric user and group identifiersz4do not extract/set bsdflags (e.g. NODUMP, IMMUTABLE)zdo not extract/set ACLszdo not extract/set xattrsz--stdoutr�z"write all extracted data to stdoutz--sparser�z7create holes in output sparse file from all-zero chunkszarchive to extracta�
        This command creates a tarball from an archive.

        When giving '-' as the output FILE, Borg will write a tar stream to standard output.

        By default (``--tar-filter=auto``) Borg will detect whether the FILE should be compressed
        based on its file extension and pipe the tarball through an appropriate filter
        before writing it to FILE:

        - .tar.gz: gzip
        - .tar.bz2: bzip2
        - .tar.xz: xz

        Alternatively a ``--tar-filter`` program may be explicitly specified. It should
        read the uncompressed tar stream from stdin and write a compressed/filtered
        tar stream to stdout.

        The generated tarball uses the GNU tar format.

        export-tar is a lossy conversion:
        BSD flags, ACLs, extended attributes (xattrs), atime and ctime are not exported.
        Timestamp resolution is limited to whole seconds, not the nanosecond resolution
        otherwise supported by Borg.

        A ``--sparse`` option (as found in borg extract) is not supported.

        By default the entire archive is extracted but a subset of files and directories
        can be selected by passing a list of ``PATHs`` as arguments.
        The file selection can further be restricted by using the ``--exclude`` option.

        For more help on include/exclude patterns, see the :ref:`borg_patterns` command output.

        ``--progress`` can be slower than no progress display, since it makes one additional
        pass over the archive metadata.
        z
export-tarzcreate tarball from archivez--tar-filterr�r�z#filter program to pipe data through)r�r�r�zarchive to exportr�rz0output tar file. "-" to write to stdout instead.)rr�a�
            This command finds differences (file contents, user/group/mode) between archives.

            A repository location and an archive name must be specified for REPO::ARCHIVE1.
            ARCHIVE2 is just another archive name in same repository (no repository location
            allowed).

            For archives created with Borg 1.1 or newer diff automatically detects whether
            the archives are created with the same chunker params. If so, only chunk IDs
            are compared, which is very fast.

            For archives prior to Borg 1.1 chunk contents are compared by default.
            If you did not create the archives with different chunker params,
            pass ``--same-chunker-params``.
            Note that the chunker params changed from Borg 0.xx to 1.0.

            For more help on include/exclude patterns, see the :ref:`borg_patterns` command output.
            rz$find differences in archive contentsz0only consider numeric user and group identifiersz--same-chunker-paramsrz%Override check of chunker parameters.z--sortr	z#Sort the output lines by file path.z--json-lineszFormat output as JSON Lines. zREPO::ARCHIVE1z%repository location and ARCHIVE1 namer�ZARCHIVE2z.ARCHIVE2 name (no repository location allowed)zEpaths of items inside the archives to compare; patterns are supportedzu
        This command renames an archive in the repository.

        This results in a different archive ID.
        r!zrename archivezarchive to renamer�ZNEWNAMEzthe new archive name to usea#
        This command deletes an archive from the repository or the complete repository.
        Disk space is reclaimed accordingly. If you delete the complete repository, the
        local cache for it (if any) is also deleted.

        When using ``--stats``, you will get some statistics about how much data was
        deleted - the "Deleted data" deduplicated size there is most interesting as
        that is how much your repository will shrink.
        Please note that the "All archives" stats refer to the state after deletion.
        r#zdelete archivezdo not change repositoryz(print statistics for the deleted archivez--cache-onlyr3z4delete only the local cache for the given repositoryz--forcer&r9z`force deletion of corrupted archives, use ``--force --force`` in case ``--force`` does not work.)r�r�r�r�zrepository or archive to deleter#zarchives to delete)rr1r�ah
        This command lists the contents of a repository or an archive.

        For more help on include/exclude patterns, see the :ref:`borg_patterns` command output.

        .. man NOTES

        The FORMAT specifier syntax
        +++++++++++++++++++++++++++

        The ``--format`` option uses python's `format string syntax
        <https://docs.python.org/3.8/library/string.html#formatstrings>`_.

        Examples:
        ::

            $ borg list --format '{archive}{NL}' /path/to/repo
            ArchiveFoo
            ArchiveBar
            ...

            # {VAR:NUMBER} - pad to NUMBER columns.
            # Strings are left-aligned, numbers are right-aligned.
            # Note: time columns except ``isomtime``, ``isoctime`` and ``isoatime`` cannot be padded.
            $ borg list --format '{archive:36} {time} [{id}]{NL}' /path/to/repo
            ArchiveFoo                           Thu, 2021-12-09 10:22:28 [0b8e9a312bef3f2f6e2d0fc110c196827786c15eba0188738e81697a7fa3b274]
            $ borg list --format '{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}' /path/to/repo::ArchiveFoo
            -rw-rw-r-- user   user       1024 Thu, 2021-12-09 10:22:17 file-foo
            ...

            # {VAR:<NUMBER} - pad to NUMBER columns left-aligned.
            # {VAR:>NUMBER} - pad to NUMBER columns right-aligned.
            $ borg list --format '{mode} {user:>6} {group:>6} {size:<8} {mtime} {path}{extra}{NL}' /path/to/repo::ArchiveFoo
            -rw-rw-r--   user   user 1024     Thu, 2021-12-09 10:22:17 file-foo
            ...

        The following keys are always available:


        zN

        Keys available only when listing archives in a repository:

        zI

        Keys available only when listing files in an archive:

        r�z#list archive or repository contentsz--shortrKz-only print file/directory names, nothing elsez--formatz
--list-formatZFORMATrz�specify format for file or archive listing (default for files: "{mode} {user:6} {group:6} {size:8} {mtime} {path}{extra}{NL}"; for archives: "{archive:<36} {time} [{id}]{NL}")aOnly valid for listing repository contents. Format output as JSON. The form of ``--format`` is ignored, but keys used in it are added to the JSON output. Some keys are always present. Note: JSON can only represent text. A "barchive" key is therefore not available.aOnly valid for listing archive contents. Format output as JSON Lines. The form of ``--format`` is ignored, but keys used in it are added to the JSON output. Some keys are always present. Note: JSON can only represent text. A "bpath" key is therefore not available.z)repository or archive to list contents ofz%paths to list; patterns are supportedz�
        This command un-mounts a FUSE filesystem that was mounted with ``borg mount``.

        This is a convenience wrapper that just calls the platform-specific shell
        command - usually this is either umount or fusermount -u.
        r^zumount repositoryz&mountpoint of the filesystem to umounta{
        This command displays detailed information about the specified archive or repository.

        Please note that the deduplicated sizes of the individual archives do not add
        up to the deduplicated size of the repository ("all archives"), because the two
        are meaning different things:

        This archive / deduplicated size = amount of data stored ONLY for this archive
        = unique chunks of this archive.
        All archives / deduplicated size = amount of data stored in the repo
        = all chunks in the repository.

        Borg archives can only contain a limited amount of file metadata.
        The size of an archive relative to this limit depends on a number of factors,
        mainly the number of files, the lengths of paths and other metadata stored for files.
        This is shown as *utilization of maximum supported archive size*.
        r�z&show repository or archive informationz2repository or archive to display information aboutzformat output as JSONz�
        This command breaks the repository and cache locks.
        Please use carefully and only while no borg process (on any machine) is
        trying to access the Cache or the Repository.
        z
break-lockz break repository and cache locksz'repository for which to break the locksa�
        The prune command prunes a repository by deleting all archives not matching
        any of the specified retention options. This command is normally used by
        automated backup scripts wanting to keep a certain number of historic backups.
        This retention policy is commonly referred to as
        `GFS <https://en.wikipedia.org/wiki/Backup_rotation_scheme#Grandfather-father-son>`_
        (Grandfather-father-son) backup rotation scheme.

        Also, prune automatically removes checkpoint archives (incomplete archives left
        behind by interrupted backup runs) except if the checkpoint is the latest
        archive (and thus still needed). Checkpoint archives are not considered when
        comparing archive counts against the retention limits (``--keep-X``).

        If a prefix is set with -P, then only archives that start with the prefix are
        considered for deletion and only those archives count towards the totals
        specified by the rules.
        Otherwise, *all* archives in the repository are candidates for deletion!
        There is no automatic distinction between archives representing different
        contents. These need to be distinguished by specifying matching prefixes.

        If you have multiple sequences of archives with different data sets (e.g.
        from different machines) in one shared repository, use one prune call per
        data set that matches only the respective archives using the -P option.

        The ``--keep-within`` option takes an argument of the form "<int><char>",
        where char is "H", "d", "w", "m", "y". For example, ``--keep-within 2d`` means
        to keep all archives that were created within the past 48 hours.
        "1m" is taken to mean "31d". The archives kept with this option do not
        count towards the totals specified by any other options.

        A good procedure is to thin out more and more the older your backups get.
        As an example, ``--keep-daily 7`` means to keep the latest backup on each day,
        up to 7 most recent days with backups (days without backups do not count).
        The rules are applied from secondly to yearly, and backups selected by previous
        rules do not count towards those of later rules. The time that each backup
        starts is used for pruning purposes. Dates and times are interpreted in
        the local timezone, and weeks go from Monday to Sunday. Specifying a
        negative number of archives to keep means that there is no limit.

        The ``--keep-last N`` option is doing the same as ``--keep-secondly N`` (and it will
        keep the last N archives under the assumption that you do not create more than one
        backup archive in the same second).

        When using ``--stats``, you will get some statistics about how much data was
        deleted - the "Deleted data" deduplicated size there is most interesting as
        that is how much your repository will shrink.
        Please note that the "All archives" stats refer to the state after pruning.
        r\zprune archivesz_force pruning of corrupted archives, use ``--force --force`` in case ``--force`` does not work.z/output verbose list of archives it keeps/prunesz
--keep-withinZINTERVALrdz+keep all archives within this time interval)rr�r�r�z--keep-lastz--keep-secondlyr]z#number of secondly archives to keep)r�r�r�r�z--keep-minutelyr^z#number of minutely archives to keepz-Hz
--keep-hourlyr_z!number of hourly archives to keepz-dz--keep-dailyr`z number of daily archives to keepz-wz
--keep-weeklyraz!number of weekly archives to keepz-mz--keep-monthlyrbz"number of monthly archives to keepz-yz
--keep-yearlyrcz!number of yearly archives to keepzrepository to pruneal
        Upgrade an existing, local Borg repository.

        When you do not need borg upgrade
        +++++++++++++++++++++++++++++++++

        Not every change requires that you run ``borg upgrade``.

        You do **not** need to run it when:

        - moving your repository to a different place
        - upgrading to another point release (like 1.0.x to 1.0.y),
          except when noted otherwise in the changelog
        - upgrading from 1.0.x to 1.1.x,
          except when noted otherwise in the changelog

        Borg 1.x.y upgrades
        +++++++++++++++++++

        Archive TAM authentication:

        Use ``borg upgrade --archives-tam REPO`` to add archive TAMs to all
        archives that are not TAM authenticated yet.
        This is a convenient method to just trust all archives present - if
        an archive does not have TAM authentication yet, a TAM will be added.
        Archives created by old borg versions < 1.0.9 do not have TAMs.
        Archives created by newer borg version should have TAMs already.
        If you have a high risk environment, you should not just run this,
        but first verify that the archives are authentic and not malicious
        (== have good content, have a good timestamp).
        Borg 1.2.5+ needs all archives to be TAM authenticated for safety reasons.

        This upgrade needs to be done once per repository.

        Manifest TAM authentication:

        Use ``borg upgrade --tam REPO`` to require manifest authentication
        introduced with Borg 1.0.9 to address security issues. This means
        that modifying the repository after doing this with a version prior
        to 1.0.9 will raise a validation error, so only perform this upgrade
        after updating all clients using the repository to 1.0.9 or newer.

        This upgrade should be done on each client for safety reasons.

        If a repository is accidentally modified with a pre-1.0.9 client after
        this upgrade, use ``borg upgrade --tam --force REPO`` to remedy it.

        If you routinely do this you might not want to enable this upgrade
        (which will leave you exposed to the security issue). You can
        reverse the upgrade by issuing ``borg upgrade --disable-tam REPO``.

        See
        https://borgbackup.readthedocs.io/en/stable/changes.html#pre-1-0-9-manifest-spoofing-vulnerability
        for details.

        Attic and Borg 0.xx to Borg 1.x
        +++++++++++++++++++++++++++++++

        This currently supports converting an Attic repository to Borg and also
        helps with converting Borg 0.xx to 1.0.

        Currently, only LOCAL repositories can be upgraded (issue #465).

        Please note that ``borg create`` (since 1.0.0) uses bigger chunks by
        default than old borg or attic did, so the new chunks won't deduplicate
        with the old chunks in the upgraded repository.
        See ``--chunker-params`` option of ``borg create`` and ``borg recreate``.

        ``borg upgrade`` will change the magic strings in the repository's
        segments to match the new Borg magic strings. The keyfiles found in
        $ATTIC_KEYS_DIR or ~/.attic/keys/ will also be converted and
        copied to $BORG_KEYS_DIR or ~/.config/borg/keys.

        The cache files are converted, from $ATTIC_CACHE_DIR or
        ~/.cache/attic to $BORG_CACHE_DIR or ~/.cache/borg, but the
        cache layout between Borg and Attic changed, so it is possible
        the first backup after the conversion takes longer than expected
        due to the cache resync.

        Upgrade should be able to resume if interrupted, although it
        will still iterate over all segments. If you want to start
        from scratch, use `borg delete` over the copied repository to
        make sure the cache files are also removed::

            borg delete borg

        Unless ``--inplace`` is specified, the upgrade process first creates a backup
        copy of the repository, in REPOSITORY.before-upgrade-DATETIME, using hardlinks.
        This requires that the repository and its parent directory reside on same
        filesystem so the hardlink copy can work.
        This takes longer than in place upgrades, but is much safer and gives
        progress information (as opposed to ``cp -al``). Once you are satisfied
        with the conversion, you can safely destroy the backup copy.

        WARNING: Running the upgrade in place will make the current
        copy unusable with older version, with no way of going back
        to previous versions. This can PERMANENTLY DAMAGE YOUR
        REPOSITORY!  Attic CAN NOT READ BORG REPOSITORIES, as the
        magic strings have changed. You have been warned.rtzupgrade repository formatz	--inplacernz^rewrite repository in place, with no chance of going back to older versions of the repository.rpz
Force upgradez--tamrizIEnable manifest authentication (in key and cache) (Borg 1.0.9 and later).z
--disable-tamrjz3Disable manifest authentication (in key and cache).z--archives-tamrkz(add TAM authentication for all archives.z%path to the repository to be upgradeda5
        Recreate the contents of existing archives.

        recreate is a potentially dangerous function and might lead to data loss
        (if used wrongly). BE VERY CAREFUL!

        ``--exclude``, ``--exclude-from``, ``--exclude-if-present``, ``--keep-exclude-tags``
        and PATH have the exact same semantics as in "borg create", but they only check
        for files in the archives and not in the local file system. If PATHs are specified,
        the resulting archives will only contain files from these PATHs.

        Note that all paths in an archive are relative, therefore absolute patterns/paths
        will *not* match (``--exclude``, ``--exclude-from``, PATHs).

        ``--recompress`` allows to change the compression of existing data in archives.
        Due to how Borg stores compressed size information this might display
        incorrect information for archives that were not recreated at the same time.
        There is no risk of data loss by this.

        ``--chunker-params`` will re-chunk all files in the archive, this can be
        used to have upgraded Borg 0.xx or Attic archives deduplicate with
        Borg 1.x archives.

        **USE WITH CAUTION.**
        Depending on the PATHs and patterns given, recreate can be used to permanently
        delete files from archives.
        When in doubt, use ``--dry-run --verbose --list`` to see how patterns/PATHS are
        interpreted. See :ref:`list_item_flags` in ``borg create`` for details.

        The archive being recreated is only removed after the operation completes. The
        archive that is built during the operation exists at the same time at
        "<ARCHIVE>.recreate". The new archive will have a different archive ID.

        With ``--target`` the original archive is not replaced, instead a new archive is created.

        When rechunking space usage can be substantial, expect at least the entire
        deduplicated size of the archives using the previous chunker params.
        When recompressing expect approx. (throughput / checkpoint-interval) in space usage,
        assuming all chunks are recompressed.

        If you recently ran borg check --repair and it had to fix lost chunks with all-zero
        replacement chunks, please first run another backup for the same data and re-run
        borg check --repair afterwards to heal any archives that had lost chunks which are
        still generated from the input data.

        Important: running borg recreate to re-chunk will remove the chunks_healthy
        metadata of all items with replacement chunks, so healing will not be possible
        any more after re-chunking (it is also unlikely it would ever work: due to the
        change of chunking parameters, the missing chunk likely will never be seen again
        even if you still have the data that produced it).
        r|zRonly display items with the given status characters (listed in borg create --help)zdo not change anythingzprint statistics at endz--targetrZTARGETzocreate a new archive with the name ARCHIVE, do not replace existing archive (only applies for a single archive))r�rr�r�r�)r�r�r�rr�z�manually specify the archive creation date/time (UTC, yyyy-mm-ddThh:mm:ss format). alternatively, give a reference file/directory.z--recompressrzrx�if-differentryajrecompress data chunks according to ``--compression``. MODE `if-different`: recompress if current compression is with a different compression algorithm (the level is not considered). MODE `always`: recompress even if current compression is with the same compression algorithm (use this to change the compression level). MODE `never` (default): do not recompress.)rr�r1r�rr2r�z�specify the chunker parameters (CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE) or `default` to use the current defaults. default: %d,%d,%d,%dz!repository or archive to recreatez)paths to recreate; patterns are supporteda�
        This command runs a user-specified command while the repository lock is held.

        It will first try to acquire the lock (make sure that no other operation is
        running in the repo), then execute the given command as a subprocess and wait
        for its termination, release the lock and return the user command's return
        code as borg's return code.

        .. note::

            If you copy a repository with the lock held, the lock will be present in
            the copy. Thus, before using borg on the copy from a different host,
            you need to use "borg break-lock" on the copied repository, because
            Borg is cautious and does not automatically remove stale locks made by a different host.
        z	with-lockzrun user command with lock heldzrepository to lockr�ZCOMMANDzcommand to runr~ZARGSzcommand argumentsa
        This command gets and sets options in a local repository or cache config file.
        For security reasons, this command only works on local repositories.

        To delete a config value entirely, use ``--delete``. To list the values
        of the configuration file or the default values, use ``--list``.  To get and existing
        key, pass only the key name. To set a key, pass both the key name and
        the new value. Keys can be specified in the format "section.name" or
        simply "name"; the section will default to "repository" and "cache" for
        the repo and cache configs, respectively.


        By default, borg config manipulates the repository config file. Using ``--cache``
        edits the repository cache's config file instead.
        rrz get and set configuration valuesz--cacher�z&get and set values from the repo cachez--deletez#delete the key from the config filez-lz"list the configuration of the repor�)r�r�zrepository to configurezname of config keyr�ZVALUEznew value for keyr�z
Extra help)r/r*r)z
--epilog-onlyr�)r�r�z--usage-onlyr�r�rzadditional help on TOPIC)rr�r1r�al
        These commands are not intended for normal use and potentially very
        dangerous if used incorrectly.

        They exist to improve debugging capabilities without direct system access, e.g.
        in case you ever run into some severe malfunction. Use them only if you know
        what you are doing or if a trusted developer tells you what to do.rcz/debugging command (not intended for normal use)z�
        This command displays some system information that might be useful for bug
        reports and debugging problems. If a traceback happens, this information is
        already appended at the end of the traceback.
        z5show system infos for debugging / bug reports (debug)zq
        This command dumps raw (but decrypted and decompressed) archive items (only metadata) to files.
        zdump-archive-itemsz%dump archive items (metadata) (debug)zarchive to dumpz\
        This command dumps all metadata of an archive in a decoded form to a file.
        zdump-archivez%dump decoded archive metadata (debug)zfile to dump data intozc
        This command dumps manifest metadata of a repository in a decoded form to a file.
        z
dump-manifestz(dump decoded repository metadata (debug)zrepository to dumpz`
        This command dumps raw (but decrypted and decompressed) repo objects to files.
        zdump-repo-objszdump repo objects (debug)z--ghostr�zRdump all segment file contents, including deleted/uncommitted objects and commits.zx
        This command searches raw (but decrypted and decompressed) repo objects for a specific bytes sequence.
        zsearch-repo-objszsearch repo objects (debug)zrepository to searchr�ZWANTEDzCterm to search the repo for, either 0x1234abcd hex term or a stringzB
        This command gets an object from the repository.
        zget-objz"get object from repository (debug)zrepository to userZIDz"hex object ID to get from the repozfile to write object data intoz@
        This command puts objects into the repository.
        zput-objz put object to repository (debug)�+z)file(s) to read and create object(s) fromzC
        This command deletes objects from the repository.
        z
delete-objz%delete object from repository (debug)r�ZIDsz(hex object ID(s) to delete from the repoz\
        This command displays the reference count for objects from the repository.
        zrefcount-objz0show refcount for object from repository (debug)z&hex object ID(s) to show refcounts forz?
        This command dumps the repository hints data.
        z
dump-hintszdump repo hints (debug)zQ
        Convert a Borg profile to a Python cProfile compatible profile.
        zconvert-profilez.convert Borg profile to Python profile (debug)r�ZINPUTr�zBorg profiler�ZOUTPUTr�zOutput filez%These commands do various benchmarks.Z	benchmarkzbenchmark commandaV	
        This command benchmarks borg CRUD (create, read, update, delete) operations.

        It creates input data below the given PATH and backups this data into the given REPO.
        The REPO must already exist (it could be a fresh empty repo or an existing repo, the
        command will create / read / update / delete some archives named borg-benchmark-crud\* there.

        Make sure you have free space there, you'll need about 1GB each (+ overhead).

        If your repository is encrypted and borg needs a passphrase to unlock the key, use::

            BORG_PASSPHRASE=mysecret borg benchmark crud REPO PATH

        Measurements are done with different input file sizes and counts.
        The file contents are very artificial (either all zero or all random),
        thus the measurement results do not necessarily reflect performance with real data.
        Also, due to the kind of content used, no compression is used in these benchmarks.

        C- == borg create (1st archive creation, no compression, do not use files cache)
              C-Z- == all-zero files. full dedup, this is primarily measuring reader/chunker/hasher.
              C-R- == random files. no dedup, measuring throughput through all processing stages.

        R- == borg extract (extract archive, dry-run, do everything, but do not write files to disk)
              R-Z- == all zero files. Measuring heavily duplicated files.
              R-R- == random files. No duplication here, measuring throughput through all processing
              stages, except writing to disk.

        U- == borg create (2nd archive creation of unchanged input files, measure files cache speed)
              The throughput value is kind of virtual here, it does not actually read the file.
              U-Z- == needs to check the 2 all-zero chunks' existence in the repo.
              U-R- == needs to check existence of a lot of different chunks in the repo.

        D- == borg delete archive (delete last remaining archive, measure deletion + compaction)
              D-Z- == few chunks to delete / few segments to compact/remove.
              D-R- == many chunks to delete / many segments to compact/remove.

        Please note that there might be quite some variance in these measurements.
        Try multiple measurements and having a otherwise idle machine (and network, if you use it).
        Zcrudz7benchmarks borg CRUD (create, extract, update, delete).z,repository to use for benchmark (must exist)z(path were to create benchmark input data)r+r,r-)rxr5ry)Wr��ArgumentParserr�Zset_defaultsr��partial�do_maincommand_helprr�r�rrr>r
r)r�ZRawDescriptionHelpFormatterr0r�Zadd_subparsersZ
add_parserr,r�r�r�r�rrr�rrrrr r(rarbZSTDIN_MODE_DEFAULTrr5ZFILES_CACHE_MODE_UI_DEFAULTr2rDr�r.ZCHUNKER_PARAMSrr+r�r r-r"r*r6Z	keys_helprRrSr8r7rGrDrOr�rhrArwr}r�Z	REMAINDERr�r'r�r2r�r�r�r�r�r�r�r�r�r�r�r�ZFileTyperR)7r�rr�r$r(r�Z
common_parserZmid_common_parserZmount_epilogr"Z
subparsersZserve_epilogZinit_epilogZcheck_epilogZkey_parsersZkey_export_epilogZkey_import_epilogZchange_passphrase_epilogZmigrate_to_repokey_epilogZ
create_epilogr#Zfs_groupZ
archive_groupZextract_epilogZexport_tar_epilogZdiff_epilogZ
rename_epilogZ
delete_epilogZlist_epilogZ
umount_epilogZinfo_epilogZbreak_lock_epilogZprune_epilogZupgrade_epilogZrecreate_epilogZwith_lock_epilogZ
config_epilogrvZdebug_epilogZ
debug_parsersZdebug_info_epilogZdebug_dump_archive_items_epilogZdebug_dump_archive_epilogZdebug_dump_manifest_epilogZdebug_dump_repo_objs_epilogZdebug_search_repo_objs_epilogZdebug_get_obj_epilogZdebug_put_obj_epilogZdebug_delete_obj_epilogZdebug_refcount_obj_epilogZdebug_dump_hints_epilogZdebug_convert_profile_epilogZbenchmark_epilogZbenchmark_parsersZbench_crud_epilogr)r!rr��build_parser�
s�
/

6







7




!


"







































"


















	





1:















/







b







2










	




















































&

zArchiver.build_parsercCs�|j|dd��}|dk	r�|j|jkr�tj|�}ttjdd�|��}|j|dd��}|j|jkr�ddddh}d	d
ddh}t�}x@|D]8}	|	|ks�t	d
|	��t
||	|�}
|
|k	r�t||	|
�q�W|S)zWusually, just returns argv, except if we deal with a ssh forced command for borg serve.rNcSsd|kS)N�=r)rlrrr�r�Isz#Archiver.get_args.<locals>.<lambda>r�r�r�r�rr�rrz*allowlist has denylisted attribute name %s)r)r�r�r�r�r��	itertools�	dropwhiler�r�r{r)r��argv�cmdr�Zclient_argvZ
client_resultZdenylistZ	allowlistZnot_presentZ	attr_namer�rrr��get_args>s*

zArchiver.get_argsc	Cs�|r|j|�}|j�}|j|p"dg�}|jj|�t|�}||jkrV|jrV|jd�t	|dd�s�|j
|j|j|j
|j|j|j|j|jh	}||kr�td��t	|dd�r�|jj|j�|_|S)Nz-hz Need at least one PATH argument.r�Tz:Not allowed to bypass locking mechanism for chosen commandrD)r�r:r)r�rr�r(rdr�r{rr�r r�r+rOrGr>rDr(r�Zwith_timestamprD)r�r~r�r�Zbypass_allowedrrr�r)is"

zArchiver.parse_argscCs|s
t�t�t|�dS)N)rIrJrw)r�r��is_serverrr��
prerun_checks~szArchiver.prerun_checkscCsNdddddd�}x8|j�D],\}}|j|d�}tj|�j|r@dnd	�qWd
S)zN turn on INFO level logging for args that imply that they will produce output zborg.output.listzborg.output.show-versionzborg.output.show-rczborg.output.statszborg.output.progress)r�rrrpr�F�INFOZWARNN)r�r�r�r��setLevel)r�r~Z
option_loggerZoptionZlogger_nameZ
option_setrrr��_setup_implied_logging�szArchiver._setup_implied_loggingcCs@x:|jD]0}d|krd|}tjd|�tj|�jd�qWdS)z9Turn on DEBUG level logging for specified --debug-topics.r�zborg.debug.zEnabling debug topic %s�DEBUGN)rr�rcr�r�rD)r�r~r�rrr��_setup_topic_debugging�s
zArchiver._setup_topic_debuggingc	Cs�tj|j�|j|_t|�}||jk}t|j||jd�|j|_|j|O_|j	t
|��|j|�t|dd�r�t|dd�r�t
jd�d|_|jr�tjd�jdt�|jt
|�t�s�t
jd�t
jd	�t
jd
�tt�St�r�t
jt�|j�r�ddl}ddl}t
jd|j�t |jd
��p}|j!�}t"t#��}|j$�zt||��S|j%�|j&�|jj'd��rz|j(|j|�nt)j*|j|dd�XWdQRXnt||��SdS)N)�levelrAr�rpFrSz;Ignoring --stats. It is not supported when using --dry-run.zborg.output.show-versionzborgbackup version %szLYou do not have a supported msgpack[-python] version installed. Terminating.zVThis should never happen as specific, supported versions are required by our setup.py.z-Do not contact borgbackup support about this.rzWriting execution profile to %sr�z.pyprofT)Zuse_bin_type)+rrr�r�r�r
rr�r�rE�varsrGr{r�r�rprr�r�r�rrBrMr�r*r&rL�PURE_PYTHON_MSGPACK_WARNINGr�cProfiler�rcr�ZProfiler��locals�enable�disableZsnapshot_statsr�r�r_�pack)	r�r~r�rArKr�r>Zprofiler�	variablesrrr��run�sL








 zArchiver.run)NN)NN)FFN)rirjrk)NN)N)Sr�rr	r�r�r�r��staticmethodr�r�r�r�r�rrFr(rorrrrr rRr�r(rkr�ZREADr�r+r�r�r r"r*r$r%r>r<rDrGrErFrOrMrNr)rhrwr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�rRrSr�r�r9r�rr:r@r)rBrErGrQrrrr�r��s�

'
O`
ZSw	
F80 PJ+x	28CZ
9
8
~`+
r�cCs�t|tj���x�tj|�D]�}|d|dj}}|d
kr�|d}y|dj�}|dj}Wntk
rxd\}}YnXt	j
dj|t|�t|���P|dkr|d
j
}y|dj�}Wntk
r�d}YnXt	j
dj|t|���PqWWdQRXdS)zLsearch the stack for infos about the currently processed file and print them�rr�rkr�r>rXz{0} {1}/{2}r�r}z{0} {1}/???N)r�rk)rr)r�)rQ�signal�SIG_IGN�inspectZgetouterframes�f_locals�tell�st_sizer�r�r�rr:r�)�sig_no�stack�framer��locr��posr�rrr��sig_info_handler�s(

r_cCs*tdtj�jdd�tjd�tj�dS)Nz)
Received SIGUSR2 at %s, dumping trace...r)Zmicrosecond)r�)r�rZnowr�r�r��faulthandlerZdump_traceback)rZr[rrr��sig_trace_handler�sracJCs@ttjjtjjddd�t_ttjjtjjddd�t_tj�tdt	t
�����tdt	t�����tdt	t�����tdt
����tdt����td	t
���jt�}d}}}tj}y|jtjtjjd
��}Wn�tk
�rR}zf|j�}|jr�tjntj}dtj�t�f}t|tjd�|tjk�r6t|tjd�tj|j�WYdd}~XnXy|j |�}W�n�tk
�r�}zD|j�}t!|�j"}|j�r�tjntj}dtj�t�f}|j}WYdd}~X�nbt#j$k
�rX}zr|j%d$k�o�|j}|j%}|�rtjntj}|�r|j&}n|j�}dj'dd�|jj(�D��}|dt�7}t)}WYdd}~Xn�t*k
�r�d}d}tj}dtj�t�f}t)}Yn�t
k
�r�d}tj}dtj�t�f}t+d}Ynbtk
�rd}d}tj}dtj�t�f}t+d}Yn&tk
�r(d}d}t+d}YnX|�r>t,j-||d�|�rPt,j.||�|j/�r�tj0d�}	d}
|t1k�r�|	j2|
d|f�nr|t3k�r�|	j4|
d|f�nT|t)k�r�|	j-|
d |f�n6|t+k�r�|	j-|
d!|f�n|	j-|
d"|�p�d#f�tj|�WdQRXWdQRXWdQRXWdQRXWdQRXWdQRXdS)%Nr�T)�line_buffering�SIGINT�SIGHUP�SIGTERM�SIGUSR1�SIGUSR2ZSIGINFOZSSH_ORIGINAL_COMMANDz%s
%s)r��LockTimeoutr2css|]}d|VqdS)z
Borg server: Nr)r|rrrr�r�%szmain.<locals>.<genexpr>zLocal Exceptionr�zKeyboard interruptrzzReceived SIGTERMzSignal.SIGTERM�zReceived SIGHUP.z
Signal.SIGHUPr)r�zborg.output.show-rcz!terminating with %s status, rc %d�successr�r�rTZabnormali�)rh)5rUr�r��bufferr�r�r`rMrQrRr�rSrTr_rar�r�ZERRORr@r>rrQr�r(Zget_message�	tracebackrF�
format_excrOr��exitr�rQr�r	rpZRPCErrorZexception_classZexception_fullr4rr&r�r'r�r��logrr�r$r�r%r�)Zarchiverr�r��tbZtb_log_levelr~rwr�Z	importantZ	rc_loggerZexit_msgrrr��main�s�






rq�__main__)	FFFTFTFTN)�r�rlr�rr�r`r�r�rVr<r�r�rrer�r8rTr]r�r�rRr&Zbinasciirr�
contextlibrrrrr�r	r
r=r�rrr
Zalgorithms.checksumsrr�rrrrrrrrrr�rrrZ	constants�compressrr�rrrr r!r"Zcrypto.keymanagerr#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcZnanorstrdr�rerfrgrhrir}rjrkr�rlrmrnZremoterorprqr�rrrsrtrurvrwZupgraderrxry�
BaseException�	print_excrnr�rrrJr�r�r�r�r�r�r_rarqr�rrrr��<module>s  	
I!_