Configs and provisioning files for my Alpine Linux servers: ufw, Caddy, Docker Compose, borgbackup, and neovim.
alpinealpine-linuxborgbackupcaddydockerdocker-composehandcodedneovimself-hostedserver-configurationshellufw
1#!/bin/sh
2# Based off of https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups
3# Init the repo with borg init -e none /srv/backup
4
5# Setting this, so the repo does not need to be given on the commandline:
6export BORG_REPO=/srv/backup
7
8# some helpers and error handling:
9info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
10trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
11
12info "Starting backup"
13
14# Backup the most important directories into an archive named after
15# the machine this script is currently running on:
16
17borg create \
18 --verbose \
19 --filter AME \
20 --list \
21 --stats \
22 --show-rc \
23 --compression lz4 \
24 --exclude-caches \
25 \
26 ::'{now}' \
27 /srv/git \
28 /srv/docker \
29 /srv/data \
30 /etc/caddy \
31
32backup_exit=$?
33
34info "Pruning repository"
35
36# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
37# archives of THIS machine.
38
39borg prune \
40 --list \
41 --show-rc \
42 --keep-daily 7 \
43 --keep-weekly 4 \
44 --keep-monthly 6 \
45
46prune_exit=$?
47
48# actually free repo disk space by compacting segments
49
50info "Compacting repository"
51
52borg compact
53
54compact_exit=$?
55
56# use highest exit code as global exit code
57global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
58global_exit=$(( compact_exit > global_exit ? compact_exit : global_exit ))
59
60if [ ${global_exit} -eq 0 ]; then
61 info "Backup, Prune, and Compact finished successfully"
62elif [ ${global_exit} -eq 1 ]; then
63 info "Backup, Prune, and/or Compact finished with warnings"
64else
65 info "Backup, Prune, and/or Compact finished with errors"
66fi
67
68exit ${global_exit}