# Run your server and keep your keys

Your server holds the bucket credentials and the encryption keys, so app machines only ever need a join token.

- [All docs](https://litebackup.com/docs)

## How your server works

- **Your bucket**. Connect Amazon S3, Cloudflare R2, Google Cloud Storage, or another S3-compatible store such as DigitalOcean Spaces, Backblaze B2, or MinIO. Litebackup tests reading, writing, listing, and deleting before it enables a bucket, and for S3 the console gives you an access policy that matches it. Use a dedicated bucket or prefix for each server.
- **Encryption**. Your server encrypts every object before it archives it, with keys that stay on the server. The recovery kit or recovery passphrase you save during setup is what lets a replacement server read those objects, so keep it somewhere other than the server and its bucket.
- **Retention**. Choose how far back you can restore, and the console estimates the space that takes on your server's disk and in your bucket before you save. Litebackup removes what retention no longer needs by itself, so avoid bucket lifecycle rules that delete its objects.
- **Server disk and bucket**. Each change reaches your server's disk within seconds and your bucket after the archive delay, 15 minutes by default, which batches many changes into fewer archives. A wait for the bucket includes that delay, so give scheduled jobs a deadline that allows for it.
- **Networking**. Machines reach your server over HTTPS on TCP 443, and the server manages its own certificate. Behind a load balancer or NAT, forward TCP 443 with TLS passthrough and give the installer the public address with --address.
- **Recovering a lost server**. With your bucket and the recovery kit or passphrase, litebackup server recover rebuilds a replacement server from the versions in your bucket. Stop the old server for good first, recover into an empty data directory, and create API keys again afterwards, because they are not kept in the bucket.
- **Administering from anywhere**. The console covers databases, machines, buckets, retention, disk, and users. litebackup admin login signs the command line in to the same instance, and litebackup admin --help lists everything it can change.
- **Updates**. Update your server from its instance page first, then each machine with litebackup install cli, run as the user that installed it. Keep the npm package and the litebackup command on the same version.

![The Add a bucket screen with provider tiles and the fields for Cloudflare R2](https://litebackup-cdn.com/media/c0bc6cdd88e1f064-06-bucket.png)

## Works with the bucket you already use

Litebackup checks each bucket before it trusts it, and any store that passes its test works.

![Amazon S3](https://litebackup-cdn.com/media/7fd66f6f640e0180-amazon-s3.png)

![Cloudflare R2](https://litebackup-cdn.com/media/f70bca90f6a6bf67-cloudflare-r2.png)

![Google Cloud Storage](https://litebackup-cdn.com/media/8cd3f17e262af81a-google-cloud-storage.png)

## Choose how long to keep backups

The retention screen shows which versions you keep and estimates the space they need on your server and in your bucket before you save.

![The retention screen with a timeline of kept versions and an estimate of disk and bucket space](https://litebackup-cdn.com/media/595de1b927066aab-05-retention.png)

## Recover your server, run the client as a service, or build an image

Recovery runs on the replacement server, while the service and Docker examples run on the machines with your databases.

### Recover

```bash
# Recover the Litebackup server and its databases from a bucket.
# Run this on the Linux server. The installer requests sudo to install the system service.
# On the replacement server, with the old one stopped for good.
# LITEBACKUP_SECRET_ACCESS_KEY holds the bucket's secret access key.
litebackup server recover \
    --data-directory /var/lib/litebackup-recovered \
    --provider aws \
    --region us-east-1 \
    --bucket YOUR_BUCKET \
    --access-key-id YOUR_ACCESS_KEY_ID \
    --encryption-key-file /secure/recovery/encryption.key

# With a recovery passphrase instead of the kit's key:
#   --passphrase-file /secure/recovery/passphrase
# Add --prefix if the bucket used one, and --endpoint for R2 and other S3-compatible stores.
```

### Service

```bash
# Install the client as a user service, check its logs, and update it.
# Runs on Linux and macOS.
# Use the account that owns the databases.
litebackup install service --api-key "${LITEBACKUP_API_KEY}"
litebackup status

if [[ "$(uname -s)" == Darwin ]]; then
    tail -f "${HOME}/.local/state/litebackup/default/daemon.log"
else
    journalctl --user --unit litebackup --follow
fi

# Run this when you update the client to match the server.
litebackup install cli
```

### Linux system service

```bash
# Install the client as a system service and check whether it is running.
# Run this on the Linux server. The installer requests sudo to install the system service.
sudo litebackup install service --user app --api-key "${LITEBACKUP_API_KEY}"
sudo systemctl status litebackup
```

### Docker

```text
# syntax=docker/dockerfile:1.10
FROM debian:bookworm-slim
ARG TARGETARCH
ARG LITEBACKUP_VERSION
ARG LITEBACKUP_SHA256
ADD --chmod=0755 --checksum=sha256:${LITEBACKUP_SHA256} \
    https://litebackup-cdn.com/litebackup/${LITEBACKUP_VERSION}/litebackup-linux-${TARGETARCH} \
    /usr/local/bin/litebackup
RUN litebackup version

# Mount the whole database directory and the client's state on volumes, so the
# -wal and -shm files stay with the database and the machine keeps its identity.
ENV XDG_STATE_HOME=/state
# Pass LITEBACKUP_API_KEY at runtime; it is only needed for the first join.
```
