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.3.tar.gz (28.7 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.3-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for urbackup_server_web_api_wrapper-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c2f0094c5d91f4e031750c2a0f66a64e9bf42a157ab01f2000db7964d6288a53
MD5 49ca94a020302b73778d48c93a2fc181
BLAKE2b-256 567a24d3c444778997905b2c04fdd561ec851872e3051532148ac27efb7cec88

See more details on using hashes here.

Provenance

The following attestation bundles were made for urbackup_server_web_api_wrapper-0.2.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for urbackup_server_web_api_wrapper-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 069f0bdc7c31e06db099668021f97efaa3e4054c7682b0bd5228ea7d0f48906f
MD5 e73e825f6e0ca53c5d82f6e928b0fd4c
BLAKE2b-256 199b97ff8386e92e118bb84dd90a5e6ffedf3f5dc1f5ff582fee253b55cc02b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for urbackup_server_web_api_wrapper-0.2.3-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