API#
Databudgie has a simple programmatic API, enabling one to invoke databudgie directly from python. The CLI interface is a thin wrapper around this API, and should generally allow much the same functionality and options.
- databudgie.api.backup(db, config, console=default_console, manifest=None, transaction_id=None, stats=False, dry_run=False)#
Perform backup.
- Parameters:
db (sqlalchemy.orm.Session) –
config (databudgie.config.BackupConfig) –
console (databudgie.output.Console) –
manifest (Optional[databudgie.manifest.manager.Manifest]) –
transaction_id (Optional[int]) –
stats (bool) –
dry_run (bool) –
- databudgie.api.restore(db, config, console, manifest=None, transaction_id=None, clean=None, stats=False, dry_run=False)#
Perform restore.
- Parameters:
db (sqlalchemy.orm.Session) –
config (databudgie.config.RestoreConfig) –
console (databudgie.output.Console) –
manifest (Optional[databudgie.manifest.manager.Manifest]) –
transaction_id (Optional[int]) –
clean (Optional[bool]) –
stats (bool) –
dry_run (bool) –
- databudgie.api.root_config(strict=False, config=(), color=True, conn=None, adapter=None, ddl=None, url=None, table=None, exclude=None, location=None, raw_config=None, raw_config_format='json')#
- Parameters:
strict (bool) –
config (Iterable[str]) –
color (bool) –
conn (Optional[str]) –
adapter (Optional[str]) –
ddl (Optional[bool]) –
url (Optional[str]) –
table (Optional[Tuple[str, Ellipsis]]) –
exclude (Optional[Tuple[str, Ellipsis]]) –
location (Optional[str]) –
raw_config (Optional[str]) –
raw_config_format (str) –
Example#
from databudgie.api import backup, root_config
from sqlalchemy.orm import Session
def perform_backup(pg: Session):
config = root_config(
raw_config="""{
"tables": []
}""",
)
backup(pg, config.backup)