> ## Documentation Index
> Fetch the complete documentation index at: https://snapr.seshuk.im/llms.txt
> Use this file to discover all available pages before exploring further.

# Jobs

> Job reference: cron schedules, compression formats, retention, hook scripts, sources, storages, encryption, splitting, and notifiers.

`jobs` is an array of backup jobs. Each job has a cron schedule, one or more sources, one or more storages, and a retention policy.

## Fields

| Option           | Type   | Required | Description                                                                             |
| ---------------- | ------ | -------- | --------------------------------------------------------------------------------------- |
| `name`           | string | Yes      | Unique job name.                                                                        |
| `schedule`       | cron   | Yes      | 5-field cron expression. See [Schedule](#schedule).                                     |
| `compression`    | enum   | No       | `tar`, `tar.gz`, `tar.zst`, `tar.xz`, `zip`. See [Compression](#compression).           |
| `sources`        | array  | Yes      | At least one source. See [Sources](/configuration/sources/overview).                    |
| `storages`       | array  | Yes      | At least one storage. See [Storages](/configuration/storages/overview).                 |
| `defaultStorage` | string | No       | `name` of the storage flagged as default in the UI.                                     |
| `retention`      | object | Yes      | See [Retention](#retention).                                                            |
| `beforeScript`   | string | No       | Shell snippet that runs before the job. See [Hook scripts](#hook-scripts).              |
| `afterScript`    | string | No       | Shell snippet that runs after the job. See [Hook scripts](#hook-scripts).               |
| `encryption`     | object | No       | Symmetric encryption. See [Encryption](/configuration/encryption).                      |
| `split`          | object | No       | Split the final archive into fixed-size parts. See [Splitter](/configuration/splitter). |
| `notifiers`      | array  | No       | Per-job notifications. See [Notifiers](/configuration/notifiers/overview).              |

## Schedule

Standard 5-field cron: `minute hour day-of-month month day-of-week`.

| Expression     | Meaning                       |
| -------------- | ----------------------------- |
| `0 2 * * *`    | Every day at 02:00            |
| `*/15 * * * *` | Every 15 minutes              |
| `0 3 * * 0`    | Every Sunday at 03:00         |
| `30 4 1 * *`   | 04:30 on the 1st of the month |
| `0 0 * * 1-5`  | Midnight on weekdays          |

<Note>
  Even with a future-dated cron, you can trigger a job immediately from the UI (**Run now**) or through the [REST
  API](/api-reference/overview). Manual runs respect retention and notifiers exactly like scheduled runs. To disable
  manual runs, set [`server.permissions.allowManualRun: false`](/configuration/server/permissions).
</Note>

## Compression

| Value     | Output     | Parallel | Description                                          |
| --------- | ---------- | -------- | ---------------------------------------------------- |
| `tar`     | `.tar`     | —        | No compression. Use for already-compressed payloads. |
| `tar.gz`  | `.tar.gz`  | Yes¹     | Classic gzip. Best compatibility.                    |
| `tar.zst` | `.tar.zst` | Yes      | zstd with `-T0`. Best speed-vs-ratio trade-off.      |
| `tar.xz`  | `.tar.xz`  | Yes      | xz with `-T0`. Highest ratio, slowest.               |
| `zip`     | `.zip`     | —        | Zip archive. Handy for Windows recipients.           |

¹ `tar.gz` uses [pigz](https://zlib.net/pigz/) when it is on `PATH` (all cores); otherwise it falls back to single-threaded `gzip` transparently.

Aliases: `gz` → `tar.gz`, `zst` / `zstd` → `tar.zst`, `xz` → `tar.xz`. Omit `compression` to use plain `tar` (no compression).

<Info>
  The official Docker image ships `tar`, `pigz`, `zstd`, `xz`, and `zip` preinstalled. On bare metal, install whichever
  compressor matches the formats you use — snapr returns a clear error at run time if a required binary is missing.
</Info>

## Retention

`retention.last` is **required** and must be at least `1`. After every successful run, snapr keeps the N newest archives for that job and deletes the rest from every storage attached to the job.

| Option | Type | Required | Description                              |
| ------ | ---- | -------- | ---------------------------------------- |
| `last` | int  | Yes      | Number of archives to keep (at least 1). |

```yaml theme={null}
retention:
  last: 30
```

## Hook scripts

`beforeScript` and `afterScript` run arbitrary shell commands around the job — quiesce a service, flush caches, clean up afterwards. Both fields are optional and accept multi-line YAML strings.

```yaml theme={null}
beforeScript: |
  systemctl stop my-app
afterScript: |
  systemctl start my-app
```

<Note>`afterScript` runs whether the job succeeded or failed.</Note>

## Example

```yaml snapr.yaml theme={null}
jobs:
  - name: postgres-nightly
    schedule: '0 3 * * *'
    compression: tar.gz
    sources:
      - type: postgresql
        host: db.internal
        username: postgres
        password: env:PG_PASSWORD
        database: app
    storages:
      - name: nas
        type: local
        path: /var/backups
      - name: offsite
        type: s3
        bucket: backups
        region: us-east-1
        accessKeyId: env:S3_KEY
        secretAccessKey: env:S3_SECRET
    defaultStorage: offsite
    retention:
      last: 30
    beforeScript: |
      systemctl stop my-app
    afterScript: |
      systemctl start my-app
    encryption:
      type: openssl
      cipher: aes-256-cbc
      password: env:BACKUP_ENC_PASSWORD
```
