add backup service
This commit is contained in:
parent
4946f503a2
commit
72240e1382
6 changed files with 57 additions and 2 deletions
|
@ -3,7 +3,7 @@ dataserver_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJsLVptkoOwmxs6DnenN
|
||||||
user_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRBrKmIKP5BFhLSdntatIgSC0R/D9EEZlak5Yt0DfUe root@lewis"
|
user_public_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRBrKmIKP5BFhLSdntatIgSC0R/D9EEZlak5Yt0DfUe root@lewis"
|
||||||
kingston1tb_mount_point: "/mnt/kingston1TB"
|
kingston1tb_mount_point: "/mnt/kingston1TB"
|
||||||
kingston1tb_uuid: "622a8d81-aa2f-460b-a563-c3cdb6285609"
|
kingston1tb_uuid: "622a8d81-aa2f-460b-a563-c3cdb6285609"
|
||||||
backup_location: "{{ kingston1tb_mount_point }}/homeserver_backup"
|
backup_location: "{{ kingston1tb_mount_point }}/atlas_backup"
|
||||||
|
|
||||||
admin_public_keys:
|
admin_public_keys:
|
||||||
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINUZp4BCxf7uLa1QWonx/Crf8tYZ5MKIZ+EuaBa82LrV user@user-laptop"
|
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINUZp4BCxf7uLa1QWonx/Crf8tYZ5MKIZ+EuaBa82LrV user@user-laptop"
|
||||||
|
|
10
roles/borg/files/backup.timer
Normal file
10
roles/borg/files/backup.timer
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Backup data daily
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 3:00:00
|
||||||
|
Persistent=true
|
||||||
|
RandomizedDelaySec=1h
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
|
@ -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
|
- name: Create extra disk moint point
|
||||||
file:
|
file:
|
||||||
path: "{{ kingston1tb_mount_point }}"
|
path: "{{ kingston1tb_mount_point }}"
|
||||||
|
|
6
roles/borg/templates/backup.service.j2
Normal file
6
roles/borg/templates/backup.service.j2
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Backup data using borgmatic
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/borgmatic --config /root/backup.yml
|
||||||
|
Type=oneshot
|
14
roles/borg/templates/backup.yml.j2
Normal file
14
roles/borg/templates/backup.yml.j2
Normal 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
|
|
@ -49,7 +49,7 @@
|
||||||
state: directory
|
state: directory
|
||||||
- name: Mount atlas data
|
- name: Mount atlas data
|
||||||
mount:
|
mount:
|
||||||
src: "lewis@atlas.lan:"
|
src: "backup-share@atlas.lan:"
|
||||||
path: "/mnt/atlas"
|
path: "/mnt/atlas"
|
||||||
state: mounted
|
state: mounted
|
||||||
fstype: fuse.sshfs
|
fstype: fuse.sshfs
|
||||||
|
|
Reference in a new issue