summaryrefslogtreecommitdiff
path: root/stdlib/backups/borg/borg-script-template
blob: c09c2978bf09d02434e50c308b0fdc07169bd196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash
set -euo pipefail

on_exit() {
  exit $?
}
trap on_exit EXIT

archiveName="%s-%s-$(date +%%Y-%%m-%%dT%%H:%%M:%%S)"
archiveSuffix=".failed"

# Run borg init if the repo doesn't exist yet
if ! borg list > /dev/null; then
  borg init --encryption none
fi
(
  borg create \
    --compression auto,zstd \
    "::${archiveName}${archiveSuffix}" \
    '%s'
)
borg rename "::${archiveName}${archiveSuffix}" "${archiveName}"

borg prune \
  --keep-daily=14 --keep-monthly=3 --keep-weekly=4 \
  --glob-archives '%s-%s*'
borg compact