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

18 lines
550 B
Bash
Raw Permalink Normal View History

2024-01-11 22:28:00 +01:00
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"