108 lines
3.2 KiB
YAML
108 lines
3.2 KiB
YAML
|
---
|
||
|
- name: testing backup plan
|
||
|
hosts: newsbot
|
||
|
become: true
|
||
|
vars:
|
||
|
backup: false
|
||
|
tasks:
|
||
|
- block:
|
||
|
- set_fact:
|
||
|
pathLocal: /docker/cfg/newsbot/database
|
||
|
container: newsbot_app_1
|
||
|
|
||
|
- name: "{{ container }} - Ensure backup dir is present"
|
||
|
file:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}"
|
||
|
state: directory
|
||
|
|
||
|
- name: "{{ container}} - Check on old backups"
|
||
|
find:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}"
|
||
|
age: 4w
|
||
|
register: searchRes
|
||
|
|
||
|
- name: "{{ container }} - Remove old backups"
|
||
|
file:
|
||
|
path: "{{ item.path }}"
|
||
|
state: absent
|
||
|
loop: "{{ searchRes.files }}"
|
||
|
|
||
|
- name: "{{ container }} - Stop container"
|
||
|
docker_container:
|
||
|
name: "{{ container }}"
|
||
|
state: stopped
|
||
|
|
||
|
- name: "{{ container }} - Generate backup"
|
||
|
community.general.archive:
|
||
|
path: "{{ pathLocal }}"
|
||
|
dest: "{{ pathNfsBackup }}/{{ container }}/temp.tgz"
|
||
|
|
||
|
- name: "{{ container }} - Copy backup"
|
||
|
copy:
|
||
|
src: "{{ pathNfsBackup}}/{{ container }}/temp.tgz"
|
||
|
dest: "{{ pathNfsBackup}}/{{ container }}/backup.tgz"
|
||
|
backup: true
|
||
|
remote_src: true
|
||
|
|
||
|
- name: "{{ container }} - Remove temp file"
|
||
|
#shell: "rm {{ PathNfsBackup }}/{{ container }}/temp.tgz"
|
||
|
file:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}/temp.tgz"
|
||
|
state: absent
|
||
|
|
||
|
|
||
|
- name: "{{ container }} - Start container"
|
||
|
docker_container:
|
||
|
name: "{{ container }}"
|
||
|
state: started
|
||
|
|
||
|
- block:
|
||
|
- set_fact:
|
||
|
pathLocal: /docker/cfg/newsbot_sin/database
|
||
|
container: newsbot_sin_1
|
||
|
|
||
|
- name: "{{ container }} - Ensure backup dir is present"
|
||
|
file:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}"
|
||
|
state: directory
|
||
|
|
||
|
- name: "{{ container}} - Check on old backups"
|
||
|
find:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}"
|
||
|
age: 4w
|
||
|
register: searchRes
|
||
|
|
||
|
- name: "{{ container }} - Remove old backups"
|
||
|
file:
|
||
|
path: "{{ item.path }}"
|
||
|
state: absent
|
||
|
loop: "{{ searchRes.files }}"
|
||
|
|
||
|
- name: "{{ container }} - Stop container"
|
||
|
docker_container:
|
||
|
name: "{{ container }}"
|
||
|
state: stopped
|
||
|
|
||
|
- name: "{{ container }} - Generate backup"
|
||
|
community.general.archive:
|
||
|
path: "{{ pathLocal }}"
|
||
|
dest: "{{ pathNfsBackup }}/{{ container }}/temp.tgz"
|
||
|
|
||
|
- name: "{{ container }} - Copy backup"
|
||
|
copy:
|
||
|
src: "{{ pathNfsBackup}}/{{ container }}/temp.tgz"
|
||
|
dest: "{{ pathNfsBackup}}/{{ container }}/backup.tgz"
|
||
|
backup: true
|
||
|
remote_src: true
|
||
|
|
||
|
- name: "{{ container }} - Remove temp file"
|
||
|
file:
|
||
|
path: "{{ pathNfsBackup }}/{{ container }}/temp.tgz"
|
||
|
state: absent
|
||
|
|
||
|
- name: "{{ container }} - Start container"
|
||
|
docker_container:
|
||
|
name: "{{ container }}"
|
||
|
state: started
|
||
|
|