From 4f1d2741c01fd1180647c481bbe40465615078e8 Mon Sep 17 00:00:00 2001 From: Paul Brinkmeier Date: Tue, 6 Sep 2022 04:39:12 +0200 Subject: [PATCH] Add backup playbook --- .gitignore | 1 + ansible/misc-backup.yaml | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 ansible/misc-backup.yaml diff --git a/.gitignore b/.gitignore index 03bd412..6778a9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.env +backups diff --git a/ansible/misc-backup.yaml b/ansible/misc-backup.yaml new file mode 100644 index 0000000..994c502 --- /dev/null +++ b/ansible/misc-backup.yaml @@ -0,0 +1,50 @@ +--- +- hosts: misc + vars: + start_time: "{{ ansible_date_time.iso8601_basic_short }}" + tasks: + - name: Stop docker stuff + become: yes + docker_compose: + project_src: /etc/pbri/docker/web + state: present + stopped: yes + - name: Create backups in /etc/pbri/backups + become: yes + docker_container: + container_default_behavior: no_defaults + name: bacman + image: busybox + volumes: + - "{{ item }}:/data" + - "/etc/pbri/backups/{{ start_time }}:/backup" + command: "cp -r /data /backup/{{ item }}" + detach: no + cleanup: yes + loop: + - codi_database + - codi_uploads + - gitlab_data + - gitlab_logs + - gitlab_config + - name: Make tar + become: yes + shell: + cmd: "tar -czvf ../{{ start_time }}.tar.gz *" + chdir: "/etc/pbri/backups/{{ start_time }}" + - name: Download tar + become: yes + fetch: + src: /etc/pbri/backups/{{ start_time }}.tar.gz + dest: ../backups + - name: Remove backups folder + become: yes + file: + path: /etc/pbri/backups + state: absent + - name: Restart docker stuff + become: yes + docker_compose: + project_src: /etc/pbri/docker/web + state: present + restarted: yes