adding restore all play
parent
848a75b19c
commit
4039392882
@ -0,0 +1,19 @@
|
||||
###
|
||||
# restore-all restores a manually specified list of volumes.
|
||||
# This is intended for user when initially setting up a home lab environment
|
||||
# and want to restore all applications from existing backups
|
||||
#
|
||||
# Restores will be skipped if there is no archive in the backup directory.
|
||||
#
|
||||
# If a container exists, it will be stopped, restored and started
|
||||
# If a container does not exist, the volume will be still be created.
|
||||
###
|
||||
|
||||
---
|
||||
- name: Redeploy Portainer and All Volumes
|
||||
hosts: servers
|
||||
tasks:
|
||||
- name: Restore Tautulli
|
||||
import_tasks: ../tasks/restore-volume-tasks.yml
|
||||
vars:
|
||||
container_name: "tautulli"
|
||||
@ -1,31 +1,9 @@
|
||||
### Example:
|
||||
# ansible-playbook -v ansible/volume-restore.yml -e "container_name=mariadb"
|
||||
# ansible-playbook -v ansible/playbooks/volume-restore.yml -e "container_name=mariadb"
|
||||
---
|
||||
- hosts: servers
|
||||
tasks:
|
||||
- name: Find volumes
|
||||
ansible.builtin.shell: docker run --rm
|
||||
-v /var/run/docker.sock:/var/run/docker.sock
|
||||
-v /mnt/hdds/backups/:/mnt/hdds/backups/
|
||||
ghcr.io/chatton/docker-volume-backup:master
|
||||
list-backups
|
||||
--host-path /mnt/hdds/backups/
|
||||
--volume-name-filter {{container_name}}
|
||||
--newest-only
|
||||
register: out
|
||||
- name: Stop the container
|
||||
docker_container:
|
||||
name: "{{container_name}}"
|
||||
state: stopped
|
||||
- name: Restore Volume
|
||||
ansible.builtin.command: docker run --rm
|
||||
-v /var/run/docker.sock:/var/run/docker.sock
|
||||
ghcr.io/chatton/docker-volume-backup:master
|
||||
restore-volume
|
||||
--volume {{item.volumeName}}
|
||||
--archive {{item.absoluteFilePath}}
|
||||
with_items: "{{ out.stdout }}"
|
||||
- name: Start the container
|
||||
docker_container:
|
||||
name: "{{container_name}}"
|
||||
state: started
|
||||
import_tasks: ../tasks/restore-volume-tasks.yml
|
||||
vars:
|
||||
container_name: "{{ container_name }}"
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
---
|
||||
# https://stackoverflow.com/questions/45237632/ansible-w-docker-show-current-container-state
|
||||
- name: Get container info
|
||||
docker_container_info:
|
||||
name: "{{container_name}}"
|
||||
register: result
|
||||
# We find the volumes
|
||||
- name: Find volumes
|
||||
ansible.builtin.shell: docker run --rm
|
||||
-v /var/run/docker.sock:/var/run/docker.sock
|
||||
-v /mnt/hdds/backups/:/mnt/hdds/backups/
|
||||
ghcr.io/chatton/docker-volume-backup:master
|
||||
list-backups
|
||||
--host-path /mnt/hdds/backups/
|
||||
--volume-name-filter {{container_name}}
|
||||
--newest-only
|
||||
register: out
|
||||
|
||||
- name: Stop the container
|
||||
# not out.stdout is search("null") occurs when there is no volume in the backups dir
|
||||
when: result.exists and not out.stdout is search("null")
|
||||
docker_container:
|
||||
name: "{{container_name}}"
|
||||
state: stopped
|
||||
- name: Restore Volume
|
||||
ansible.builtin.command: docker run --rm
|
||||
-v /var/run/docker.sock:/var/run/docker.sock
|
||||
ghcr.io/chatton/docker-volume-backup:master
|
||||
restore-volume
|
||||
--volume {{item.volumeName}}
|
||||
--archive {{item.absoluteFilePath}}
|
||||
with_items: "{{ out.stdout }}"
|
||||
# the output will be "null" if there are no backups. We simply skip if this is the case
|
||||
when: not out.stdout is search("null")
|
||||
- name: Start the container
|
||||
# not out.stdout is search("null") occurs when there is no volume in the backups dir
|
||||
when: result.exists and not out.stdout is search("null")
|
||||
docker_container:
|
||||
name: "{{container_name}}"
|
||||
state: started
|
||||
Loading…
Reference in New Issue