monica: add backup script

main
Jef Roosens 2024-01-11 22:28:00 +01:00
parent 363eaecc07
commit 86f741c3e9
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,17 @@
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"

View File

@ -43,3 +43,11 @@
chdir: '/etc/monica' chdir: '/etc/monica'
cmd: 'docker compose up -d --remove-orphans' cmd: 'docker compose up -d --remove-orphans'
when: 'res.changed' when: 'res.changed'
- name: Ensure backup script is present
ansible.builtin.copy:
src: 'monica.backup.sh'
dest: '/etc/backups/monica.backup.sh'
owner: 'root'
group: 'root'
mode: '0644'