# Backing up files

How the buckets of an environment are backed up, every object with its metadata, only what changed, and how to leave a bucket or a folder out.


Every bucket Brewless manages for an environment at Scaleway Object Storage is in its backup, with every object and its metadata.

## How a bucket is backed up

The backup job copies the bucket to its own disk, keeping every object's last-modified time, and gives the objects to restic as files. restic stores only new and changed data, so an unchanged object adds nothing to the repository.

Next to the objects, every backup holds a **manifest** of the bucket (`manifest/<bucket>.jsonl`): per object its size, last-modified time, ETag, checksum, content type, cache control, content disposition, content encoding and its own metadata (`x-amz-meta-*`). A [restore](/running/restoring-backups) puts the metadata back from it, so a restored image is served with the same content type as before.

## What is left out by itself

| Bucket | Why |
| --- | --- |
| The application's own bucket for backups (`backup.bucket`) | It already holds backups, written by your application |
| The repository and state buckets of the backups | They are the backups |
| The private buckets of [Malware Protection](/running/malware-protection) | They hold files kept apart on purpose |
| A storage zone at bunny.net | It lives at the edge, not in your Scaleway account |
| A bucket another environment shares | It is backed up once, by the first production environment that uses it |

The Backups tab lists each of them with its reason.

## Leaving a bucket or a folder out

`exclude` in `brewless.yml` takes three kinds of rules:

```yaml
environments:
  production:
    backup:
      exclude:
        - bucket:shop-exports            # a whole bucket
        - database:shop-scratch          # a whole database
        - prefix:shop-files/cache/       # a folder of one bucket
```

A rule is refused when it starts with anything else. What you leave out is not in the backup, and the Recovery Kit says so.

## Large buckets

A backup job at Scaleway has a disk of 10 GB and cannot mount a bucket. A bucket larger than 8 GB, by the size Scaleway Cockpit measures, is therefore backed up on a **temporary Instance** instead:

1. The backup job backs up the databases, the smaller buckets and the configuration, and reports. The large buckets are listed as skipped, "on the Instance".
2. Brewless then makes a small Instance in the environment's project and zone, named `brewless-backup-<application>-<environment>-instance-<run>` (the last ten characters of the job's run), and sized by the number of objects in those buckets (about 3 GB of memory for five million objects): DEV1-S to DEV1-XL.
3. The Instance runs the same backup runner as the jobs, mounts the large buckets read-only, backs them up into the primary destination as part of the same recovery point, reports, and powers itself off. The next backup job copies its snapshots on to your other destinations.
4. Brewless removes the Instance with its disk. Every backup Instance carries a deadline (its `brewless-deadline` tag, at most 24 hours on); the hourly check removes one that is still there after it. Both are in the audit trail.

Until the Instance reports, the recovery point shows as running, and no success or failure is announced. When the Instance fails, stops without a report or reaches its deadline, the point becomes partly successful: the large buckets fail with `abandoned` or `deadline`, and the owners and admins get the usual mail.

The Instance works as the runner, with a key of its own that expires at the deadline. Its start-up script holds no secret: the keys wait in the state bucket behind a link that holds for 15 minutes, and are removed with the Instance. Brewless never signs in to it.

A bucket that grows past the job's disk between two looks fails with `source_too_large` once, and is backed up on the Instance from the next run on. It moves back to the job when it is at most half of the 8 GB again.

The [estimate](/backups/how-it-works#what-it-costs) on the Backups tab counts the Instance's hours at Scaleway's list prices: what the Instances of the last 30 days stood, or, before the first one, two hours per scheduled run.

> [!NOTE]
> The temporary Instance is switched on by Brewless together with the runner release that can mount on it. Until then every bucket is copied by the job, and one too large for its disk fails with `source_too_large`.

A bucket is backed up as one snapshot, however many objects it holds. A backup job runs at most 24 hours at Scaleway, and so does the Instance. A run that does not finish in that time fails, and its report says so.

## Files and the database are not taken at the same moment

The buckets are backed up after the databases, each at its own moment. A file your application uploaded after its database was taken can be in the backup without its row, and the other way round. See [known limitations](/backups/troubleshooting#known-limitations).
