Skip to content

SDK and command line reference

These tables list every SDK call and the settings it reads, with the full reference in the [SDK repository on GitHub](https://github.com/litebackup/sdk/blob/main/docs/sdk-reference.md) and `--help` on every command.

SDK calls

Litebackup has SDKs for TypeScript, Python, Go, Ruby, PHP, and Rust. See the SDK guide for installation commands.

Construct a client with new Litebackup({ apiKey, session }) in TypeScript, Litebackup(api_key=api_key, session=session) or AsyncLitebackup(...) in Python, and litebackup.Connect(ctx, &litebackup.ConnectArgs{APIKey: apiKey, Session: session}) in Go. Python names its calls in snake_case, such as replicas.start_prefix, and takes keyword arguments. Go passes a context first and a pointer to the call's Args struct last, and nil uses the defaults.

TypeScript Go Returns when
backups.start(path, options) StartBackup(ctx, path, args) The backup rule is saved on this machine. Starting the same path with the same options returns the saved rule.
backups.once(path, options) Backup(ctx, path, args) The version is on your server, or in your bucket with durability: "cloud".
backups.stop(name), rules.stop(id) StopBackup, StopBackupRule The backup or the whole rule has stopped.
databases.restore(name, { path, version, time }) Restore(ctx, name, args) The new file is written and checked.
databases.revert(name, { version, time }) Revert(ctx, name, args) A past version's contents are the newest version again, and every later version stays restorable.
databases.versions(name, { after, limit }) Versions(ctx, name, args) It has every kept version, oldest first.
replicas.start(name, { path }) Replicate(ctx, name, args) The first version is on this machine.
replicas.startPrefix(prefix, { directory }) ReplicatePrefix(ctx, prefix, args) The prefix is followed, and files arrive in the background.
failovers.start(path, options) StartFailover(ctx, path, args) This machine has a role, and events report it at start and on each change.
databases.acquire(name, { path }) client.Acquire(ctx, name, args) This machine holds the database and has its newest version.
databases.release(name, { wait, offload }) client.Release(ctx, name, args) The final changes are safe and the database is free.
databases.pool({ adapter }) NewPool(client, args) A pool: use keeps a backup rule's database open, and lease keeps one that moves between machines until it is idle for a minute, released, or the pool closes.
databases.offload(name, { durability }) client.Offload(ctx, name, args) A released local copy is removed once your server holds it, or your bucket with durability: "cloud".
databases.writer(name) client.Writer(ctx, name) It knows which machine writes the database and until when.
session.status(), databases.get(name), databases.sync(name) Status, Database, Sync It has the state of this machine's databases, and databases.sync waits for your server.
close(), session.shutdown() Close, Shutdown This connection is closed, or the whole client has stopped.

Options

Go fields have the same names, capitalized. TypeScript durations are milliseconds or strings such as "30s" and "2m", and Go uses time.Duration.

Call Options
backups.start name for an exact name, prefix for a namespace, maximumLocalDatabases to offload idle files above a count, and offloadDurability: "cloud" to offload them only once your bucket holds them
backups.once name, prefix, durability ("server" by default, or "cloud"), timeout, and in TypeScript signal
replicas.start path, timeout, and writeProtection: "lock" (the default), "detect", or "none"
failovers.start name and timeout, with the events origin, replica, unknown, denied, and error (Go: OnRoleChange, OnDenied, OnError)
databases.acquire path, timeout, machineLabel, offloadOnRelease: true (Go: OffloadOnRelease: true), offloadDurability: "cloud" to wait for your bucket before that offload, maintenance for a checkpoint and VACUUM on release, and discardLocal to replace a local copy that diverged from your server with its current database
databases.release durability ("server" by default, or "cloud"), offload, and timeout
databases.restore path, and either version or time
databases.revert either version or time

Environment

Variable What it sets
LITEBACKUP_API_KEY An API key or a join token, then @ and the server address (JOIN_TOKEN@HOST). A join token is exchanged once for a key of the machine; the saved key is used until the variable holds a different credential.
LITEBACKUP_SESSION The client session, default when unset. Separate sessions keep separate local settings.
LITEBACKUP_PATH The litebackup binary the SDKs start, instead of the one npm installed or the one on PATH.
XDG_STATE_HOME Where a per-user client keeps its identity and backup rules. Put it on a volume in containers.
XDG_RUNTIME_DIR Where a per-user client puts its socket when no service install recorded one.

States and errors

Every database on a machine has a role, origin or replica, and one of these states.

State What it means
pending It waits to take its write lock, as after a start or a drain.
syncing Changes are on their way to your server.
synced Your server has every change.
waiting Another machine writes the database.
offloaded The local copy was removed, and acquire brings it back from your server.
stopped Litebackup no longer follows the file.
conflicted The local file was refused and left as it is; it needs a decision.
error The database's last error says what to fix.

Errors from the client are LitebackupError in TypeScript and Python and *litebackup.Error in Go, which litebackup.IsCode(err, litebackup.CodeLockUnavailable) checks. Their code is one of busy, lock_unavailable, not_found, file_exists (a restore target exists), rule_exists (the path has a backup rule with other settings), still_open, timeout, not_configured, sdk_unsupported, or daemon_unsupported, and the troubleshooting page explains each. Their details hold the rest of the answer, such as the saved rule for rule_exists.

Command line

Top-level commands such as start, backup, restore, replicate, failover, acquire, and status go to the client on this machine. litebackup server runs on your Litebackup server's own host, litebackup admin reaches your instance over HTTPS after litebackup admin login, and litebackup account manages your litebackup.com account. Add --stdout-format json to any command for JSON output. The command line page has the flags for each task.