add backup service

This commit is contained in:
Pim Kunis 2023-04-11 22:10:57 +02:00
parent 4946f503a2
commit 72240e1382
6 changed files with 57 additions and 2 deletions

View file

@ -3,7 +3,7 @@ dataserver_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJsLVptkoOwmxs6DnenN
user_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRBrKmIKP5BFhLSdntatIgSC0R/D9EEZlak5Yt0DfUe root@lewis"
kingston1tb_mount_point: "/mnt/kingston1TB"
kingston1tb_uuid: "622a8d81-aa2f-460b-a563-c3cdb6285609"
backup_location: "{{ kingston1tb_mount_point }}/homeserver_backup"
backup_location: "{{ kingston1tb_mount_point }}/atlas_backup"
admin_public_keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINUZp4BCxf7uLa1QWonx/Crf8tYZ5MKIZ+EuaBa82LrV user@user-laptop"

View file

@ -0,0 +1,10 @@
[Unit]
Description=Backup data daily
[Timer]
OnCalendar=*-*-* 3:00:00
Persistent=true
RandomizedDelaySec=1h
[Install]
WantedBy=timers.target

View file

@ -1,3 +1,28 @@
- name: Install borg
apt:
pkg:
- borgbackup
- borgmatic
- name: Copy borg backup config
template:
src: "{{ role_path }}/templates/backup.yml.j2"
dest: /root/backup.yml
- name: Copy systemd service
template:
src: "{{ role_path }}/templates/backup.service.j2"
dest: "/etc/systemd/system/backup.service"
register: service
- name: Copy systemd timer
copy:
src: "{{ role_path }}/files/backup.timer"
dest: "/etc/systemd/system/backup.timer"
register: timer
- name: Enable timer
systemd:
name: backup.timer
enabled: true
state: started
daemon_reload: "{{ 'yes' if service.changed or timer.changed else 'no' }}"
- name: Create extra disk moint point
file:
path: "{{ kingston1tb_mount_point }}"

View file

@ -0,0 +1,6 @@
[Unit]
Description=Backup data using borgmatic
[Service]
ExecStart=/usr/bin/borgmatic --config /root/backup.yml
Type=oneshot

View file

@ -0,0 +1,14 @@
location:
source_directories:
- /mnt/atlas
repositories:
- {{ backup_location }}
retention:
keep_daily: 7
keep_weekly: 4
keep_monthly: 6
hooks:
before_everything:
- echo down | ssh backup-control@atlas.lan
after_everything:
- echo up | ssh backup-control@atlas.lan

View file

@ -49,7 +49,7 @@
state: directory
- name: Mount atlas data
mount:
src: "lewis@atlas.lan:"
src: "backup-share@atlas.lan:"
path: "/mnt/atlas"
state: mounted
fstype: fuse.sshfs