add export service
This commit is contained in:
parent
d01de238a7
commit
dbb78ed37f
7 changed files with 86 additions and 4 deletions
35
README.md
35
README.md
|
|
@ -5,6 +5,29 @@
|
||||||
All configuration is to be placed inside the `backups` dict.
|
All configuration is to be placed inside the `backups` dict.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# Settings for all backup related timers.
|
||||||
|
jobs:
|
||||||
|
retention:
|
||||||
|
# Can be used to enable/disable the job
|
||||||
|
enabled: true
|
||||||
|
# Time this job runs on, random by default
|
||||||
|
OnCalendar: "hh:mm"
|
||||||
|
run:
|
||||||
|
# Can be used to enable/disable the job
|
||||||
|
enabled: true
|
||||||
|
# Time this job runs on, random by default
|
||||||
|
OnCalendar: "hh:mm"
|
||||||
|
check:
|
||||||
|
# Can be used to enable/disable the job
|
||||||
|
enabled: true
|
||||||
|
# Time this job runs on, random by default
|
||||||
|
OnCalendar: "hh:mm"
|
||||||
|
export:
|
||||||
|
# Can be used to enable/disable the job
|
||||||
|
enabled: false
|
||||||
|
# Time this job runs on, random by default
|
||||||
|
OnCalendar: "hh:mm"
|
||||||
|
|
||||||
# backend specific settings
|
# backend specific settings
|
||||||
backends:
|
backends:
|
||||||
# restic specific settings
|
# restic specific settings
|
||||||
|
|
@ -33,6 +56,18 @@ retention:
|
||||||
months: 12
|
months: 12
|
||||||
years: 3
|
years: 3
|
||||||
|
|
||||||
|
# Settings for the export task
|
||||||
|
export:
|
||||||
|
# list of all remote destinations the backup should be exported to
|
||||||
|
destinations: []
|
||||||
|
# every element of this list describes an export target
|
||||||
|
# - user: root
|
||||||
|
# host: localhost
|
||||||
|
# remotepath: /
|
||||||
|
# type: rsync
|
||||||
|
# port: 22
|
||||||
|
# key: "/etc/backup-client/id_ed25519"
|
||||||
|
|
||||||
# keys are strings with glob patterns of files to be excluded. Value musst be true to enable the exclude, false to disable it
|
# keys are strings with glob patterns of files to be excluded. Value musst be true to enable the exclude, false to disable it
|
||||||
# Only supportet in restic based backups
|
# Only supportet in restic based backups
|
||||||
exclude_files: {}
|
exclude_files: {}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ backups:
|
||||||
check:
|
check:
|
||||||
enabled: true
|
enabled: true
|
||||||
OnCalendar: "monday 5:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}"
|
OnCalendar: "monday 5:{{ 60|random(seed=(inventory_hostname + 'backups_jobs')) }}"
|
||||||
|
export:
|
||||||
|
enabled: false
|
||||||
|
OnCalendar: "{{ [21,22,23]|random(seed=(inventory_hostname + 'backups_export_h')) }}:{{ 60|random(seed=(inventory_hostname + 'backups_export_m')) }}"
|
||||||
backends:
|
backends:
|
||||||
restic:
|
restic:
|
||||||
url: /var/backup-client/restic
|
url: /var/backup-client/restic
|
||||||
|
|
@ -21,6 +24,8 @@ backups:
|
||||||
weeks: 16
|
weeks: 16
|
||||||
months: 12
|
months: 12
|
||||||
years: 3
|
years: 3
|
||||||
|
export:
|
||||||
|
destinations: []
|
||||||
exclude_files:
|
exclude_files:
|
||||||
'/tmp': true
|
'/tmp': true
|
||||||
'/var/tmp': true
|
'/var/tmp': true
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
- check
|
- check
|
||||||
- retention
|
- retention
|
||||||
- run
|
- run
|
||||||
|
- export
|
||||||
systemd:
|
systemd:
|
||||||
name: "backup-{{ item }}.timer"
|
name: "backup-{{ item }}.timer"
|
||||||
enabled: "{{ backups.jobs[item].enabled }}"
|
enabled: "{{ backups.jobs[item].enabled }}"
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
backup_backend: "{% if backups.mode in ['standalone-restic', 'hypervisor-restic'] %}restic{% else %}False{% endif %}"
|
backup_backend: "{% if backups.mode in ['standalone-restic', 'hypervisor-restic'] %}restic{% else %}False{% endif %}"
|
||||||
backup_executor: "{% if backups.mode in ['vm-via-hypervisor'] %}False{% else %}True{% endif %}"
|
backup_executor: "{% if backups.mode in ['vm-via-hypervisor'] %}False{% else %}True{% endif %}"
|
||||||
|
|
||||||
- debug:
|
|
||||||
var: backup_backend
|
|
||||||
|
|
||||||
- name: create config folder
|
- name: create config folder
|
||||||
file:
|
file:
|
||||||
path: /etc/backup-client/
|
path: /etc/backup-client/
|
||||||
|
|
@ -17,6 +14,10 @@
|
||||||
- name: setup hosts that actualy run backup code (not vms for example)
|
- name: setup hosts that actualy run backup code (not vms for example)
|
||||||
when: backup_executor
|
when: backup_executor
|
||||||
block:
|
block:
|
||||||
|
- name: generate ssh key
|
||||||
|
community.crypto.openssh_keypair:
|
||||||
|
path: /etc/backup-client/id_ed25519
|
||||||
|
type: ed25519
|
||||||
- name: create retention file
|
- name: create retention file
|
||||||
copy:
|
copy:
|
||||||
dest: /etc/backup-client/retention.env
|
dest: /etc/backup-client/retention.env
|
||||||
|
|
@ -48,6 +49,7 @@
|
||||||
- backup-full
|
- backup-full
|
||||||
- backup-cronjob
|
- backup-cronjob
|
||||||
- backup-check
|
- backup-check
|
||||||
|
- backup-export
|
||||||
- status-email-root
|
- status-email-root
|
||||||
template:
|
template:
|
||||||
src: "{{ item }}.j2"
|
src: "{{ item }}.j2"
|
||||||
|
|
@ -63,6 +65,7 @@
|
||||||
- backup-check
|
- backup-check
|
||||||
- backup-retention
|
- backup-retention
|
||||||
- backup-run
|
- backup-run
|
||||||
|
- backup-export
|
||||||
- status-email-root@
|
- status-email-root@
|
||||||
template:
|
template:
|
||||||
src: "{{ item }}.service.j2"
|
src: "{{ item }}.service.j2"
|
||||||
|
|
@ -79,6 +82,7 @@
|
||||||
- check
|
- check
|
||||||
- retention
|
- retention
|
||||||
- run
|
- run
|
||||||
|
- export
|
||||||
template:
|
template:
|
||||||
src: "timer.j2"
|
src: "timer.j2"
|
||||||
dest: "/etc/systemd/system/backup-{{ item }}.timer"
|
dest: "/etc/systemd/system/backup-{{ item }}.timer"
|
||||||
|
|
@ -116,9 +120,15 @@
|
||||||
mode: 0600
|
mode: 0600
|
||||||
content: "{{ backups.include_files|filterEnabled|join('\n') }}"
|
content: "{{ backups.include_files|filterEnabled|join('\n') }}"
|
||||||
- name: create repo key for restic
|
- name: create repo key for restic
|
||||||
command: "dd if=/dev/urandom of=/etc/backup-client/restic.key bs=1k count=16"
|
shell: "umask 177; dd if=/dev/urandom of=/etc/backup-client/restic.key bs=1k count=16"
|
||||||
args:
|
args:
|
||||||
creates: "/etc/backup-client/restic.key"
|
creates: "/etc/backup-client/restic.key"
|
||||||
|
- name: set repo key permissions
|
||||||
|
file:
|
||||||
|
path: /etc/backup-client/restic.key
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0600
|
||||||
- name: create restic env file
|
- name: create restic env file
|
||||||
copy:
|
copy:
|
||||||
dest: /etc/backup-client/restic.env
|
dest: /etc/backup-client/restic.env
|
||||||
|
|
|
||||||
0
templates/backup-export.
Normal file
0
templates/backup-export.
Normal file
21
templates/backup-export.j2
Executable file
21
templates/backup-export.j2
Executable file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "Starting to export backups..."
|
||||||
|
|
||||||
|
{% if backup_backend == 'restic' %}
|
||||||
|
# restic backend
|
||||||
|
source /etc/backup-client/restic.env
|
||||||
|
|
||||||
|
{% for i in backups.export.destinations if i.type == "rsync" %}
|
||||||
|
echo "exporting to {{ i.host }}"
|
||||||
|
rsync -h -r -a --append-verify --delete --stats -e "ssh -p {{ i.port|d(22) }} -i {{ i.key|d('/etc/backup-client/id_ed25519') }}" "${RESTIC_REPOSITORY}/" "{{ i.user }}@{{ i.host }}:{{ i.remotepath }}"
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not backup_backend %}
|
||||||
|
echo "Noop, backup is handled external"
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
echo "done!"
|
||||||
10
templates/backup-export.service.j2
Normal file
10
templates/backup-export.service.j2
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Export backups to an external host
|
||||||
|
OnFailure=status-email-root@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Nice=19
|
||||||
|
IOSchedulingClass=idle
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/bin/backup-export
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue