infra/roles/deadspace/templates/deadspace_pull.sh.j2

73 lines
1.7 KiB
Django/Jinja

#!/bin/bash
# {{ template_path }}
# NOTE: chattr, -f is set:
# -f Suppress most error messages
set -e
LOCKFILE={{ deadspace_pull_lockfile }}
lockfile -r 0 $LOCKFILE
function cleanup {
rm -f $LOCKFILE
}
trap cleanup EXIT
{% set user = deadspace_user %}
IGNORE="{% for excl in deadspace_ignore %}--exclude {{ excl }} {% endfor %}"
# -S, --sparse: slows it down
PARAMS="-rah --numeric-ids --delete-after --safe-links "
if [[ "$1" == "-v" ]]; then
PARAMS="$PARAMS --info=progress2"
fi
{% for origin in deadspace %}
{% for item in deadspace[origin] %}
{% if origin != inventory_hostname and inventory_hostname in item.replicas %}
{% set hostname = item.hostname | default(origin) %}
if [[ "$1" == "-v" ]]; then echo "{{ hostname }}:{{ item.path }}"; fi
{% if 'rsnapshot/' in item.path %}
EXCLUDE="$IGNORE --exclude {{ inventory_hostname }}/"
{% else %}
EXCLUDE="$IGNORE "
{% endif %}
mkdir -p {{ item.path }}
stat {{ item.path }} > /dev/null
{% if not item.skip_chattr|default(false) %}
chattr -fR -i {{ item.path }} || true
{% endif %}
rsync -e "ssh -i {{ deadspace_sshkey }}" $PARAMS $EXCLUDE {{ user }}@{{ hostname }}:{{ item.path }}/ {{ item.path }}/ || true
echo "origin: {{ hostname }}
path: {{ item.path }}
state: replica
comment: {{ item.comment|default("") }}
updated: $(date -Is)" > {{ item.path }}/.deadspace-info
chmod 644 {{ item.path }}/.deadspace-info
{% if 'rsnapshot/' in item.path %}
echo "did not rsync my own backup from origin" > {{ item.path }}/{{ inventory_hostname }}.txt
{% endif -%}
{% if not item.skip_chattr|default(false) %}
chattr -fR +i {{ item.path }} || true
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
rm -f $LOCKFILE