Skip to main content

Python wrapper to access and control an UrBackup server

Project description

urbackup-server-web-api-wrapper

Python wrapper to access and control an UrBackup server.

All responses are returned as typed dataclasses (e.g. StatusResult, Backups, UserListItem) so you get IDE autocompletion and type checking out of the box.

Installation

Install with:

pip3 install urbackup-server-web-api-wrapper

Usage

Connect and log in

from urbackup_api import urbackup_server_typed

server = urbackup_server_typed("http://127.0.0.1:55414/x", "admin", "foo")
server.login()

Start a backup

from urbackup_api import BackupType

# Get the client ID from the status list
status = server.get_status_result()
client = [c for c in status.status if c.name == "testclient0"][0]

results = server.start_backup([client.id], BackupType.FULL_FILE)
for r in results:
    print(f"client {r.clientid}: start_ok={r.start_ok}")

List clients with no file backup in the last three days

import datetime
import time

status = server.get_status_result()
diff_time = 3 * 24 * 60 * 60  # 3 days

for client in status.status:
    if client.lastbackup == "-" or client.lastbackup < time.time() - diff_time:
        if client.lastbackup == "-" or client.lastbackup == 0:
            lastbackup = "Never"
        else:
            lastbackup = datetime.datetime.fromtimestamp(client.lastbackup).strftime("%x %X")

        print(f"Last file backup at {lastbackup} of client {client.name} is older than three days")

Browse backups

from urbackup_api import Backups

backups = server.get_backups(client.id)
for b in backups.backups:
    print(f"Backup {b.id}: {b.size_bytes} bytes, incremental={b.incremental}")

# Browse files inside a backup
files = server.get_files(client.id, backups.backups[0].id, path="/")
for f in files.files:
    print(f"  {'[dir]' if f.dir else '     '} {f.name}")

Monitor progress

from urbackup_api import ProgressResult

progress = server.get_progress(with_last_activities=True)
for p in progress.progress:
    print(f"Client {p.name}: {p.pcdone:.1f}% done")

for a in progress.lastacts or []:
    print(f"  Last activity: {a.name} ({a.duration}s)")

Manage settings

# Global settings
settings = server.get_general_settings_result()
print(settings["settings"]["max_file_incr"]["value"])

server.save_general_settings({"max_file_incr": "15"})

# Client settings (by ID)
client_settings = server.get_client_settings_by_id(client.id)
server.save_client_settings_by_id(client.id, {"internet_authkey": "mykey", "overwrite": "true"})

# Mail / LDAP
server.save_mail_settings({"mail_servername": "smtp.example.com", "mail_serverport": "587"})
ldap = server.get_ldap_settings()

User management

from urbackup_api import UserListItem

# List users
users = server.get_user_list()
for u in users:
    print(f"{u.name} (id={u.id})")

# Create / remove / change password
server.create_user("operator", "s3cret")
server.change_user_rights(users[0].id, "all=all")
server.change_user_password(users[0].id, "newpassword")
server.remove_user(users[0].id)

Logs

from urbackup_api import LogLevel

logs = server.get_logs(log_level=LogLevel.WARNING)
for entry in logs:
    print(f"[{entry.name}] errors={entry.errors} warnings={entry.warnings}")

# Detailed log entries
details = server.get_log(logs[0].id)
for row in details:
    print(f"  [{row.level}] {row.message}")

Extra clients

# Extra clients are included in the status result
status = server.get_status_result()
for ec in status.extra_clients:
    print(ec["hostname"])

server.add_extra_client("10.0.1.100")
server.remove_extra_client(ec_id)

Remove / stop-remove clients

server.remove_client(client.id)
server.stop_remove_client(client.id)  # cancel pending removal

Usage statistics

usage = server.get_usage_stats()
for u in usage:
    print(f"{u.name}: files={u.files}, images={u.images}, used={u.used}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urbackup_server_web_api_wrapper-0.2.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urbackup_server_web_api_wrapper-0.2.1-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file urbackup_server_web_api_wrapper-0.2.1.tar.gz.

File metadata

File hashes

Hashes for urbackup_server_web_api_wrapper-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3d67494ab9def56fb149467af963f7bd9e65f6a413c63ff2a12c9565f3cf5ec4
MD5 47352284d7a2567f162b88bb8a0c7b61
BLAKE2b-256 39181ed2165cf5af9f50b266be3344852db56c380c9f7b91d15c881a4de54424

See more details on using hashes here.

Provenance

The following attestation bundles were made for urbackup_server_web_api_wrapper-0.2.1.tar.gz:

Publisher: publish.yml on uroni/urbackup-server-python-web-api-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file urbackup_server_web_api_wrapper-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for urbackup_server_web_api_wrapper-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7edd6ed36c7e596d5c5d71e1e0b4ed3c6a7f5ac54c6f3df4d81d04da057c8eb0
MD5 f4c4e99b19db74a022bb551ca95acc5d
BLAKE2b-256 69a414e86a1b5c0c896b872b68ce50f81b4085ff231d8616428f148031e16cf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for urbackup_server_web_api_wrapper-0.2.1-py3-none-any.whl:

Publisher: publish.yml on uroni/urbackup-server-python-web-api-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page