#!/bin/bash
# {{ ansible_managed }}

{% if backups is defined and 'containers' in backups %}
{% if containers is defined %}
{% for container in containers %}
{% if container.volumes is defined %}
{% for volume in container.volumes %}
{% if volume|regex_replace(':.*') not in backups_ignore %}

BACKUP_DIR='/opt/restores{{ volume | regex_replace(':.*') }}'

echo "Starting restore of '{{ container.name }}:{{ volume | regex_replace(':.*') }} to $BACKUP_DIR'..."
/usr/bin/rclone copy b2-container-data:current/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} "$BACKUP_DIR" \
	--fast-list \
	--progress
echo
echo

{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}