Commit c6efb9b8 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Merge branch 'borg_backup_check' into 'master'

Borg backup check

See merge request archlinux/infrastructure!322
parents ddba82db 9b9e9a3e
Pipeline #5546 passed with stage
in 43 seconds
......@@ -6,6 +6,8 @@ src="/"
snapshotdir="backup-snapshot"
backup_mountdir="/backup"
declare -a list_of_btrfs_submounts
##
# usage : is_btrfs( $path )
# return : whether $path is on a btrfs
......@@ -22,6 +24,21 @@ delete_snapshot() {
btrfs subvolume delete --commit-after "$1"
}
##
# exit cleanup handler
##
cleanup() {
if is_btrfs "$src"; then
umount -R "$backup_mountdir"
for vol in $list_of_btrfs_submounts; do
delete_snapshot "$vol/$snapshotdir"
done
rmdir "$backup_mountdir"
fi
}
trap cleanup EXIT
if is_btrfs "$src"; then
# List all btrfs submounts we want to backup, e.g. homedir.archlinux.org with "/ /home"
list_of_btrfs_submounts=$(findmnt -Rl -o target,fstype,options / | grep btrfs | grep -v docker | grep -v "subvol=\/[[:alnum:]]" | cut -d ' ' -f1)
......@@ -75,11 +92,3 @@ borg create -v --stats -C zstd \
-e "$backup_mountdir/var/lib/docker" \
{{ item['host'] }}/{{ item['dir'] }}::$(date "+%Y%m%d-%H%M%S") "$backup_mountdir"
borg prune -v {{ item['host'] }}/{{ item['dir'] }} --keep-daily=7 --keep-weekly=4 --keep-monthly=6
if is_btrfs "$src"; then
umount -R "$backup_mountdir"
for vol in $list_of_btrfs_submounts; do
delete_snapshot "$vol/$snapshotdir"
done
rmdir "$backup_mountdir"
fi
[Unit]
Description=Prometheus Borg Exporter TextCollector
After=network.target
ConditionPathExistsGlob=!/root/.cache/borg/*/lock.roster
# If the backup snapshot path exists, the backup script runs and a borg
# lockfile exists and we can't run borg list
ConditionPathExists=!/backup
[Service]
Type=oneshot
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment