setup borg backup #4
9 changed files with 102 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# templates
|
# templates
|
||||||
|
backup/config.yaml
|
||||||
services/fail2ban/jail.local
|
services/fail2ban/jail.local
|
||||||
services/forgejo/app.ini
|
services/forgejo/app.ini
|
||||||
services/matrix/config/homeserver.yaml
|
services/matrix/config/homeserver.yaml
|
||||||
|
|
35
backup/config.template.yaml
Normal file
35
backup/config.template.yaml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
source_directories:
|
||||||
|
- ${BASE_DIR}
|
||||||
|
- /tmp/container-server
|
||||||
|
|
||||||
|
repositories:
|
||||||
|
- path: ${BORG_REPO}
|
||||||
|
label: remote repo
|
||||||
|
|
||||||
|
exclude_patterns:
|
||||||
|
- ${BASE_DIR}/*/psql
|
||||||
|
|
||||||
|
compression: auto,zstd
|
||||||
|
encryption_passphrase: "${BORG_PASSPHRASE}"
|
||||||
|
archive_name_format: "{hostname}-{now:%Y-%m-%d-%H%M%S}"
|
||||||
|
|
||||||
|
retries: 5
|
||||||
|
retry_wait: 5
|
||||||
|
|
||||||
|
keep_daily: 3
|
||||||
|
keep_weekly: 4
|
||||||
|
keep_monthly: 12
|
||||||
|
|
||||||
|
checks:
|
||||||
|
- name: repository
|
||||||
|
frequency: 4 weeks
|
||||||
|
- name: archives
|
||||||
|
frequency: 8 weeks
|
||||||
|
|
||||||
|
check_last: 3
|
||||||
|
|
||||||
|
before_backup:
|
||||||
|
- /opt/container-server/backup/prepare-backup.sh
|
||||||
|
|
||||||
|
# after_backup:
|
||||||
|
# - echo "`date` - Finished backup"
|
8
backup/prepare-backup.sh
Executable file
8
backup/prepare-backup.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
rm -r /tmp/container-server
|
||||||
|
mkdir -p /tmp/container-server
|
||||||
|
|
||||||
|
cd /opt/container-server
|
||||||
|
|
||||||
|
task srv:psql-dump-all
|
41
backup/readme.md
Normal file
41
backup/readme.md
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# Backup
|
||||||
|
|
||||||
|
Backing up the BASE_DIR (default: /srv) should in theory be sufficient.
|
||||||
|
|
||||||
|
## Database Backup
|
||||||
|
|
||||||
|
As database servers like PostgreSQL might not play nicely with taking a backup of their data folders while running, it's advised to first dump the database and only include the dump in the backup.
|
||||||
|
|
||||||
|
Therefore, all database containers SHOULD follow a common naming folder scheme.
|
||||||
|
|
||||||
|
### postgres
|
||||||
|
|
||||||
|
**Scheme:** $BASE_DIR/{service}/psql
|
||||||
|
|
||||||
|
**Task:** `task srv:psql-dump -- {service}`
|
||||||
|
|
||||||
|
**Dump:** /tmp/container-server/{service}.sql
|
||||||
|
|
||||||
|
### {to be extended}
|
||||||
|
|
||||||
|
**Scheme:** $BASE_DIR/{service}/tbd
|
||||||
|
|
||||||
|
**Task:** `task srv:tbd-dump -- {service}`
|
||||||
|
|
||||||
|
**Dump:** /tmp/container-server/{service}.tbd
|
||||||
|
|
||||||
|
## Borgmatic
|
||||||
|
|
||||||
|
Create a repo on your backup server, e.g. https://www.borgbase.com
|
||||||
|
|
||||||
|
### Install
|
||||||
|
|
||||||
|
```sh
|
||||||
|
apk add borgmatic
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ln -vs /opt/container-server/backup/config.yaml /etc/borgmatic/config.yaml
|
||||||
|
```
|
|
@ -213,8 +213,8 @@ Add first line: `MAILTO=cron@<your domain>`.
|
||||||
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
ln -s /opt/container-server/setup/cron/daily/* /etc/periodic/daily/
|
ln -vs /opt/container-server/setup/cron/daily/* /etc/periodic/daily/
|
||||||
ln -s /opt/container-server/setup/cron/weekly/* /etc/periodic/weekly/
|
ln -vs /opt/container-server/setup/cron/weekly/* /etc/periodic/weekly/
|
||||||
```
|
```
|
||||||
|
|
||||||
### localhost alias
|
### localhost alias
|
||||||
|
|
3
setup/cron/daily/borgmatic
Executable file
3
setup/cron/daily/borgmatic
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
borgmatic --verbosity -1 --syslog-verbosity 1
|
4
setup/cron/weekly/check-updates
Executable file
4
setup/cron/weekly/check-updates
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
apk update --quiet
|
||||||
|
apk list --upgradable
|
|
@ -42,10 +42,16 @@ tasks:
|
||||||
psql-dump:
|
psql-dump:
|
||||||
desc: Dump postgres database for backup or update
|
desc: Dump postgres database for backup or update
|
||||||
cmds:
|
cmds:
|
||||||
|
# - echo "{{.TMP_DIR}}/{{.CLI_ARGS}}.sql"
|
||||||
- mkdir -p {{.TMP_DIR}}
|
- mkdir -p {{.TMP_DIR}}
|
||||||
- docker exec pg-{{.CLI_ARGS}} pg_dumpall -U {{.CLI_ARGS}} > {{.TMP_DIR}}/{{.CLI_ARGS}}.sql
|
- docker exec pg-{{.CLI_ARGS}} pg_dumpall -U {{.CLI_ARGS}} > {{.TMP_DIR}}/{{.CLI_ARGS}}.sql
|
||||||
- ls -la {{.TMP_DIR}}/{{.CLI_ARGS}}.sql
|
- ls -la {{.TMP_DIR}}/{{.CLI_ARGS}}.sql
|
||||||
|
|
||||||
|
psql-dump-all:
|
||||||
|
desc: Run 'psql-dump' task for each running postgres container
|
||||||
|
cmds:
|
||||||
|
- task compose:list | awk '/postgres/ { sub(/pg-/, "", $3) ; system("task srv:psql-dump -- "$3) }'
|
||||||
|
|
||||||
psql-restore:
|
psql-restore:
|
||||||
desc: Load postgres database for restore
|
desc: Load postgres database for restore
|
||||||
cmds:
|
cmds:
|
||||||
|
|
|
@ -20,11 +20,11 @@ tasks:
|
||||||
deps: [validate]
|
deps: [validate]
|
||||||
cmds:
|
cmds:
|
||||||
- |
|
- |
|
||||||
find services -name "*.template.*" | while read -r f
|
find . -name "*.template.*" | while read -r f
|
||||||
do
|
do
|
||||||
echo "templating $f"
|
echo "templating $f"
|
||||||
envsubst < $f > ${f/.template/}
|
envsubst < $f > ${f/.template/}
|
||||||
done
|
done
|
||||||
sources:
|
sources:
|
||||||
- services/**/*.template.*
|
- ./**/*.template.*
|
||||||
- .env
|
- .env
|
||||||
|
|
Loading…
Reference in a new issue