Add autobackup support to pvc-ansible
This commit is contained in:
27
roles/pvc/tasks/autobackup/disable.yml
Normal file
27
roles/pvc/tasks/autobackup/disable.yml
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
|
||||
- name: disable timer units
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
enabled: false
|
||||
loop:
|
||||
- pvc-autobackup-normal.timer
|
||||
- pvc-autobackup-full.timer
|
||||
|
||||
- name: remove autobackup configurations
|
||||
file:
|
||||
dest: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /etc/pvc/autobackup.yaml
|
||||
- /etc/systemd/system/pvc-autobackup-normal.timer
|
||||
- /etc/systemd/system/pvc-autobackup-normal.service
|
||||
- /etc/systemd/system/pvc-autobackup-full.timer
|
||||
- /etc/systemd/system/pvc-autobackup-full.service
|
||||
register: systemd
|
||||
ignore_errors: yes
|
||||
|
||||
- name: reload systemd to apply changes
|
||||
command: systemctl daemon-reload
|
||||
when: systemd.changed
|
47
roles/pvc/tasks/autobackup/enable.yml
Normal file
47
roles/pvc/tasks/autobackup/enable.yml
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
|
||||
- name: install required automount packages
|
||||
apt:
|
||||
name: "{{ pvc_autobackup.auto_mount.packages }}"
|
||||
state: present
|
||||
when:
|
||||
- pvc_autobackup.auto_mount.enabled is defined and pvc_autobackup.auto_mount.enabled
|
||||
- pvc_autobackup.auto_mount.packages is defined and pvc_autobackup.auto_mount.packages
|
||||
|
||||
- name: install autobackup YAML configuration
|
||||
template:
|
||||
src: "autobackup/autobackup.yaml.j2"
|
||||
dest: "/etc/pvc/autobackup.yaml"
|
||||
|
||||
- name: install autobackup normal systemd units
|
||||
template:
|
||||
src: "autobackup/pvc-autobackup-normal.{{ item }}.j2"
|
||||
dest: "/etc/systemd/system/pvc-autobackup-normal.{{ item }}"
|
||||
loop:
|
||||
- timer
|
||||
- service
|
||||
register: systemd_normal
|
||||
|
||||
- name: install autobackup forced-full systemd units
|
||||
template:
|
||||
src: "autobackup/pvc-autobackup-full.{{ item }}.j2"
|
||||
dest: "/etc/systemd/system/pvc-autobackup-full.{{ item }}"
|
||||
loop:
|
||||
- timer
|
||||
- service
|
||||
when: pvc_autobackup.schedule.forced_full_time is defined and pvc_autobackup.schedule.forced_full_time
|
||||
register: systemd_full
|
||||
|
||||
- name: reload systemd to apply changes
|
||||
command: systemctl daemon-reload
|
||||
when: systemd_normal.changed or systemd_full.changed
|
||||
|
||||
- name: enable timer units
|
||||
systemd:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
loop:
|
||||
- pvc-autobackup-normal.timer
|
||||
- pvc-autobackup-full.timer
|
||||
|
7
roles/pvc/tasks/autobackup/main.yml
Normal file
7
roles/pvc/tasks/autobackup/main.yml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- include: enable.yml
|
||||
when: pvc_autobackup.enabled
|
||||
|
||||
- include: disable.yml
|
||||
when: not pvc_autobackup.enabled
|
@ -56,6 +56,11 @@
|
||||
- include: pvc/main.yml
|
||||
tags: pvc-daemon
|
||||
|
||||
# Install PVC autobackup
|
||||
- include: autobackup/main.yml
|
||||
tags: pvc-autobackup
|
||||
when: pvc_autobackup is defined
|
||||
|
||||
# Install CPU tuning
|
||||
- include: cputuning/main.yml
|
||||
tags: pvc-cputuning
|
||||
|
24
roles/pvc/templates/autobackup/autobackup.yaml.j2
Normal file
24
roles/pvc/templates/autobackup/autobackup.yaml.j2
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
# PVC Autobackup configuration
|
||||
# {{ ansible_managed }}
|
||||
|
||||
autobackup:
|
||||
backup_root_path: {{ pvc_autobackup.backup_root_path }}
|
||||
backup_root_suffix: {{ pvc_autobackup.backup_root_suffix }}
|
||||
backup_tags:
|
||||
{% for tag in pvc_autobackup.backup_tags %}
|
||||
- {{ tag }}
|
||||
{% endfor %}
|
||||
backup_schedule:
|
||||
full_interval: {{ pvc_autobackup.schedule.full_interval }}
|
||||
full_retention: {{ pvc_autobackup.schedule.full_retention }}
|
||||
auto_mount:
|
||||
enabled: {{ pvc_autobackup.auto_mount.enabled }}
|
||||
mount_cmds:
|
||||
{% for cmd in pvc_autobackup.auto_mount.mount_cmds %}
|
||||
- "{{ cmd }}"
|
||||
{% endfor %}
|
||||
unmount_cmds:
|
||||
{% for cmd in pvc_autobackup.auto_mount.unmount_cmds %}
|
||||
- "{{ cmd }}"
|
||||
{% endfor %}
|
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=[Cron] PVC VM autobackup (forced-full)
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
IgnoreSIGPIPE=false
|
||||
KillMode=process
|
||||
ExecStart=/usr/bin/pvc --quiet vm autobackup --cron --force-full
|
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=[Timer] PVC VM autobackup (forced-full)
|
||||
|
||||
[Timer]
|
||||
Unit=pvc-autobackup-full.service
|
||||
OnCalendar={{ pvc_autobackup.schedule.forced_full_time }}
|
||||
|
||||
[Install]
|
||||
WantedBy=pvc.target
|
@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=[Cron] PVC VM autobackup (normal)
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
IgnoreSIGPIPE=false
|
||||
KillMode=process
|
||||
ExecStart=/usr/bin/pvc --quiet vm autobackup --cron
|
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=[Timer] PVC VM autobackup (normal)
|
||||
|
||||
[Timer]
|
||||
Unit=pvc-autobackup-normal.service
|
||||
OnCalendar={{ pvc_autobackup.schedule.normal_time }}
|
||||
|
||||
[Install]
|
||||
WantedBy=pvc.target
|
Reference in New Issue
Block a user