Add backup playbook

This commit is contained in:
Paul Brinkmeier 2022-09-06 04:39:12 +02:00
parent 5dfa5d91e4
commit 4f1d2741c0
2 changed files with 51 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.env
backups

50
ansible/misc-backup.yaml Normal file
View File

@ -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