You install Kopia on a dozen hosts and point them all directly at an S3 bucket. It works. Then you notice that every host has the full repository password, every host can see every other host’s snapshots, and the per-host retention policy is whatever each individual operator typed into their crontab. The fleet works only because nobody has misconfigured it yet. The fix is Kopia’s repository server — a single TLS endpoint that holds the S3 credentials and the repo password, brokers per-client identities, and enforces policies centrally so a new host inherits the right retention by virtue of belonging to the right group.
What’s happening
Kopia ships with three modes that look similar in the docs and behave very differently in production.
Direct mode is one host writing directly to S3/B2/Azure/etc. The host has the storage credentials and the repo password. Convenient for laptops. Bad as a fleet pattern because the credentials are everywhere.
Repository server mode is what changes the calculus. One server holds the storage credentials and the master repo password. Clients connect to the server over TLS with per-client usernames and passwords. The server authorizes operations and proxies the encrypted reads/writes to S3. A compromised client gets only its tenant’s encrypted view — not the storage credentials, not the master key.
Server-side policies are the third piece. Kopia represents retention, compression, error handling, etc. as policies attached to users, hosts, paths, or globals. A policy attached to host:web01 is inherited by every snapshot from web01. Policies attached to globals apply to everyone unless overridden. This is what lets you set “production hosts keep 14d/8w/12m, staging keeps 7d/4w” without editing a config on every host.
The pieces that make this run cleanly:
- A dedicated server VM in front of the object storage. Not running anything else.
- TLS — Kopia uses its own TLS certificate, generated at server init or supplied externally. Pair with a reverse proxy if you want managed certs from Let’s Encrypt.
- Per-client identities registered server-side. Each client has a username (typically
client@host) and password, plus a server-defined set of allowed paths. - Policy hierarchy worked out before onboarding clients: global → host → user → path.
- Maintenance schedule that lets the server run
kopia maintenance(the equivalent of restic prune) automatically. Clients should not run maintenance; the server is the authority.
How to verify
From a client host that’s been registered:
kopia repository status
# Status: CONNECTED
# Server URL: https://kopia.internal:51515
# Username: web01@prod
# Hostname: web01
# Read-only: false
List effective policy for this client — what retention will actually run:
kopia policy show --global
kopia policy show --user-host
# Should reflect the policy hierarchy: global + any host/user override
On the server, list all clients and their last activity:
kopia server user list
# web01@prod: enabled, last connect 2026-05-14T03:02
# web02@prod: enabled, last connect 2026-05-14T03:04
# stage01@staging: enabled, last connect 2026-05-14T03:06
Check that maintenance is running and not falling behind:
kopia maintenance info
# Owner: kopia-server@kopia-host
# Quick Cycle:
# Last run: 2026-05-13 04:00 (success, 12 min)
# Full Cycle:
# Last run: 2026-05-08 04:00 (success, 1h 43m)
If “Last run” for the full cycle is older than your scheduled cadence + a grace period, maintenance is stuck or disabled and storage will keep growing.
The fix
Server installer for Ubuntu 22.04. Save as /root/kopia-server-setup.sh and run on the dedicated Kopia server VM:
#!/usr/bin/env bash
set -euo pipefail
### Kopia repository server on Ubuntu 22.04
### Backs up to S3-compatible storage, exposes a TLS endpoint to clients
### Maintenance runs server-side on a schedule
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT ===
KOPIA_USER="kopia"
KOPIA_HOME="/var/lib/kopia"
KOPIA_PORT="51515"
KOPIA_SERVER_FQDN="kopia.internal" # what clients will connect to
S3_ENDPOINT="s3.us-west-2.amazonaws.com"
S3_BUCKET="acme-kopia-backups"
S3_PREFIX="prod/"
S3_REGION="us-west-2"
S3_ACCESS_KEY="CHANGE_ME"
S3_SECRET_KEY="CHANGE_ME"
REPO_PASSWORD="CHANGE_ME_REPO_PASSWORD"
KOPIA_SERVER_PASSWORD="CHANGE_ME_SERVER_PASSWORD" # only used to bootstrap UI/CLI on server
# ============
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get upgrade -y
apt-get install -y curl gnupg ca-certificates apt-transport-https \
ufw fail2ban chrony jq lsof iproute2 net-tools
echo "==> Installing Kopia from official repo"
curl -fsSL https://kopia.io/signing-key | gpg --dearmor -o /usr/share/keyrings/kopia-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kopia-keyring.gpg] https://packages.kopia.io/apt/ stable main" \
> /etc/apt/sources.list.d/kopia.list
apt-get update -y
apt-get install -y kopia
echo "==> Creating kopia user and tree"
adduser --system --group --home "${KOPIA_HOME}" --disabled-login --shell /usr/sbin/nologin "${KOPIA_USER}"
mkdir -p "${KOPIA_HOME}/.config/kopia" "${KOPIA_HOME}/cache" "${KOPIA_HOME}/logs"
chown -R "${KOPIA_USER}:${KOPIA_USER}" "${KOPIA_HOME}"
chmod 750 "${KOPIA_HOME}"
echo "==> Time sync"
systemctl enable --now chrony
echo "==> Writing server credentials env file"
install -d -m 700 -o ${KOPIA_USER} -g ${KOPIA_USER} /etc/kopia
cat > /etc/kopia/server.env <<EOF
KOPIA_PASSWORD=${REPO_PASSWORD}
AWS_ACCESS_KEY_ID=${S3_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY=${S3_SECRET_KEY}
HOME=${KOPIA_HOME}
EOF
chmod 600 /etc/kopia/server.env
chown ${KOPIA_USER}:${KOPIA_USER} /etc/kopia/server.env
echo "==> Connecting/creating the repository on S3"
runuser -u ${KOPIA_USER} -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
if ! kopia repository status >/dev/null 2>&1; then
if kopia repository connect s3 \
--bucket=${S3_BUCKET} \
--endpoint=${S3_ENDPOINT} \
--prefix=${S3_PREFIX} \
--region=${S3_REGION} 2>/dev/null; then
echo 'Connected to existing repo.'
else
echo 'Initializing new repo on S3...'
kopia repository create s3 \
--bucket=${S3_BUCKET} \
--endpoint=${S3_ENDPOINT} \
--prefix=${S3_PREFIX} \
--region=${S3_REGION}
fi
fi
"
echo "==> Generating TLS certificate (self-signed; replace with proxy-terminated TLS in production)"
runuser -u ${KOPIA_USER} -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
kopia server start \
--insecure \
--address=127.0.0.1:0 \
--no-ui 2>/dev/null &
sleep 1
" || true
# Use kopia's tls helpers
runuser -u ${KOPIA_USER} -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
mkdir -p ${KOPIA_HOME}/.config/kopia
if [[ ! -f ${KOPIA_HOME}/.config/kopia/tls.cert ]]; then
openssl req -x509 -newkey rsa:4096 -days 825 -nodes \
-keyout ${KOPIA_HOME}/.config/kopia/tls.key \
-out ${KOPIA_HOME}/.config/kopia/tls.cert \
-subj '/CN=${KOPIA_SERVER_FQDN}' \
-addext 'subjectAltName=DNS:${KOPIA_SERVER_FQDN}'
chmod 600 ${KOPIA_HOME}/.config/kopia/tls.*
fi
"
echo "==> Initial policy setup (server-side defaults)"
runuser -u ${KOPIA_USER} -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
# Global retention default
kopia policy set --global \
--keep-latest 30 \
--keep-hourly 24 \
--keep-daily 14 \
--keep-weekly 8 \
--keep-monthly 12 \
--keep-annual 3 \
--compression=zstd-fastest
# Make ignored paths sensible globally
kopia policy set --global \
--add-ignore '*/.cache' \
--add-ignore '*/node_modules' \
--add-ignore '/proc' --add-ignore '/sys' \
--add-ignore '/var/lib/docker/overlay2'
"
echo "==> systemd unit"
cat > /etc/systemd/system/kopia-server.service <<UNIT
[Unit]
Description=Kopia repository server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=${KOPIA_USER}
Group=${KOPIA_USER}
EnvironmentFile=/etc/kopia/server.env
ExecStart=/usr/bin/kopia server start \\
--tls-cert-file=${KOPIA_HOME}/.config/kopia/tls.cert \\
--tls-key-file=${KOPIA_HOME}/.config/kopia/tls.key \\
--address=0.0.0.0:${KOPIA_PORT} \\
--server-control-username=server-control \\
--server-control-password-file=/etc/kopia/server-control-password \\
--no-ui
Restart=on-failure
RestartSec=5
LimitNOFILE=200000
[Install]
WantedBy=multi-user.target
UNIT
echo "${KOPIA_SERVER_PASSWORD}" > /etc/kopia/server-control-password
chmod 600 /etc/kopia/server-control-password
chown ${KOPIA_USER}:${KOPIA_USER} /etc/kopia/server-control-password
systemctl daemon-reload
systemctl enable --now kopia-server.service
echo "==> Maintenance schedule (server runs quick + full automatically)"
runuser -u ${KOPIA_USER} -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
# Server is the maintenance owner; clients should never be
kopia maintenance set --owner '${KOPIA_USER}@${KOPIA_SERVER_FQDN}'
kopia maintenance set --enable-quick true --quick-interval=1h
kopia maintenance set --enable-full true --full-interval=24h
"
echo "==> Helper script: register a client"
cat > /usr/local/sbin/kopia-add-client <<'ADDCLIENT'
#!/usr/bin/env bash
set -euo pipefail
# kopia-add-client <username> <hostname> <password> [--allowed-path=/etc]
if [[ $# -lt 3 ]]; then
echo "Usage: $0 <username> <hostname> <password>" >&2
exit 2
fi
USERNAME="$1"
HOSTNAME="$2"
PASSWORD="$3"
runuser -u kopia -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
kopia server user add ${USERNAME}@${HOSTNAME} --user-password '${PASSWORD}'
"
echo "Tell the kopia server to reload its user database:"
runuser -u kopia -- bash -c "
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/server.env | xargs)
kopia server refresh \
--server-control-username=server-control \
--server-control-password=\$(cat /etc/kopia/server-control-password) \
--address https://localhost:51515 --insecure
"
echo "Client connect command:"
echo " kopia repository connect server \\"
echo " --url=https://${KOPIA_SERVER_FQDN}:51515 \\"
echo " --override-username=${USERNAME} \\"
echo " --override-hostname=${HOSTNAME}"
echo " (When prompted, paste the client password.)"
ADDCLIENT
chmod 750 /usr/local/sbin/kopia-add-client
echo "==> Firewall + fail2ban"
ufw allow ${KOPIA_PORT}/tcp
ufw allow 22/tcp
ufw --force enable
cat > /etc/fail2ban/jail.d/kopia.local <<EOF
[sshd]
enabled = true
EOF
systemctl enable --now fail2ban
echo
echo "========================================"
echo "Kopia server ready"
echo "========================================"
echo
echo "Listener:"
ss -lntp | grep ":${KOPIA_PORT}" || true
echo
echo "Add a client (example):"
echo " /usr/local/sbin/kopia-add-client client1 web01 's3kret'"
echo
echo "TLS cert SHA256 (for client --server-cert-fingerprint):"
openssl x509 -in ${KOPIA_HOME}/.config/kopia/tls.cert -fingerprint -sha256 -noout
echo
echo "Maintenance status:"
runuser -u ${KOPIA_USER} -- bash -c "export \$(grep -v '^#' /etc/kopia/server.env | xargs) && kopia maintenance info" || true
Client installer. Save as /root/kopia-client-setup.sh on each host that backs up:
#!/usr/bin/env bash
set -euo pipefail
### Kopia client on Ubuntu 22.04
### Connects to the central kopia server, no S3 credentials on the client
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT ===
KOPIA_SERVER_URL="https://kopia.internal:51515"
KOPIA_USERNAME="web01"
KOPIA_HOSTNAME="$(hostname -s)"
KOPIA_PASSWORD="CHANGE_ME_CLIENT_PW"
SERVER_CERT_FINGERPRINT="sha256:XX:YY:ZZ:..." # from `openssl x509 -fingerprint -sha256` on server
BACKUP_PATHS=(/etc /var/log /var/lib /home /srv)
# ============
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get install -y curl gnupg ca-certificates apt-transport-https jq
curl -fsSL https://kopia.io/signing-key | gpg --dearmor -o /usr/share/keyrings/kopia-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/kopia-keyring.gpg] https://packages.kopia.io/apt/ stable main" \
> /etc/apt/sources.list.d/kopia.list
apt-get update -y
apt-get install -y kopia
mkdir -p /etc/kopia
cat > /etc/kopia/client.env <<EOF
KOPIA_PASSWORD=${KOPIA_PASSWORD}
KOPIA_CHECK_FOR_UPDATES=false
HOME=/root
EOF
chmod 600 /etc/kopia/client.env
echo "==> Connecting to repository server"
export $(grep -v '^#' /etc/kopia/client.env | xargs)
kopia repository connect server \
--url="${KOPIA_SERVER_URL}" \
--override-username="${KOPIA_USERNAME}" \
--override-hostname="${KOPIA_HOSTNAME}" \
--server-cert-fingerprint="${SERVER_CERT_FINGERPRINT}"
cat > /usr/local/sbin/kopia-backup <<BACKUP
#!/usr/bin/env bash
set -euo pipefail
export \$(grep -v '^#' /etc/kopia/client.env | xargs)
logger -t kopia-backup[${KOPIA_HOSTNAME}] starting
kopia snapshot create ${BACKUP_PATHS[@]} 2>&1 \\
| logger -t kopia-backup[${KOPIA_HOSTNAME}]
logger -t kopia-backup[${KOPIA_HOSTNAME}] completed
# Clients do NOT run kopia maintenance; the server does.
BACKUP
chmod 750 /usr/local/sbin/kopia-backup
cat > /etc/systemd/system/kopia-backup.service <<'UNIT'
[Unit]
Description=Kopia backup
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/kopia-backup
TimeoutStartSec=4h
RuntimeMaxSec=5h
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7
UNIT
cat > /etc/systemd/system/kopia-backup.timer <<'TIMER'
[Unit]
Description=Daily kopia backup
[Timer]
OnCalendar=*-*-* 03:00:00
RandomizedDelaySec=45m
Persistent=true
Unit=kopia-backup.service
[Install]
WantedBy=timers.target
TIMER
systemctl daemon-reload
systemctl enable --now kopia-backup.timer
echo
echo "Smoke test:"
echo " systemctl start kopia-backup.service"
echo " journalctl -u kopia-backup.service -f"
After registering a client server-side and connecting from the client, set tenant-specific policies. The policy hierarchy means most hosts inherit globals; only deviations need explicit entries:
# On the kopia server, as the kopia user:
# Production hosts keep 30 days; staging keeps 7 days
kopia policy set --host db01 --keep-daily 30 --keep-weekly 12 --keep-monthly 24
kopia policy set --host stage01 --keep-daily 7 --keep-weekly 4 --keep-monthly 3
# Compress logs with zstd-best (slower, smaller), DB dumps with zstd-fastest
kopia policy set /var/log --compression=zstd-best
kopia policy set /var/lib/pgsql-dumps --compression=zstd-fastest
# A "panic" path that is excluded everywhere
kopia policy set --global --add-ignore '/var/lib/restic-cache'
Operational notes that catch teams the first time:
-
Server-cert fingerprint is the trust anchor. With self-signed TLS, the client validates by SHA-256 fingerprint. Rotate the cert by issuing both old + new fingerprints to clients during the cutover window. Behind a reverse proxy (nginx, Caddy) with a real CA cert, clients use normal CA validation and you skip fingerprint pinning.
-
kopia server useris the username database; client credentials are stored server-side. Clients never have the master repo password — only their per-tenant password. The server holds the repo password in/etc/kopia/server.env. -
Maintenance ownership is exclusive. Only one identity can be the maintenance owner. If the server VM is rebuilt and the new identity is different, transfer ownership:
kopia maintenance set --owner <new>. Don’t let clients become owners — they will block server-side maintenance. -
Server-side ACL restricts which paths a given user can write to. The server’s
kopia server aclcommands let you, for example, denyclient1@web01from writing to anything other than its own host’s snapshot manifest. Worth setting up for shared environments. -
Behind a reverse proxy. For real CA certs, terminate TLS at Caddy or nginx and proxy to
127.0.0.1:51515over HTTP. See Caddy reverse proxy deploy for the proxy side.
Stack Harbor runs Kopia repository servers for managed customers as part of environment management — server-side maintenance, per-tenant policy, off-account vault, and quarterly restore drills wired into the monitoring + on-call plane. Plan the rollout with our team.