move to snapshots-based backups

This commit is contained in:
Pim Kunis 2023-06-17 12:54:41 +02:00
parent 04becbb99d
commit feb29ed0bf
14 changed files with 65 additions and 92 deletions

View file

@ -0,0 +1,17 @@
location:
source_directories:
- /mnt/thecloud
repositories:
- /mnt/backups/share
retention:
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
hooks:
before_everything:
- virsh snapshot-create-as --domain tf-thecloud --name backup-thecloud --disk-only --quiesce --no-metadata --diskspec vda,snapshot=no --diskspec vdb,file=/kvm/snapshots/thecloud.qcow2
- guestmount -a /kvm/snapshots/thecloud.qcow2 -m /dev/sda1 --ro /mnt/thecloud
after_everything:
- guestunmount /mnt/thecloud && sleep 1
- virsh blockcommit tf-thecloud vdb --active --verbose --pivot
- rm /kvm/snapshots/thecloud.qcow2

View file

@ -1,3 +0,0 @@
#!/bin/bash
for i in $(virsh list --all --name --autostart); do virsh start "$i"; done

View file

@ -1,9 +0,0 @@
#!/bin/bash
for i in $(virsh list --state-running --name --autostart); do
virsh shutdown "$i"
echo Stopping domain "$i"
until virsh domstate "$i" | grep shut; do
sleep 0.5
done
done

View file

@ -1,3 +1,13 @@
- name: Create snapshots directory
file:
path: /kvm/snapshots
state: directory
- name: Create backup mountpoint
file:
path: /mnt/thecloud
state: directory
- name: Install Borg
apt:
pkg:
@ -9,31 +19,19 @@
name: apprise
- name: Copy Borgmatic script
template:
src: "{{ role_path }}/templates/backup.yml.j2"
copy:
src: "{{ role_path }}/backup.yml"
dest: /root/backup.yml
- name: Copy start_vms.sh
copy:
src: "{{ role_path }}/files/start_vms.sh"
dest: /root/start_vms.sh
mode: preserve
- name: Copy stop_vms.sh
copy:
src: "{{ role_path }}/files/stop_vms.sh"
dest: /root/stop_vms.sh
mode: preserve
- name: Copy systemd backup unit
copy:
src: "{{ role_path }}/files/backup.service"
src: "{{ role_path }}/backup.service"
dest: /etc/systemd/system/backup.service
notify: systemd daemon reload
- name: Copy systemd backup timer
copy:
src: "{{ role_path }}/files/backup.timer"
src: "{{ role_path }}/backup.timer"
dest: /etc/systemd/system/backup.timer
notify: systemd daemon reload

View file

@ -1,28 +0,0 @@
# vi: ft=yaml
location:
source_directories:
- /data
repositories:
- 'ssh://root@lewis.hyp/mnt/backups/hosts/{{ ansible_hostname }}'
retention:
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
storage:
unknown_unencrypted_repo_access_is_ok: true
relocated_repo_access_is_ok: true
hooks:
before_everything:
- 'apprise --body="{{ ansible_hostname }}: Stopping VMs" {{ apprise_url }} || true'
- /root/stop_vms.sh
- 'apprise --body="{{ ansible_hostname }}: Stopped VMs" {{ apprise_url }} || true'
after_everything:
- 'apprise --body="{{ ansible_hostname }}: Starting VMs" {{ apprise_url }} || true'
- /root/start_vms.sh
- 'apprise --body="{{ ansible_hostname }}: Started VMs" {{ apprise_url }} || true'
before_backup:
- 'apprise --body="{{ ansible_hostname }}: Performing backup" {{ apprise_url }} || true'
after_backup:
- 'apprise --body="{{ ansible_hostname }}: Backup done" {{ apprise_url }} || true'
on_error:
- 'apprise --body="{{ ansible_hostname }}: Backup error" {{ apprise_url }} || true'