Partially complete new docker_borg_backup role

This commit is contained in:
Bradley committed 2026-11-28 22:30:01 -05:00
1 parent e535d8a2f6
commit de0bcc8df4
6 files changed
+49 -12

No files matched your search

+1 -1
View File
@@ -57,7 +57,7 @@
cmd: >
export BORG_PASSPHRASE={{ borg_password }};
borg create --stats --progress --compression lz4
ssh://borg@10.42.0.3:2222/var/backups/borg/openwrt::{now:%Y-%m-%d-%H-%M-%s}
ssh://borg@10.42.0.3:2222/var/backups/borg/openwrt::{now:%Y-%m-%d-%H-%M-%S}
{{ unarchive_where }}/
register: borg_backup
delegate_to: localhost
@@ -1,2 +1,7 @@
---
# defaults file for docker_borg_backup
containers_to_stop_start: "{{ [] }}"
borg_repo_name: ""
borg_password: ""
borg_async_time: 7200
borg_poll_time: 30
directories_to_backup: "{{ [] }}"
@@ -1,2 +0,0 @@
---
# handlers file for docker_borg_backup
@@ -1,2 +1,43 @@
---
# tasks file for docker_borg_backup
- name: Fail if no containers are specified
ansible.builtin.fail:
msg: "You have to specify at least one container"
when: containers_to_stop_start | default([]) | length == 0
- name: Fail if borg repo name is not specified
ansible.builtin.fail:
msg: "You have to specify a borg repo name"
when: borg_repo_name | default("") | length == 0
- name: Fail if borg_password is not specified
ansible.builtin.fail:
msg: "You have to specify a borg password"
when: borg_password | default("") | length == 0
- name: Fail if no directories have been specified for backup
ansible.builtin.fail:
msg: "You must specify at least one directory to backup"
when: directories_to_backup | default([]) | length == 0
- name: Stop containers
community.docker.docker_container:
name: "{{ item }}"
state: stopped
loop: "{{ containers_to_stop_start }}"
- name: Attempt to trigger a borg backup
ansible.builtin.shell:
cmd: >
export BORG_PASSPHRASE={{ borg_password }};
borg create --stats --progress --compression lz4
ssh://borg@10.42.0.3:2222/var/backups/borg/{{ borg_repo_name }}::{now:%Y-%m-%d-%H-%M-%S}
{{ directories_to_backup | join(" ") }}
register: borg_backup
async: "{{ borg_async_time }}"
poll: "{{ borg_poll_time }}"
- name: Start containers
community.docker.docker_container:
name: "{{ item }}"
state: started
loop: "{{ containers_to_stop_start | reverse | list }}"
@@ -1,2 +0,0 @@
localhost
@@ -1,5 +0,0 @@
---
- hosts: localhost
remote_user: root
roles:
- docker_borg_backup