SFTP
The SFTP backend stores the kopia repository on a server reached over SSH and SFTP: a NAS, a VPS, anything you can sftp into. Kopiur uses key-based authentication, meaning an SSH private key plus a pinned known_hosts entry, both delivered as files.
Reach for SFTP when the target is a remote host with SSH but no object-store API. For the same NAS mounted as a volume, see filesystem.
Provider prerequisites
Section titled “Provider prerequisites”-
An SFTP account on the server and a path for the repository, such as
/volume1/kopia. The account must be able to read, write, and create there. -
An SSH private key for that account. Kopiur supports key-based authentication only; there is no password option. Add the matching public key to the server’s
authorized_keys. -
The server’s host key, so you pin
known_hostsinstead of trusting on first use:Terminal window $ ssh-keyscan -p 22 nas.lannas.lan ssh-ed25519 AAAAC3Nz...
The Secret shape
Section titled “The Secret shape”SFTP is one of the three file-delivered backends, and the most asked-about, so here is exactly what the Secret looks like.
kopia’s SFTP backend has no environment-variable credential form. And a Secret key like ssh-privatekey is not a valid environment-variable name, because envFrom silently drops keys containing a dash.
So Kopiur standardizes on two environment keys that are valid identifiers. The mover reads them, writes each to a private file with mode 0600, and passes --keyfile and --known-hosts to kopia.
| Secret key | Required | What it is | Becomes |
|---|---|---|---|
KOPIA_SFTP_KEY_DATA |
yes | The SSH private key in PEM form, exactly as generated, including the whole BEGIN…END block. |
a 0600 keyfile → kopia --keyfile |
KOPIA_SFTP_KNOWN_HOSTS |
yes | One known_hosts line for the server (from ssh-keyscan). |
a file → kopia --known-hosts |
KOPIA_PASSWORD |
yes | The repository encryption password. | env var kopia reads |
stringData: KOPIA_SFTP_KEY_DATA: | -----BEGIN OPENSSH PRIVATE KEY----- REPLACE_ME -----END OPENSSH PRIVATE KEY----- KOPIA_SFTP_KNOWN_HOSTS: "nas.lan ssh-ed25519 AAAAC3Nz...REPLACE_ME" KOPIA_PASSWORD: "choose-something-long-and-random"The complete, apply-ready Secret + Repository is below.
The Repository
Section titled “The Repository”---apiVersion: v1kind: Secretmetadata: name: sftp-repo-creds namespace: backupstype: OpaquestringData: # SSH key-based auth. kopia's SFTP backend has no env-var credential form, so # the operator's mover reads these two keys from the env (envFrom) and writes # them to files, then passes `--keyfile`/`--known-hosts` to kopia. The key # NAMES must be valid env identifiers (this is why it's KOPIA_SFTP_KEY_DATA, # not `ssh-privatekey` — a dashed key is dropped by Kubernetes envFrom). KOPIA_SFTP_KEY_DATA: | -----BEGIN OPENSSH PRIVATE KEY----- REPLACE_ME -----END OPENSSH PRIVATE KEY----- # Pin the server host key (avoid trust-on-first-use). Get it with: # ssh-keyscan -p 22 nas.lan KOPIA_SFTP_KNOWN_HOSTS: "nas.lan ssh-ed25519 AAAAC3Nz...REPLACE_ME" KOPIA_PASSWORD: "choose-something-long-and-random"---apiVersion: kopiur.home-operations.com/v1alpha1kind: Repositorymetadata: name: sftp-primary namespace: backupsspec: backend: sftp: host: nas.lan # SFTP server hostname or IP port: 22 # optional; defaults to 22 path: /volume1/kopia # remote path holding the repository username: backup # SSH user to connect as auth: secretRef: name: sftp-repo-creds encryption: passwordSecretRef: name: sftp-repo-creds key: KOPIA_PASSWORD create: enabled: trueFields reference (backend.sftp)
Section titled “Fields reference (backend.sftp)”| Field | Required | Default | Example | What it controls |
|---|---|---|---|---|
host |
yes | — | nas.lan |
SFTP server hostname or IP. It must match the name in the known_hosts line, because that is how the entry is looked up. |
path |
yes | — | /volume1/kopia |
Remote absolute path on the server that holds the repository. The SSH user must be able to write it. |
port |
no | 22 |
2222 |
TCP port. Any port other than 22 changes the known_hosts format. See the warning below. |
username |
no | — | kopia |
SSH user to connect as: the account whose authorized_keys holds the public key. |
auth.secretRef |
no | — | { name: sftp-repo-creds } |
Names the Secret holding the key + known_hosts above. Same namespace as the Repository; a ClusterRepository adds namespace:. |
SSH has no cloud IAM to federate with, so SFTP’s auth is Secret-only. There is no workloadIdentity here. A stray auth.workloadIdentity is not rejected; the API server silently prunes it, because it isn’t in the schema.
Customization — the values you actually change
Section titled “Customization — the values you actually change”host,port,path, andusernameare the connection coordinates.KOPIA_SFTP_KNOWN_HOSTSmust be updated if the server is rebuilt or its host key rotates. Re-runssh-keyscanand paste the new line.create.enabledinitializes the repository if it’s missing.
As a ClusterRepository
Section titled “As a ClusterRepository”The same backend.sftp stanza works on a cluster-scoped ClusterRepository, with two requirements. Every Secret reference must carry an explicit namespace:, and the Secret holding the key, the known_hosts line, and the password must exist in the namespaces the movers run in. See Movers.
Try it end-to-end
Section titled “Try it end-to-end”Prove this backend really takes a backup. The same example file carries a tiny smoke-test: a throwaway PVC, a SnapshotPolicy, and a Snapshot, all pointed at the sftp-primary repository above. It takes you from “applied” to “a snapshot on my server” in one go.
1. Apply the bundle. That is the backups namespace, the Secret, the Repository, and the smoke-test objects:
$ kubectl apply -f deploy/examples/backends/sftp.yaml2. Wait for the repository to be Ready. Everything else waits on this:
$ kubectl -n backups wait --for=condition=Ready repository/sftp-primary --timeout=2mrepository.kopiur.home-operations.com/sftp-primary condition met3. Take the smoke backup. The Snapshot uses generateName, so create it rather than apply it. The namespace, Secret, Repository, PVC, and policy already exist and report unchanged. The Snapshot is the one new object:
$ kubectl create -f deploy/examples/backends/sftp.yamlsnapshot.kopiur.home-operations.com/smoke-now-abc12 created4. Watch it succeed:
$ kubectl -n backups get snapshots -wNAME PHASE ORIGIN SNAPSHOT AGEsmoke-now-abc12 Pending manual 2ssmoke-now-abc12 Running manual 7ssmoke-now-abc12 Succeeded manual k1f1ec0a8 38sThe output above is illustrative. The Snapshot has no fixed Succeeded condition, so to wait on it in a script, key on the phase:
$ kubectl -n backups wait --for=jsonpath='{.status.phase}'=Succeeded \ snapshot/smoke-now-abc12 --timeout=5m5. Prove the data really moved. status.stats shows non-zero bytesNew and filesNew, and status.snapshot.kopiaSnapshotID is the kopia snapshot ID on your server:
$ kubectl -n backups get snapshot smoke-now-abc12 -o jsonpath='{.status.stats}'{"sizeBytes":4096,"bytesNew":1280,"filesNew":2,"filesUnchanged":0}
$ kubectl -n backups get snapshot smoke-now-abc12 -o jsonpath='{.status.snapshot.kopiaSnapshotID}'k1f1ec0a8Both outputs are illustrative; sizes and the ID vary. Non-zero bytesNew proves the backup uploaded real content over SFTP.
6. Clean up the smoke-test when you’re done:
$ kubectl -n backups delete snapshot --all # finalizer also deletes the kopia snapshot$ kubectl -n backups delete snapshotpolicy smoke$ kubectl -n backups delete pvc smoke-dataFrom here the rest of the lifecycle is the same on every backend. Only the Repository differs. Put it on a cron with a SnapshotSchedule, described in Backups & schedules and Example 01. Restore by picking a Snapshot, described in Restores and Example 03.
Troubleshooting
Section titled “Troubleshooting”permission denied (publickey). Either the public key isn’t in the server’sauthorized_keys, or the private key underKOPIA_SFTP_KEY_DATAis malformed: clipped, re-indented, or simply the wrong key.- Writes fail after connecting. The SSH user can’t write
path. Fix the ownership and permissions on the server.
See also
Section titled “See also”- Repositories & backends: the concepts, meaning scope, encryption, and creation.
- Permissions, UID & GID: server-side ownership of the repository path.
- Movers, RBAC & credentials: where the credential Secret must live.
- Sibling backend: filesystem, the same NAS as a mounted volume.