Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

160 lines
3.8 KiB

#!/bin/bash
REPO="backup@{{ borgrepo_backup_host }}.dmz.{{ domain }}:{{ item.key }}"
export BORG_RSH="ssh -i /root/.ssh/id_ed25519_BORG"
export BORG_PASSPHRASE=""
export BORG_RELOCATED_REPO_ACCESS_IS_OK="no"
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK="no"
borg --version
{% for folder in item.value.folders|d({})|dict2items %}
##### Folder {{ folder.key }}
BEGIN_EPOCH=$(date +%s)
DATE="folder-{{ folder.key }}-$(date --iso-8601)-$(hostname)"
echo "Starting backup for $DATE"
borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--exclude-caches \
{% for exclude in folder.value.excludes|d([]) %}
--exclude '{{ exclude }}' \
{% endfor %}
\
${REPO}::'folder-{{ folder.key }}-{hostname}-{now:%Y-%m-%d@%H:%M}' \
{{ folder.value.path }}
backup_rc=$?
prune_rc=99
if [ "${backup_rc}" = "2" ]; then
echo "Failed backup for $DATE"
else
echo "Completed backup for $DATE"
echo "Pruning archives for $DATE"
borg prune \
--list \
--prefix 'folder-{{ folder.key }}-{hostname}-' \
--show-rc \
--keep-daily {{ folder.value.daily|d(7) }} \
--keep-weekly {{ folder.value.weekly|d(4) }} \
--keep-monthly {{ folder.value.monthly|d(6) }} \
${REPO}
prune_rc=$?
if [ "${prune_rc}" = "2" ]; then
echo "Failed pruning for $DATE"
else
echo "Completed pruning for $DATE"
fi
fi
echo "$(date +%s)|${BEGIN_EPOCH}|${backup_rc}|${prune_rc}" > /var/log/backup-status/{{ item.key }}/folder-{{ folder.key }}
{% endfor %}
#####
{% for db in item.value.pgsql_dbs|d({})|dict2items %}
##### pgSQL DB {{ db.key }}
DATE="pgsqldb-{{ db.key }}-$(date --iso-8601)-$(hostname)"
echo "Starting backup for $DATE"
su postgres -c 'pg_dump -d {{ db.value.dbname }}' | borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--stdin-name "{{ db.value.dbname }}.sql" \
\
${REPO}::'pgsqldb-{{ db.key }}-{hostname}-{now:%Y-%m-%d@%H:%M}' \
-
backup_rc=$?
prune_rc=99
if [ "${backup_rc}" = "2" ]; then
echo "Failed backup for $DATE"
else
echo "Completed backup for $DATE"
echo "Pruning archives for $DATE"
borg prune \
--list \
--prefix 'pgsqldb-{{ db.key }}-{hostname}-' \
--show-rc \
--keep-daily {{ db.value.daily|d(7) }} \
--keep-weekly {{ db.value.weekly|d(4) }} \
--keep-monthly {{ db.value.monthly|d(6) }} \
${REPO}
prune_rc=$?
if [ "${prune_rc}" = "2" ]; then
echo "Failed pruning for $DATE"
else
echo "Completed pruning for $DATE"
fi
fi
echo "$(date +%s)|${BEGIN_EPOCH}|${backup_rc}|${prune_rc}" > /var/log/backup-status/{{ item.key }}/pgsqldb-{{ db.key }}
{% endfor %}
{% for db in item.value.ldap_dbs|d({})|dict2items %}
##### LDAP DB {{ db.key }}
DATE="ldapdb-{{ db.key }}-$(date --iso-8601)-$(hostname)"
echo "Starting backup for $DATE"
slapcat -n {{ db.value.dbnum }} | borg create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression lz4 \
--stdin-name "slapcat.db{{ db.value.dbnum }}.ldif" \
\
${REPO}::'ldapdb-{{ db.key }}-{hostname}-{now:%Y-%m-%d@%H:%M}' \
-
backup_rc=$?
prune_rc=99
if [ "${backup_rc}" = "2" ]; then
echo "Failed backup for $DATE"
else
echo "Completed backup for $DATE"
echo "Pruning archives for $DATE"
borg prune \
--list \
--prefix 'ldapdb-{{ db.key }}-{hostname}-' \
--show-rc \
--keep-daily {{ db.value.daily|d(7) }} \
--keep-weekly {{ db.value.weekly|d(4) }} \
--keep-monthly {{ db.value.monthly|d(6) }} \
${REPO}
prune_rc=$?
if [ "${prune_rc}" = "2" ]; then
echo "Failed pruning for $DATE"
else
echo "Completed pruning for $DATE"
fi
fi
echo "$(date +%s)|${BEGIN_EPOCH}|${backup_rc}|${prune_rc}" > /var/log/backup-status/{{ item.key }}/ldapdb-{{ db.key }}
{% endfor %}