rbackup.struct package

Submodules

rbackup.struct.hierarchy module

class rbackup.struct.hierarchy.Hierarchy(dest)

Bases: os.PathLike

A general class for organizing a hierarchy of data.

Hierarchy objects are non-intrusive in that they do not affect the filesystem upon creation. It is up to the caller to call either shutil.mkdir() or related method to create the directory structure it emulates.

Implementation Details

  • For consistency, Hierarchy objects always store and return absolute paths

  • Data for all Hierarchy objects and subclassed objects use JSON for serialization

gen_metadata()

Generate metadata for this repository.

After this method is called, the data necessary for this hierarchy has been created.

metadata_path
Returns

the path of this hierarchy’s metadata file.

Return type

path-like object

name
Returns

the name of this hierarchy.

Return type

str

path
Returns

the base directory of this hierarchy

Return type

path-like object

read_metadata()

Read this repository’s metadata from its file and then return it.

Return type

type that the data is serialized as

write_metadata(attr)

Write this repository’s metadata to its metadata file.

Note

This write operation is atomic to the caller.

Parameters

attr (any type) – class data to write to file

rbackup.struct.repository module

A repository is a directory that contains backup data sequestered into snapshots and a symlink to the most recently created snapshot.

Properties

  • Each snapshot in a repository is unaware of one another,

    this is the job of the repository to organize

  • Has a symlink pointing to the most recently created snapshot

class rbackup.struct.repository.Repository(dest)

Bases: rbackup.struct.hierarchy.Hierarchy

A class for interacting with a backup repository.

Snapshots can be accessed on a one-by-one basis through iteration.

>>> for snapshot in Repository('backup'): 
...     ...
...

Snapshots on repositories can be retrieved by index using python’s list slicing syntax.

>>> print(Repository('backup')[:])
[Snapshot(...), ...]

Membership of a snapshot in a repository can be checked by name.

>>> Repository('backup').create_snapshot('test')
>>> 'test' in Repository('backup')
True

Number of snapshots in a repository can be checked as well

>>> Repository('backup').create_snapshot()
>>> len(Repository('backup'))
1
cleanup(*, remove_snapshots=False, remove_repo_dir=False)

Clean up any filesystem references to this repository. By default, no snapshots are deleted.

Parameters
  • remove_snapshots (bool) – delete the data directory of this repository

  • remove_repo_dir (bool) – remove the top-level directory of this repository

create_snapshot(name=None)

Create a new snapshot in this repository.

This operation is non-intrusive in that it will not make any changes in the filesystem when called.

If name is not given, then the new snapshot’s name is the current UTC date in ISO format.

If name is given, then it is the name for the new snapshot.

If name is given and it is the name of a snapshot already on the repository, that snapshot is overwritten instead.

Parameters

name (str) – the name of the snapshot

Returns

Snapshot object

Raises

ValueError – if name is an invalid value

empty
Returns

True if there are no Snapshots in this Repository, False otherwise

Return type

bool

gen_metadata()

Generate metadata for this repository. After this method is called, the data necessary for this snapshot has been created.

static is_valid_snapshot_name(name)

Check if the given name is a valid name.

Invalid Names:

  • Contain slashes

  • Are empty values

Valid names:

  • Match the regex r’[w]+[^/]*’

Parameters

name (str) – name to validate

Returns

true if this name is deemed valid, otherwise False

Return type

bool

snapshot_dir
Returns

the directory in this Repository in which snapshots are stored.

Return type

path-like object

snapshots
Returns

all snapshots stored in this repository

Return type

list of Snapshot objects

Create a symbolic link in the Repository directory to a snapshot.

Parameters

snapshot (Snapshot object) – the snapshot to create the symlink to

rbackup.struct.snapshot module

class rbackup.struct.snapshot.Snapshot(path)

Bases: rbackup.struct.hierarchy.Hierarchy

Hierarchy for a single snapshot.

Data from each run of a backup script is intended to go here.

Snapshots are unaware of one another, it is up to a third-party caller to orchestrate operations such as hardlinking between snapshots and ordering snapshots.

gen_metadata()

Generate metadata for this repository.

After this method is called, the data necessary for this hierarchy has been created.

pkg_dir
Returns

the package manager backup directory of this snapshot.

Return type

path-like object

Module contents