-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-knot
executable file
·32 lines (32 loc) · 1.01 KB
/
backup-knot
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
28
29
30
31
32
#!/bin/bash
# shellcheck disable=SC2174
set -o nounset
#
# Copyright © 2024 Christopher Bock <[email protected]>
# SPDX-License-Identifier: MIT
#
BASE_BAK=/var/backups/knot/
BAK="$BASE_BAK/$(date -Im)"
DAYS=62
mkdir -p -m 0750 "$BASE_BAK"
mkdir -p -m 0750 "$BAK"
tar -czf "$BAK/etc_knot.tgz" -P /etc/knot
chown -Rf knot:knot "$BASE_BAK"
knotc -x zone-status|awk -F'[][]' '{print$2}'| sed 's/.$//g' | while read -r zone
do
su --command "mkdir --mode 0750 -p $BAK/$zone" --shell /bin/sh knot
{
knotc --blocking zone-freeze "$zone"
knotc --blocking zone-flush "$zone"
if knotc --blocking zone-backup "$zone" +backupdir "$BAK/$zone"; then
if ! test -e "$BAK/$zone/knot_backup.label"; then
{
echo "Failed backup of zone: $zone"
journalctl --since -5s --grep "$zone"
} >/dev/stderr
fi
fi
knotc --blocking zone-thaw "$zone"
} >/dev/null
done
su --command "find $BASE_BAK -maxdepth 1 -mindepth 1 -type d -mtime +$DAYS -exec rm -rf '{}' +" --shell /bin/sh knot