BorgAPI
A helpful wrapper for borgbackup to be able to easily use it in python scripts.
Installation
pip install borgapi
Requires:
borgbackup: 1.1.16
Usage
import borgapi
api = borgapi.BorgAPI(defaults={}, options={})
# Initalize new repository
api.init("/foo/bar", make_parent_dirs=True)
# Create backup
output = api.create("/foo/bar::backup", "/home", "/mnt/baz", json=True)
print(output["name"]) # backup
print(output["repository"]["location"]) # /foo/bar
BorgAPI Init arguments
class BorgAPI(
defaults: dict = None,
options: dict = None,
log_level: str = 'info',
log_json: bool = False
)
- defaults: dictionary that has command names as keys and value that is a dict of command specific optional arguments
{
"init": {
"encryption": "repokey-blake2",
"make_parent_dirs": True,
},
"create": {
"json": True,
},
}
- options: dictionary that contain the optional arguments (common, exclusion, filesystem, and archive) used for every command (when valid). Options that aren't valid for a command will get filterd out. For example,
strip_componentswill be passed into theextractcommand but not thediffcommand.
{
"debug": True,
"log_json": True,
"exclue_from": "baz/spam.txt",
"strip_components": 2,
"sort": True,
"json_lines": True,
}
- log_level: defualt log level, can be overriden for a specific comand by passing in another level as and keyword argument
- log_json: log lines written by logger are formatted as json lines, passed into the logging setup
Borg Commands
When using a borg command any of the arguments can be set as keyword arguments.
The argument names are the long option names with dashes turned into underscores.
So the --storage-quota argument in init gets turned into the keyword argument storage_quota.
Examples:
api.init(
repository="/foor/bar",
encryption="repokey",
append_only=True,
storage_quota="5G",
make_parent_dirs=True,
debug=True,
log_json=True,
)
diff_args = {
sort: True,
json_lines: True,
debug: True,
exclude_from: "./exclude_patterns.txt",
}
api.diff(
"/foo/bar::tuesday",
"friday",
"/foo/bar",
"/baz",
**diff_args,
)
Available Commands
- init
- create
- extract
- check
- rename
- list
- diff
- delete
- prune
- info
- mount
- umount
- key_change_passphrase (key change-passphrase)
- key_export (key export)
- key_import (key import)
- upgrade
- export_tar
- config
Borg Commands Not Available
- recreate
- serve
- with-lock
- break-lock
- benchmark crud
Command Quirks
Things that were changed from the way the default borg commands work to make things a bit more manageable.
- init
encryptionis an optional argument that defaults torepokey
Roadmap
- Add ability to set environment variables from api (either a function or part of the initalizer or both)
- https://borgbackup.readthedocs.io/en/stable/usage/general.html#environment-variables
- Currently requires user to set them beforehand
Links
Contributing
Help is greatly appreciated. First check if there are any issues open that relate to what you want to help with. Also feel free to make a pull request with changes / fixes you make.
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file borgapi-0.1.1.tar.gz.
File metadata
- Download URL: borgapi-0.1.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
613d75fbe3f9fbb60837cc5847d0d57e2524271aa1bccdf7f241da9407d675e5
|
|
| MD5 |
38954315d50dc904c60968d0ffb27ccd
|
|
| BLAKE2b-256 |
752de858282ca8455386101117c50fba0347d9f35cef0915f3db9e9c3b2b6cef
|
File details
Details for the file borgapi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: borgapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43c034e247aef73336632e726766f9985d9e95b2611d5eef5c3857b8535d761c
|
|
| MD5 |
acda504176ca68ed2dddbe9bb2ea7bdb
|
|
| BLAKE2b-256 |
e99cea0166f0f17fd3e822226e2182355fe4e555e815635272e051a643559d71
|