#!/bin/bash

set -eo pipefail

mkdir -p /home/lbkp/linstor/

{% if linctl_ha %}
# Check we are the current active node. Else, just skip the backup
if [[ ! -e /var/lib/linstor/linstordb.mv.db ]]; then
  echo Linstor DB not available on this node, skipping backup
  exit 0
fi
{% endif %}

echo Dumping linstor DB dump
linstor controller backupdb linstor_backup
echo Moving dump to /home/lbkp/linstor/linstor_backup.zip
mv /var/lib/linstor/linstor_backup.zip /home/lbkp/linstor/
