btrsync.btrfs

Data structures and functions manipulating btrfs subvolumes.

Module Attributes

FSTREE

Path of the btrfs filesystem root, as printed by btrfs-progs.

btrsync.btrfs.FSTREE = '<FS_TREE>'

Path of the btrfs filesystem root, as printed by btrfs-progs.

Functions

abspaths(vols, rootpath)

Process a sequence of btrfs volumes, making all relative paths absolute; absolute paths are left unchanged.

relpaths(vols, rootpath)

Process a sequence of btrfs volumes, making all paths below a chosen root relative to that root; other paths are left unchanged.

btrsync.btrfs.abspaths(vols, rootpath)[source]

Process a sequence of btrfs volumes, making all relative paths absolute; absolute paths are left unchanged.

Parameters
  • vols – the sequence of btrfs subvolumes to process

  • rootpath – the absolute path that subvolume paths are relative to

Returns

iterator over the modified subvolumes

Raises

ValueError – if rootpath is not absolute (does not start with FSTREE)

btrsync.btrfs.relpaths(vols, rootpath)[source]

Process a sequence of btrfs volumes, making all paths below a chosen root relative to that root; other paths are left unchanged.

Parameters
  • vols – the sequence of btrfs subvolumes to process

  • rootpath – the absolute path that subvolume paths are to be made relative to

Returns

iterator over the modified subvolumes

Raises

ValueError – if rootpath is not absolute (does not start with FSTREE)

Classes

COWTree(subvols[, check])

Build a hierarchy of btrfs subvolumes based on snapshotting (COW) parentage.

class btrsync.btrfs.COWTree(subvols, check=None)[source]

Build a hierarchy of btrfs subvolumes based on snapshotting (COW) parentage.

Parameters
  • subvols – the sequence of subvolumes (dict instances keyed by subvolume properties) to process

  • check – a function that takes a subvolume as argument and returns a boolean whether to consider it for parentage; by default accept all

static ancestors(node)[source]

Iterate over the COW ancestors of node, including itself.

static bfs(*nodes, **kwargs)[source]

Iterate, in a breadth-first search, over nodes and their COW descendants.

static dfs(node)[source]

Iterate, in a depth-first search, over node and its COW descendants.

static diff(aroots, broots, akeys, bkeys)[source]

Perform a diff operation over two sets of COW hierarchies, identifying common subvolumes based on custom key functions.

Two subvolumes are considered identical if any non-None results of their key functions match.

Parameters
  • aroots – the first sequence of COW hierarchies to compare

  • broots – the second sequence of COW hierarchies to compare

  • akeys – the sequence of key functions to apply to aroots

  • bkeys – the sequence of key functions to apply to broots

Returns

tuple of dicts (coma, comb), indexing, by subvolume uuid, the elements of aroots and broots respectively, which have corresponding identical subvolumes in the other set

Modules

btrsync.btrfs.cmd

Programmatically generate btrfs subcommand invocations.

btrsync.btrfs.parse

Parsers for the output of btrfs subcommands.