diff --git a/group_vars/all.yml b/group_vars/all.yml index 67b8603..6ce836b 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -4,6 +4,7 @@ server: domain: mrdev023.fr ssh_port: 7943 work_dir: /mnt/work + backup_dir: /mnt/backup acme: email: florian.richer.97@outlook.com debug: true diff --git a/group_vars/all.yml.sample b/group_vars/all.yml.sample index 5220c1b..19eea40 100644 --- a/group_vars/all.yml.sample +++ b/group_vars/all.yml.sample @@ -4,6 +4,7 @@ server: domain: mrdev023.test ssh_port: 22 work_dir: /mnt/test + backup_dir: /mnt/btest acme: email: test@test.fr debug: true diff --git a/playbook.yml b/playbook.yml index 4777e50..f03adad 100644 --- a/playbook.yml +++ b/playbook.yml @@ -13,4 +13,5 @@ - { role: n8n, tags: ["n8n"] } - { role: matrix, tags: ["matrix"] } - { role: iptables, tags: ["iptables"] } + - { role: borg, tags: ["borg"] } - { role: clean, tags: ["clean"] } diff --git a/roles/borg/tasks/base.yml b/roles/borg/tasks/base.yml new file mode 100644 index 0000000..8e8fb49 --- /dev/null +++ b/roles/borg/tasks/base.yml @@ -0,0 +1,13 @@ +--- + +- name: Copy template conf + ansible.builtin.template: + backup: true + src: "{{ item.src }}" + dest: "/usr/bin/{{ item.dest }}" + group: root + owner: root + mode: u=rwx,g=rx,o=rx + loop: + - { src: 'backup.j2', dest: 'backup' } + become: true \ No newline at end of file diff --git a/roles/borg/tasks/cron.yml b/roles/borg/tasks/cron.yml new file mode 100644 index 0000000..1294ff5 --- /dev/null +++ b/roles/borg/tasks/cron.yml @@ -0,0 +1,8 @@ +--- + +- name: Ensure a job that run to backup data + ansible.builtin.cron: + name: "borg backup" + special_time: "daily" + job: "/usr/bin/backup" + become: yes \ No newline at end of file diff --git a/roles/borg/tasks/main.yml b/roles/borg/tasks/main.yml new file mode 100644 index 0000000..148965f --- /dev/null +++ b/roles/borg/tasks/main.yml @@ -0,0 +1,7 @@ +--- + +- ansible.builtin.import_tasks: base.yml + name: base + +- ansible.builtin.import_tasks: cron.yml + name: cron diff --git a/roles/borg/templates/backup.j2 b/roles/borg/templates/backup.j2 new file mode 100644 index 0000000..668f9c9 --- /dev/null +++ b/roles/borg/templates/backup.j2 @@ -0,0 +1,2 @@ +#!/bin/sh +cd {{ server.work_dir }} && borg create --stats -C zstd,22 --progress "{{ server.backup_dir }}::$(date --iso-8601=seconds)" . \ No newline at end of file