1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_role_restic.git synced 2024-12-11 23:41:32 +01:00

fix: lvm: Allow / to be backed up as LVM

This commit causes an LVM backup target of / to be treated as /rootfs
instead.

Note that this will conflict with a path called /rootfs if we *do* try
to back that up.

Also, while we're at it, drop the -m option from mount. Not all
systems have this option.
This commit is contained in:
Martin Kennedy 2023-03-07 16:24:30 -05:00
parent 4cf66ebec4
commit de3d35d4ec

View file

@ -82,9 +82,13 @@ function mount_opt_map {
function prepare_vol {
local path="$1"
[ -d "$path" ] || path="$(dirname "$path")"
if [ "$path" == '/' ] ; then
mkdir -p /rootfs;
newpath='/rootfs';
else
newpath="$path";
fi
# TODO: path cannot be /,
## nor can it be where restic is
{
local source="$(findmnt -J -T ${path} | jq -r '.filesystems[0].source')"
local target="$(findmnt -J -T ${path} | jq -r '.filesystems[0].target')"
@ -98,26 +102,30 @@ function prepare_vol {
mount -t "$fs" \
-o "$(mount_opt_map "$fs")" \
--make-private \
-m \
"${source}_snap" "${tmpdir}"
mount -m --bind --make-private "${tmpdir}/${subdir}" "${path}"
mount --bind --make-private "${tmpdir}/${subdir}" "${newpath}"
}
}
function cleanup_vol {
local path="$1"
[ -d "$path" ] || path="$(dirname "$path")"
if [ "$path" == '/' ] ; then
newpath='/rootfs';
else
newpath="$path";
fi
{
local source="$(findmnt -v -J -T ${path} | jq -r '.filesystems[]|.source' | grep '_snap$')"
local source="$(findmnt -v -J -T "${newpath}" | jq -r '.filesystems[]|.source' | grep '_snap$')"
if ! grep -q '_snap$' <<< $source; then
echo "Snapshot for ${path} could not be found (found: ${source}). Exiting!" && return 1;
fi
echo "Cleaning up mount ..."
umount "${path}"
umount "${newpath}"
echo "Cleaning up snapshot ..."
umount "${source}"
@ -215,7 +223,7 @@ fi
{% else %}
{
{% if item.lvm is defined %}prepare_vol $BACKUP_SOURCE &&{% endif %}
{{ restic_install_path }}/restic backup $BACKUP_SOURCE $MODE_TAG \
{{ restic_install_path }}/restic backup {% if item.lvm is defined and item.src == '/' %}/rootfs{% endif %}$BACKUP_SOURCE $MODE_TAG \
{{ tags(item.tags) }} \
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
$@ \