{##ensure that backup pillar exists##}
{%- if pillar['backup'] is defined -%}

  {##restore directories from backup##}
  {%- for name in pillar['backup'] %}
    {%- if pillar['backup'][name]['location'] is defined %}
  #handle restoring radarr backup folder
{{ pillar['backup'][name]['location'] }}:
  file.recurse:
    - source: salt://backups/{{ name }}/latest
      {%- if pillar['backup'][name]['user'] is defined %}
    - user: {{ pillar['backup'][name]['user'] }}
      {%- endif -%}
      {%- if pillar['backup'][name]['group'] is defined %}
    - group: {{ pillar['backup'][name]['group'] }}
      {%- endif -%}
      {%- if pillar['backup'][name]['fmode'] is defined %}
    - file_mode: {{ pillar['backup'][name]['fmode'] }}
      {%- endif -%}
      {%- if pillar['backup'][name]['dmode'] is defined %}
    - dir_mode: {{ pillar['backup'][name]['dmode'] }}
      {%- endif %}
    - clean: true
    - include_empty: true
    - keep_symlinks: true
    - force_symlinks: true

      {%- if pillar['backup'][name]['services'] is defined %}
        {%- for service in pillar['backup'][name]['services'] %}
{{ service }}:
  service.running:
    - watch:
      - file: {{ pillar['backup'][name]['location'] }}
        {%- endfor %}
      {%- endif -%}
    {%- endif -%}
  {%- endfor %}
{%- endif %}