homelab/roles/monica/files/monica.backup.sh

18 lines
550 B
Bash

cd /etc/monica
/usr/bin/docker compose exec -T db mysqldump -u monica -pmonica monica |
/usr/bin/gzip --rsyncable |
/usr/local/bin/restic backup --stdin --stdin-filename monica-mariadb.sql.gz
# Snapshot data directory
data_dir='/mnt/data1/monica/monica'
snapshot_dir="${data_dir}.snapshot"
# Read-only snapshot for atomic backup
btrfs subvolume snapshot -r "$data_dir" "$snapshot_dir" || exit $?
/usr/local/bin/restic backup "$snapshot_dir"
# Always remove snapshot subvolume, even if restic fails
btrfs subvolume delete "$snapshot_dir"