genvid.toolbox.Backup

class genvid.toolbox.Backup

Bases: object

API to create backup archives and restore data from them.

The idea is to subclass this base class with different “strategies” to backup and restore data. Then, as long as all the strategies are compatible, you can use the methods from this class to backup / restore all everything easily.

name

Name of the service or entity being backed up.

backup(archive: zipfile.ZipFile, obj)

Save the relevant state in a ZIP archive.

Objects subclassing Backup are responsible for populating a ZIP archive with all the necessary data they need to restore.

Parameters:
  • archive – ZIP archive for storing recovery data.
  • obj – Instance of the object whose state is to be backupd.
restore(archive: zipfile.ZipFile, obj)

Recover state from the data backupd in the backup ZIP archive.

Objects subclassing Backup should be able to restore all relevant states from the data that was added with backup().

Parameters:
  • archive – ZIP archive containing the recovery data.
  • obj – Instance of the object whose state is to be restored.
static backup_all(strategies: typing.Iterable[ForwardRef('Backup')], path: str, obj)

Allow to easily backup states using multiple strategies.

Parameters:
  • path – Path to the ZIP archive destination (it will be created or overridden).
  • obj – Instance of the object containing the states to backup.

Warning

It is important to refer to the documentation of each backup strategy to make sure the obj passed as parameter is compatible with each of them. Additionally, a logger should be present on the obj for diagnostics.

static restore_all(strategies: typing.Iterable[ForwardRef('Backup')], path: str, obj)

Allow to easily restore states using multiple strategies.

Parameters:
  • path – Path to the ZIP archive containing the backup data.
  • obj – Instance of the object which will receive the restored states.

Warning

It is important to refer to the documentation of each restore strategy to make sure the obj passed as parameter is compatible with each of them. Additionally, a logger should be present on the obj for diagnostics.

class backup.Backup

Implementation of genvid.toolbox.Backup