# Backing up to S3

> Paste one temporary key and Berth creates an EU bucket with versioning, Object Lock, a lifecycle rule and a key restricted to that bucket, then starts the encrypted copy.

Source: https://www.berthpanel.app/library/backup-to-s3/ · Category: backup · Updated: 2026-10-29

An external copy in S3-compatible object storage protects you against losing the server, and with Object Lock also against someone who gets hold of the server and tries to delete the backups. Berth can set this up for you from a single temporary key, or you can enter an existing bucket and keys yourself. This article covers both, plus encrypted loose archives and how to roll a bucket back after an attack.

For the general model of places and schedules, see [How backups work](https://www.berthpanel.app/library/backups-overview/).

## Two ways to use S3

| | Deduplicated place (restic) | Loose archives |
|---|---|---|
| Label | *External: moments, encrypted and deduplicated* | *External: loose archives (S3)* |
| What lands in the bucket | an encrypted restic repository | one archive per subscription per run |
| Transfer | only what changed | the whole archive each time |
| Server settings (for disaster recovery) | yes | no |
| Readable without Berth | with restic and the repository password | with `gpg` and the archive key |

The one-key wizard creates a deduplicated place. Use loose archives in addition when you want plain files that any Berth server, or a person with `gpg`, can pick up.

## The one-key wizard

The wizard supports five providers, in EU regions only:

| Provider | EU regions (default first) |
|---|---|
| Scaleway | `nl-ams`, `fr-par`, `pl-waw` |
| Backblaze B2 | follows the account (EU Central is `eu-central-003`) |
| AWS | `eu-central-1`, `eu-west-1`, `eu-west-3`, `eu-north-1`, `eu-south-1` |
| Wasabi | `eu-central-2`, `eu-central-1`, `eu-west-2`, `eu-south-1` |
| Hetzner | `fsn1`, `nbg1`, `hel1` |

For Backblaze, whose region follows the account, Berth refuses an account outside the EU unless you tick *Also an account outside the EU*.

### Steps in the panel

1. Go to *Backups → Places* → **Add place** and choose *Paste one key, the panel does the rest*. The page is titled *External copy with one key*.
2. Choose the provider and the EU region. The page shows which temporary key to create in the provider's console and which permissions it needs.
3. Paste the **temporary administrative key**.
4. Choose the lock mode, *GOVERNANCE* or *COMPLIANCE*, and the retention in days. See below.
5. Optionally adjust how long the copy keeps snapshots (daily, weekly, monthly; default 7, 4 and 6).
6. Tick *First copy and restore test right away*. The result arrives as a notification.
7. Save the **repository password** that is shown once, outside the server, for example in a password vault. Without it the copy cannot be opened after the server is lost.

### What the wizard creates

- **A bucket in the chosen EU region** with versioning and Object Lock, and a default retention.
- **A restricted key** that can only reach that bucket. It can list, read, write and place delete markers, but it can never bypass or change the lock, set retention or delete the bucket. On AWS the policy explicitly denies `s3:BypassGovernanceRetention`; on Backblaze the key is limited to the new bucket and lacks the bypass capability.
- **A lifecycle rule** named `berth-restic` (see below).
- **The encrypted copy**, configured with the restricted key and a new repository password. From then on a copy refuses to run against a bucket that no longer locks.
- **A nightly schedule** to the new place that carries the server settings and the archives on this server, so a full [disaster recovery](https://www.berthpanel.app/library/disaster-recovery/) is possible from the first night. For hourly or more frequent off-site snapshots straight from the sources, add a schedule of your own to the same place under *Backups → Schedules*.

The temporary key is held only in memory for the duration of the setup. It is not stored in the database, logs, audit trail or error messages, and it is only sent to the provider's fixed API addresses. Delete it at the provider afterwards. If anything fails halfway, the wizard removes what it had already created and tells you what might remain.

**Hetzner** has no keys per bucket. The copy therefore uses the S3 keys you pasted. Use a dedicated project for backups and choose COMPLIANCE. A dedicated project for backups is good practice with every provider.

### From the command line

The key goes in a file (two lines: key and secret, or `access_key=…` and `secret_key=…`) or on stdin, never as an argument:

```bash
umask 077
printf '%s\n%s\n' "$KEY_ID" "$SECRET" > /root/temp-key
berth backup remote setup --provider scaleway --region nl-ams \
  --mode COMPLIANCE --days 60 --key-file /root/temp-key --first-copy
rm /root/temp-key
```

`--first-copy` waits until the first copy and the restore test have finished. The API equivalent is `POST /api/v1/backups/remote/setup`; see the [REST API](https://www.berthpanel.app/library/rest-api/).

## Object Lock: GOVERNANCE or COMPLIANCE

With Object Lock, every version of every object stays for at least the retention period, even if someone with the key "deletes" everything. A delete then only adds a delete marker; the data underneath remains.

- **GOVERNANCE** (the default): the owner of the storage account can still remove locked versions through the provider's console. Suits teams that want a way out, for example to stop paying for storage after a mistake.
- **COMPLIANCE**: nobody can remove anything until the term has ended, not you and not the provider. Suits environments where backups must be provably immutable, and anywhere the storage account itself could be compromised.

Object Lock can only be enabled when a bucket is created. For an existing place, the place's page shows whether versioning and Object Lock are active, lets you set the default retention, and offers *Only copy if the bucket locks*, so a run refuses to write to a bucket without a lock:

```bash
berth backup remote s3-lock --mode COMPLIANCE --days 30 --require
berth backup remote s3-status
```

## The lifecycle rule

With versioning, restic's cleanup never really deletes anything: old versions and delete markers stay behind, and without a rule the storage (and the bill) grows forever. Berth therefore sets a lifecycle rule `berth-restic` on the repository's folder:

- old versions are removed after **N days**;
- delete markers with nothing behind them are removed;
- unfinished uploads are removed after 7 days.

N is the default retention plus 7 days of margin (30 days of retention gives 37), or 30 days with versioning but no retention. Berth sets the rule when connecting, when you change the retention, and after each copy. Other rules in the bucket are left alone. The place's page and `berth backup remote s3-status` show "old versions disappear after N days" (`lifecycle.days`).

If the provider has no lifecycle rules, or the key may not manage them, the copy still runs, but the page, the CLI and `berth doctor` warn that old versions stay. When the wizard set the rule with the temporary key, the restricted key may not be able to read it back; the page then says the rule was set during setup and only warns when a longer retention needs a longer rule.

## Rolling a bucket back to before an attack

If someone with the storage keys "deleted" your backups, the data is still there under delete markers. Roll the bucket back to a moment before the attack, then restore as usual.

In the panel: the place's page → *Restore after an attack…*, fill in *Back to before* and first count what would change, then confirm with *Really restore*.

```bash
berth backup remote s3-restore --before "2026-10-20 03:00"           # count only
berth backup remote s3-restore --before "2026-10-20 03:00" --apply   # really
berth backup remote verify
```

Add `--location <id>` when you have more than one deduplicated place. Rolling back works within the lifecycle window of N days, because after that the old versions are gone. Choose the retention with that in mind: if you might notice an attack late, choose a longer retention, or keep a second copy elsewhere, for example on a [NAS](https://www.berthpanel.app/library/backup-to-nas/).

## Setting up S3 by hand

If you already have a bucket and keys, or use another S3 service such as MinIO, choose *Or enter the details yourself* when adding a place: provider or own address, region, bucket, an optional folder, access key and secret key. An address must be an EU address of the chosen provider, unless you choose *Other address*.

```bash
umask 077
printf 'access_key=%s\nsecret_key=%s\n' "$AK" "$SK" > /root/s3-keys
berth backup location add --kind restic --name "Offsite EU" --storage s3 \
  --fields endpoint=https://s3.example.com,bucket=acme-backups,path=server1 \
  --keys-file /root/s3-keys
```

Without `--password-file`, Berth generates the repository password and shows it once. Backblaze B2 (native API), SFTP, a REST server, Azure Blob Storage, Google Cloud Storage and a mounted path are set up the same way with `--storage b2|sftp|rest|azure|gcs|path`. For SFTP, the page then shows the server's public key to put in `authorized_keys` on the backup server.

## Loose archives in S3

Under *Add place*, *External: loose archives (S3)* stores each archive as an object in a bucket. You choose how many archives per subscription to keep, and Berth labels the place EU or outside the EU.

### Encryption with an archive key

A new loose-archive place encrypts archives itself, before upload, with an **archive key** for that place (OpenPGP, AES-256). The provider only sees encrypted files; server-side encryption by the provider (SSE) can be added on top. The checkbox is *Encrypt archives locally*; on an existing place, tick it to start encrypting new archives.

Berth shows the key once after adding the place. Later you can show it again with *Show archive key* on the place's page or `berth backup location archive-key <id>`; that action is recorded in the audit trail. **Store it outside the server.** Without it, the archives cannot be restored on a new server.

Decrypting without Berth needs nothing but `gpg`:

```bash
gpg --decrypt 20261020-013000.tar.gz.gpg > 20261020-013000.tar.gz   # passphrase: the archive key
```

On a new server, add a loose-archive place with the same bucket, the access keys and the archive key (`--archive-key-file`), then fetch archives with `berth backup fetch`; they are decrypted on the way in. Archives that a customer encrypted with their [own OpenPGP key](https://www.berthpanel.app/library/backups-overview/#the-customer-s-own-openpgp-key) are stored and fetched as they are.

```bash
berth backup location add --kind s3 --name "Archives EU" \
  --endpoint https://s3.example.com --bucket acme-archives --prefix server1 \
  --keys-file /root/s3-keys
berth backup schedule add --name "Archives to S3" --location <id> \
  --schedule daily --hour 3 --keep 14
```

## Related

- [Restoring files, mail and databases](https://www.berthpanel.app/library/restoring-data/)
- [Restore tests](https://www.berthpanel.app/library/restore-tests/)
- [Disaster recovery](https://www.berthpanel.app/library/disaster-recovery/)
