> Index of every page on this site: [llms.txt](https://docs.a-line.cloud/llms.txt)

# Volumes, backups and cron jobs

> Persistent volumes, sharing them between apps, backups and scheduled jobs.

The examples on this page share one project, `shop`, which also manages a
bucket for its backups.

```yaml title="projects/shop/project.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
name: shop
cluster: hetzner-fsn1
buckets:
  - name: shop-backups
    quota_gb: 100
```

```yaml title="clusters/hetzner-fsn1.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
provider: hetzner
region: fsn1
pools:
  - name: control-plane
    role: control_plane
  - name: general
```

## Volumes

```yaml title="projects/shop/apps/media.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
source:
  image: ghcr.io/example/media:1.0.0
port: 8080
volumes:
  - name: uploads
    mount_path: /data/uploads
    size: 20Gi
    access_mode: ReadWriteMany
    auto_expand:
      threshold_percent: 80
      increment_gb: 10
      max_size_gb: 200
backup_policies:
  - name: nightly-uploads
    source:
      volume: uploads
    schedule: "0 3 * * *"
    retention_count: 14
    targets:
      - bucket: shop-backups
        primary: true
```

| Volume key | Meaning |
| --- | --- |
| `name`, `mount_path` | The volume's name and where it is mounted. |
| `size` | The size, such as `10Gi`. |
| `access_mode` | `ReadWriteOnce` (the default) for a volume used by one node, or `ReadWriteMany` to share it. |
| `auto_expand` | Grow the volume when its usage reaches `threshold_percent` (default 80), by `increment_gb` (default 5), up to `max_size_gb`. |
| `read_only` | Mount the volume read-only. |
| `storage_class` | `longhorn` or `lvm-localpath`; left out, the cluster default. A `ReadWriteMany` volume can't use `lvm-localpath`. |
| `replicas` | How many copies Longhorn keeps, 1 to 3. Only with `storage_class: longhorn`, at most the node count of the cluster's largest Longhorn pool, and fixed once the volume exists (`volume_immutable_field`). |

See [`VolumeSpec`](/iac/reference/types#volumespec) for every key.

### Sharing a volume

`volume_mounts` mounts another app's volume, read-only. `from` is
`<app>/<volume>`, and the volume must be `ReadWriteMany`.

```yaml title="projects/shop/apps/thumbnails.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
source:
  image: ghcr.io/example/thumbnails:1.0.0
volume_mounts:
  - from: media/uploads
    mount_path: /data/uploads
```

## Backups

`backup_policies` backs up a volume (`source: {volume: <name>}`) or a
database app's data (`source: database`) to one or more buckets.

| Policy key | Default |
| --- | --- |
| `schedule` | `0 2 * * *` (a cron expression) |
| `retention_count`, `retention_days` | 7 and 7 |
| `backup_type` | `full` |
| `compression` | `gzip` |
| `enabled` | `true` |

A target bucket must be managed by the same link, or be
[granted](/iac/references#grants) to it. `strategy` names a backup strategy
of your organization, also by grant.

A database template app also takes a simpler `backup` block, with
`enabled`, `schedule`, `retention_days` and `compression`:

```yaml title="projects/shop/apps/db.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
source:
  template: postgres
  version: "16"
backup:
  enabled: true
  schedule: "0 2 * * *"
  retention_days: 14
```

Backups are never deleted with their app. See
[`BackupPolicySpec`](/iac/reference/types#backuppolicyspec).

## Cron jobs

```yaml title="projects/shop/apps/reports.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
source:
  image: ghcr.io/example/reports:1.0.0
cron_jobs:
  - name: daily-report
    schedule: "30 6 * * *"
    timezone: Europe/Amsterdam
    command: ["/app/report", "--daily"]
    memory_limit: 1Gi
```

A cron job runs the app's image (or `image_override`) on a cron `schedule`.

| Key | Default |
| --- | --- |
| `timezone` | `UTC` |
| `concurrency_policy` | `Forbid` |
| `cpu_limit`, `memory_limit` | `500m` and `512Mi` |
| `successful_jobs_history`, `failed_jobs_history` | 3 |
| `suspended` | `false` |

See [`CronJobSpec`](/iac/reference/types#cronjobspec).

## Bucket access

`storage_bindings` gives the app credentials for a bucket as environment
variables. The bucket must be managed by the same link, or be
[granted](/iac/references#grants) to it.

```yaml title="projects/shop/apps/exporter.yaml" iac
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
source:
  image: ghcr.io/example/exporter:1.0.0
storage_bindings:
  - bucket: shop-backups
    permission: write_only
    key_prefix: media/
    env_prefix: BACKUP
    credential_mode: per_pod
```

| Key | Meaning |
| --- | --- |
| `bucket` | The bucket's name. |
| `permission` | `read_write` (the default), `read_only` or `write_only`. |
| `key_prefix` | Limit access to object keys under this prefix. |
| `env_prefix` | Prefix of the variable names, default `S3`. Upper-case letters, digits and `_`, starting with a letter, at most 32 characters. |
| `credential_mode` | `static` (the default) or `per_pod`, see below. |

| `credential_mode` | Credentials |
| --- | --- |
| `static` | One key shared by every pod of the app. |
| `per_pod` | Each pod gets its own key through a dynamic secret lease. The key is revoked when the lease ends, when the binding is removed and when the app is deleted. |

`write_only`, `key_prefix` and `per_pod` need the A-Line S3 gateway. A
platform that serves S3 in direct mode refuses them, and an external
storage needs **Route through A-Line gateway** turned on for `per_pod`.

See [`StorageBindingSpec`](/iac/reference/types#storagebindingspec).
