add backup service
This commit is contained in:
parent
4946f503a2
commit
72240e1382
6 changed files with 57 additions and 2 deletions
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
|
||||
file:
|
||||
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
|
Reference in a new issue