restic and Kopia
restic and Kopia are open-source tools for encrypted, deduplicated backups of servers and workstations. Both store their repository directly in an S3 bucket, including chili. Kopia can also set Object Lock retention. The full guides are in the restic documentation and the Kopia documentation.
Prerequisites
- a current version of restic or Kopia
- chili access keys (access key and secret key) of the IAM user
- for restic: a bucket, created in the chili Console, with the template
rclone or scripts(Object Lock off, versioning on) - for Kopia without Object Lock: the same template
rclone or scripts - for Kopia with Object Lock: a bucket with the template
Other backup softwareand the retentionChosen by the application, see the section "Immutability with Kopia"
The commands restic init and kopia repository create only create the repository inside an existing bucket, not a new bucket.
Connection values
Field | restic | Kopia |
|---|---|---|
Endpoint | in the repository path: |
|
Region |
|
|
Access key |
|
|
Secret key |
|
|
Bucket | part of the repository path |
|
Prefix | part of the repository path |
|
Path style | automatic with a custom endpoint, force with | automatic with a custom endpoint |
1. Set up restic
Set the credentials as environment variables. The repository password encrypts all data; without it, no restore is possible.
export AWS_ACCESS_KEY_ID=AKIA...
export AWS_SECRET_ACCESS_KEY=...
export AWS_DEFAULT_REGION=ch-east
export RESTIC_REPOSITORY=s3:https://s3-ch-east.chilistorage.com/restic-backup/server01
export RESTIC_PASSWORD_FILE=/root/.restic-passwordCreate the repository in the existing bucket and run the first backup:
restic init
restic backup /etc /home /srv
restic snapshotsRestore, clean up old snapshots and check the repository:
restic restore latest --target /tmp/restore
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
restic check --read-data-subset=5%forget --prune deletes data in the bucket that is no longer needed. restic needs delete permission for this. The access level Read, write and delete from the template covers it.
2. Set up Kopia
Create the repository in the existing bucket. Kopia asks for a repository password; alternatively, set KOPIA_PASSWORD.
kopia repository create s3 \
--bucket kopia-backup \
--prefix server01/ \
--endpoint s3-ch-east.chilistorage.com \
--region ch-east \
--access-key AKIA... \
--secret-access-key ...Back up, list, set retention and restore:
kopia snapshot create /etc /home /srv
kopia snapshot list
kopia policy set --global --keep-daily 7 --keep-weekly 4 --keep-monthly 12
kopia restore <snapshot-id> /tmp/restoreOn another machine, connect with kopia repository connect s3 and the same parameters.
Immutability with Kopia
Kopia can set an Object Lock retention period when the repository is created and then applies it to every object it writes. This requires a bucket with Object Lock; versioning is switched on automatically. Create it in the chili Console with the template Other backup software and the retention Chosen by the application, so that Kopia sets the period itself. Background: Object Lock.
kopia repository create s3 \
--bucket kopia-locked \
--prefix server01/ \
--endpoint s3-ch-east.chilistorage.com \
--region ch-east \
--access-key AKIA... \
--secret-access-key ... \
--retention-mode GOVERNANCE \
--retention-period 30d
kopia maintenance set --extend-object-locks trueWith --extend-object-locks true, full maintenance keeps extending the retention. The full maintenance interval must be at least one day shorter than --retention-period, otherwise Kopia refuses the setting. More details are in Ransomware Protection in the Kopia documentation.
In a versioned bucket, deleted objects only receive a delete marker; the locked versions stay until their retention ends and continue to be billed. Set up a lifecycle rule that removes noncurrent versions after the retention period. Give Kopia an access key without the s3:BypassGovernanceRetention permission.
restic does not set Object Lock retention. A default retention on the bucket does not make sense for restic: forget --prune would only set delete markers, the locked data would remain and be billed, and restic cannot restore older object versions by itself. If you need immutable backups, use Kopia.
Verify
After the first backup, restore individual files and a whole folder into an empty directory and compare the contents. Check integrity regularly with restic check --read-data-subset or kopia snapshot verify. Reading costs nothing on chili, because there are no egress fees.
Common pitfalls
- restic reports a region or bucket location error: set
AWS_DEFAULT_REGION=ch-east. - DNS errors with the bucket name in the hostname: force path style with
-o s3.bucket-lookup=path. - Kopia expects the endpoint without a scheme: enter
s3-ch-east.chilistorage.comwithouthttps://. - Repository password lost: the data is encrypted and cannot be recovered. Keep the password separate from the system being backed up.
- Kopia cannot set `--retention-mode`: the bucket was created without Object Lock. Object Lock cannot be enabled later; create a new bucket.
- Storage keeps growing despite cleanup: versioning keeps deleted data as older versions. Set up a lifecycle rule for noncurrent versions.