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:
parent
4cf66ebec4
commit
de3d35d4ec
1 changed files with 15 additions and 7 deletions
|
@ -82,9 +82,13 @@ function mount_opt_map {
|
||||||
function prepare_vol {
|
function prepare_vol {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
[ -d "$path" ] || path="$(dirname "$path")"
|
[ -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 source="$(findmnt -J -T ${path} | jq -r '.filesystems[0].source')"
|
||||||
local target="$(findmnt -J -T ${path} | jq -r '.filesystems[0].target')"
|
local target="$(findmnt -J -T ${path} | jq -r '.filesystems[0].target')"
|
||||||
|
@ -98,26 +102,30 @@ function prepare_vol {
|
||||||
mount -t "$fs" \
|
mount -t "$fs" \
|
||||||
-o "$(mount_opt_map "$fs")" \
|
-o "$(mount_opt_map "$fs")" \
|
||||||
--make-private \
|
--make-private \
|
||||||
-m \
|
|
||||||
"${source}_snap" "${tmpdir}"
|
"${source}_snap" "${tmpdir}"
|
||||||
|
|
||||||
mount -m --bind --make-private "${tmpdir}/${subdir}" "${path}"
|
mount --bind --make-private "${tmpdir}/${subdir}" "${newpath}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup_vol {
|
function cleanup_vol {
|
||||||
local path="$1"
|
local path="$1"
|
||||||
[ -d "$path" ] || path="$(dirname "$path")"
|
[ -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
|
if ! grep -q '_snap$' <<< $source; then
|
||||||
echo "Snapshot for ${path} could not be found (found: ${source}). Exiting!" && return 1;
|
echo "Snapshot for ${path} could not be found (found: ${source}). Exiting!" && return 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Cleaning up mount ..."
|
echo "Cleaning up mount ..."
|
||||||
umount "${path}"
|
umount "${newpath}"
|
||||||
|
|
||||||
echo "Cleaning up snapshot ..."
|
echo "Cleaning up snapshot ..."
|
||||||
umount "${source}"
|
umount "${source}"
|
||||||
|
@ -215,7 +223,7 @@ fi
|
||||||
{% else %}
|
{% else %}
|
||||||
{
|
{
|
||||||
{% if item.lvm is defined %}prepare_vol $BACKUP_SOURCE &&{% endif %}
|
{% 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) }} \
|
{{ tags(item.tags) }} \
|
||||||
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
|
{% if item.exclude is defined %}{{ exclude(item.exclude) }}{% endif %} \
|
||||||
$@ \
|
$@ \
|
||||||
|
|
Loading…
Reference in a new issue