btrsync.cli¶
Command line interface to btrsync. Run as main with ‘-h’ for usage information.
Functions
|
Parse command-line arguments from argv and run |
Return an |
|
|
Process a destination location string, returning a tuple of |
|
Perform btrsync from srcs to dst. |
|
Return a |
|
Format the paths that make up a transfer for display on the command line. |
|
Represent n bytes in human-readable form using IEC units (i.e., KiB, MiB, etc.). |
|
Call |
|
Parse a location string into a protocol string and btrfs root options. |
|
Process |
|
Process a source location string, returning a tuple of |
- btrsync.cli.cli_main(argv)[source]¶
Parse command-line arguments from argv and run
do_btrsync().
- btrsync.cli.cli_parser()[source]¶
Return an
argparse-like parser for btrsync’s command-line options.
- async btrsync.cli.dest_root(loc, rootopts={}, rootargs={})[source]¶
Process a destination location string, returning a tuple of
(btrfs_root, receive_path).
- async btrsync.cli.do_btrsync(*, src_coros, dst_coro, incls, excls, auto, confirm, syncer, syncopts, transfer, transopts)[source]¶
Perform btrsync from srcs to dst.
- Parameters
src_coros – sequence of coroutines that return (source_root, matcher) pairs
dst_coro – coroutine that returns a (destination_root, receive_path) pair
incls – list of globs matching subvolumes to include in the sync
excls – list of globs matching subvolumes to exclude from the sync
auto – if
Falsedo a dry run, ifNoneask for confirmation, ifTrueproceed without askingconfirm –
Confirm-like class to handle user interaction for confirmationsyncer –
btrsync.sync.BtrSync-like class to use for syncsyncopts – keyword arguments to pass to syncer
transfer –
btrsync.sync.Transfer-like class to use for synctransopts – keyword arguments to pass to transfer
- async btrsync.cli.dump_root(odir, inner_coro=None, rootopts={}, rootargs={})[source]¶
Return a
(root, receive_path)pair for dumping a stream to a local file.
- btrsync.cli.format_transfer(volpaths, parent, destdir, *, verb=False)[source]¶
Format the paths that make up a transfer for display on the command line.
- Parameters
volpaths – sequence of paths to send
parent – parent to use for incremental send, or
Nonefor full senddestdir – destination directory used for receive
verb – if
Trueinclude more details
- Returns
formatted string
- btrsync.cli.humanbytes(n, sep=' ')[source]¶
Represent n bytes in human-readable form using IEC units (i.e., KiB, MiB, etc.).
- Parameters
n – the number of bytes to represent
sep – separator between numeric value and unit
- Returns
human-readable representation as string
- btrsync.cli.main()[source]¶
Call
cli_main()withsys.argv.
- btrsync.cli.parse_root(locstr)[source]¶
Parse a location string into a protocol string and btrfs root options.
- Parameters
locstr – the location string to parse
- Returns
a tuple
(protocol, root_options, root_arguments): the protocol to pass tobtrsync.sync.default_root()to obtain a root factory, the arguments to pass to the root factory to obtain a root class, and the location to pass to the root class, respectively.
- btrsync.cli.process_args(cliargs)[source]¶
Process
argparse-style output into arguments fordo_btrsync().
- async btrsync.cli.src_root(loc, rootopts={}, rootargs={})[source]¶
Process a source location string, returning a tuple of
(btrfs_root, matcher_instance).
Classes
Match against a set of include and exclude globs. |
|
|
Transfer class that periodically reports progress on stdout. |
|
Handle the UI aspects of confirming a sync via the command line. |
|
|
|
Convenience class to parse, store, and validate SSH location parameters. |
|
Match a single path, accounting for include and exclude globs, and stop all processing afterwards. |
|
Match all paths that are below or matching a particular glob, further accounting for include and exclude globs. |
- class btrsync.cli.BaseMatch[source]¶
Match against a set of include and exclude globs.
If no include globs are given, match all not explicitly excluded.
- base_match(path)[source]¶
Return the form of path to be matched against includes and excludes, or
Noneto exclude it outright.By default return path unaltered; override to change behavior.
- match(path)[source]¶
Return
Trueif path matches againstbase_match()and current includes and excludes,Falseotherwise.
- class btrsync.cli.CliProgress(*args, **kwargs)[source]¶
Transfer class that periodically reports progress on stdout.
- err(e, *args)¶
Called on encountering an exception e; expected to log the error and return successfully.
- async progress(flow, seq)¶
Implement progress reporting every period seconds.
- async report(vols, par, src, dst)¶
Called at the start of a transfer of volumes vols with parent par from src to dst.
- async report_done(vols, par, src, dst)¶
Called when the transfer of volumes vols with parent par from src to dst has finished.
- async report_progress(total, prev, seq)[source]¶
Called on every progress reporting event.
- Parameters
total – currrent total bytes transferred
prev – value of total from previous call
seq – sequence to indicate activity
- async transf(vols, par, src, dst)¶
Progress reporting transfer function, as expected by .BtrSync.sync.
- Parameters
vols – the subvolumes to transfer
par – the parent subvolume to use for an incremental transfer
src – the source btrfs root
dst – the destination btrfs root
- Raises
asyncio.CancelledError – if any error has occurred, after logging it with
err()
- async try_await(aw)¶
Try awaiting awaitable aw, converting any exceptions to
asyncio.CancelledError.Exceptions raised by aw will be logged by
err().
- async try_gather(*coroutines)¶
Try running and waiting for all coroutines, canceling all upon error.
Exceptions raised by the tasks will be logged by
err().- Raises
asyncio.CancelledError – if any tasks raise an exception
- class btrsync.cli.Confirm(src, *args, **kwargs)[source]¶
Handle the UI aspects of confirming a sync via the command line.
- Parameters
src – the SOURCE command line argument currently being processed
- confirm()[source]¶
Called after
preview()to give final confirmation.- Returns
'Y'to proceed with sync,'S'to skip the current source and continue with the next, and'N'to immediately abort
- err(e, *args)¶
Called on encountering an exception e; expected to log the error and return successfully.
- preview()[source]¶
Called after the dry run sync finishes to print a preview of the transfers to be performed.
- async progress(flow, seq)¶
Implement progress reporting every period seconds.
- async report(vols, par, src, dst)¶
Called at the start of a transfer of volumes vols with parent par from src to dst.
- async report_done(vols, par, src, dst)¶
Called when the transfer of volumes vols with parent par from src to dst has finished.
- async report_progress(total, prev, seq)¶
Called on every progress reporting event.
- Parameters
total – currrent total bytes transferred
prev – value of total from previous call
seq – sequence to indicate activity
- async transf(vols, par, src, dst)[source]¶
Transfer function as expected by
btrsync.sync.BtrSync.sync()that only logs transfers.
- async try_await(aw)¶
Try awaiting awaitable aw, converting any exceptions to
asyncio.CancelledError.Exceptions raised by aw will be logged by
err().
- async try_gather(*coroutines)¶
Try running and waiting for all coroutines, canceling all upon error.
Exceptions raised by the tasks will be logged by
err().- Raises
asyncio.CancelledError – if any tasks raise an exception
- class btrsync.cli.IncrSync(src, dst, *, srckeys=None, dstkeys=None)[source]¶
btrsync.sync.BtrSyncclass that skips non-incremental transfers.- static check(vol, parent)[source]¶
Return
Trueif the sync of vol with COW parent parent should proceed.
- parent(vol)¶
Return the COW parent of vol to be used as basis for incremental send, or
Noneif unavailable.
- static stop(vols)¶
Called after vols have been synced; return
Trueif sync should immediately stop.
- async sync(trans, *, batch=False, parallel=False, transfer_existing=False, volgroups=None, target=None, parent=None, check=None, stop=None)¶
Perform synchronization of subvolumes.
Returns whether the sync was successful and all error handling is delegated to trans.
- Parameters
trans –
Transfer-like object to perform the actual send/receive operationsbatch – if
True, batch together multiple volumes into a single transferparallel – if
True, run independent transfers in paralleltransfer_existing – if
True, consider for transfer volumes that already exist on the destinationvolgroups – override for
volgroups()target – override for
target()parent – override for
parent()check – override for
check()stop – override for
stop()
- Returns
Trueif sync successful,Falseif errors occured
- static target(vol)¶
Return
Trueif vol is to be considered for sync.
- static volgroups(roots)¶
Iterate over roots and their descendants in groups of COW-independent volumes.
- class btrsync.cli.SSHLoc(user: str, host: str, port: str)[source]¶
Convenience class to parse, store, and validate SSH location parameters.
- validate()[source]¶
Validate SSH parameters: host cannot be empty, and user or port, if specified, cannot be empty.
- Returns
self
- Raises
ValueError – for invalid parameters
- class btrsync.cli.SingleMatch(path)[source]¶
Match a single path, accounting for include and exclude globs, and stop all processing afterwards.
- Parameters
path – the target path to match
- exclude(*globs)¶
Add globs to the list of excluded globs.
- include(*globs)¶
Add globs to the list of included globs.
- match(path)¶
Return
Trueif path matches againstbase_match()and current includes and excludes,Falseotherwise.
- class btrsync.cli.UnderGlob(glob)[source]¶
Match all paths that are below or matching a particular glob, further accounting for include and exclude globs.
- Parameters
glob – a shell-like glob matching the path prefix of targets
- exclude(*globs)¶
Add globs to the list of excluded globs.
- include(*globs)¶
Add globs to the list of included globs.
- match(path)¶
Return
Trueif path matches againstbase_match()and current includes and excludes,Falseotherwise.
- stop(paths)¶
Return
Trueif further processing should stop after handling paths, orFalseif it should continue.By default always return
False.