backup restore working correctly

pull/20/head
Cian Hatton 3 years ago
parent 099c29e7d4
commit 41762fb07e

@ -6,6 +6,8 @@
include_vars: '../{{vault_file}}' include_vars: '../{{vault_file}}'
tags: [always] tags: [always]
roles: roles:
- role: docker_restore - role: docker_s3_volume_restore
vars:
container_restore: linkding # - role: docker_restore_container
# vars:
# container_restore: linkding

@ -0,0 +1,2 @@
---
# defaults file for docker_archive_volume_restore

@ -0,0 +1,2 @@
---
# handlers file for docker_archive_volume_restore

@ -0,0 +1,2 @@
---
# tasks file for docker_archive_volume_restore

@ -0,0 +1,2 @@
---
# vars file for docker_archive_volume_restore

@ -19,18 +19,19 @@
- name: Extract only the volume mounts (not bind mounts) - name: Extract only the volume mounts (not bind mounts)
set_fact: volume_mounts="{{ result.container.Mounts | selectattr("Type", "equalto", "volume")}}" set_fact: volume_mounts="{{ result.container.Mounts | selectattr("Type", "equalto", "volume")}}"
- debug: msg="{{volume_mounts}}"
- name: Create Backup of Container Volumes - name: Create Backup of Container Volumes
community.docker.docker_container: community.docker.docker_container:
name: "backup-container-{{ item.Name }}-{{ 10 | random }}" name: "backup-container-{{ item.Name }}-{{ 10 | random }}"
image: ubuntu image: ubuntu
command: "tar cvf /backups/{{ item.Name }}-{{ backup_time }}.tar.gz {{ item.Destination }}" command: "tar -czvf /backups/{{ item.Name }}-{{ backup_time }}.tar.gz /data"
auto_remove: true auto_remove: true
detach: false # block until this container exists. detach: false # block until this container exists.
state: started state: started
volumes: volumes:
- "{{ item.Name }}:/data"
- /mnt/mergerfs/backups:/backups - /mnt/mergerfs/backups:/backups
volumes_from:
- "{{ container_backup }}"
with_items: "{{ volume_mounts }}" with_items: "{{ volume_mounts }}"
- name: Start the container - name: Start the container

@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

@ -0,0 +1,5 @@
---
# defaults file for docker_s3_volume_restore
docker_volume_s3_restores:
- volume_name: "linkding_data"
s3_key: "linkding_data/linkding_data-2022-09-01T21:32:54Z.tar.gz"

@ -0,0 +1,2 @@
---
# handlers file for docker_s3_volume_restore

@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

@ -0,0 +1,54 @@
---
# https://docs.ansible.com/ansible/latest/collections/community/docker/docker_container_module.html#ansible-collections-community-docker-docker-container-module
# https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes
#
- name: Download archive from S3
amazon.aws.aws_s3:
bucket: "{{ aws_s3.bucket }}"
object: "{{ item.s3_key }}"
aws_access_key: "{{ aws_s3.aws_access_key }}"
aws_secret_key: "{{ aws_s3.aws_secret_key }}"
region: "{{ aws_s3.region }}"
s3_url: "https://{{ aws_s3.s3_url }}"
mode: get
dest: "/tmp/{{ item.s3_key }}"
register: get_out
with_items: "{{ docker_volume_s3_restores }}"
- debug: msg="{{ get_out }}"
- name: Ensure Volume
docker_volume:
name: "{{ item.volume_name }}"
state: present
with_items: "{{ docker_volume_s3_restores }}"
# TODO: skip if the volume was just created
- name: Remove contents of volumes
community.docker.docker_container:
name: "restore-container-{{ item.volume_name }}-{{ 10 | random }}"
image: ubuntu
command: "rm -rf ./*"
auto_remove: true
detach: false # block until this container exists.
state: started
# start inside the directory we want to wipe
working_dir: "/data"
volumes:
- "{{ item.volume_name }}:/data"
with_items: "{{ docker_volume_s3_restores }}"
- name: Restore contents of volumes
community.docker.docker_container:
name: "restore-container-{{ item.volume_name }}-{{ 10 | random }}"
image: ubuntu
# extract the tar into the volume.
command: "tar xvf /tmp/{{ item.s3_key }} -C /data --strip-components 1"
auto_remove: true
detach: false # block until this container exists.
state: started
volumes:
- "{{ item.volume_name }}:/data"
- /tmp:/tmp
with_items: "{{ docker_volume_s3_restores }}"

@ -0,0 +1,2 @@
---
# vars file for docker_s3_volume_restore

@ -63,8 +63,7 @@
register: find_volumes register: find_volumes
changed_when: false changed_when: false
- debug: msg="{{find_volumes.results | map(attribute='stdout_lines') | list | flatten - debug: msg="{{ find_volumes.results | map(attribute='stdout_lines') | list | flatten }}"
}}"
- name: Docker | Find volumes that need to be restored - name: Docker | Find volumes that need to be restored
script: scripts/find-volumes-to-restore.py script: scripts/find-volumes-to-restore.py
@ -110,8 +109,7 @@
chatton.portainer.portainer_stack: chatton.portainer.portainer_stack:
username: admin username: admin
password: '{{portainer.password}}' password: '{{portainer.password}}'
docker_compose_file_path: '{{directories.docker_compose_directory}}/{{ item.name docker_compose_file_path: '{{ directories.docker_compose_directory }}/{{ item.name }}/docker-compose.yml'
}}/docker-compose.yml'
stack_name: '{{ item.name }}' stack_name: '{{ item.name }}'
endpoint_id: '{{ item.endpoint_id }}' endpoint_id: '{{ item.endpoint_id }}'
state: present state: present

Loading…
Cancel
Save